forked from Bananymous/banan-os
LibC: Implement tmpnam()
This implementation is not really spec compliant as rand() does not guarantee TMP_MAX different outputs + seeding
This commit is contained in:
parent
62db9a8ef3
commit
e52dac3b25
|
@ -667,8 +667,23 @@ char* tempnam(const char*, const char*);
|
||||||
// TODO
|
// TODO
|
||||||
FILE* tmpfile(void);
|
FILE* tmpfile(void);
|
||||||
|
|
||||||
// TODO
|
char* tmpnam(char* storage)
|
||||||
char* tmpnam(char*);
|
{
|
||||||
|
static int s_counter = rand();
|
||||||
|
static char s_storage[PATH_MAX];
|
||||||
|
if (storage == nullptr)
|
||||||
|
storage = s_storage;
|
||||||
|
for (int i = 0; i < TMP_MAX; i++)
|
||||||
|
{
|
||||||
|
sprintf(storage, "/tmp/tmp_%04x", s_counter);
|
||||||
|
s_counter = rand();
|
||||||
|
|
||||||
|
struct stat st;
|
||||||
|
if (stat(storage, &st) == -1 && errno == ENOENT)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return storage;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
int ungetc(int, FILE*);
|
int ungetc(int, FILE*);
|
||||||
|
|
Loading…
Reference in New Issue