mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 23:27:42 +00:00
LibC: A whole bunch of compat work towards porting Lynx.
This commit is contained in:
parent
48590a0e51
commit
2c3cf22bc9
10 changed files with 125 additions and 5 deletions
|
@ -161,6 +161,8 @@ void* calloc(size_t count, size_t size)
|
|||
|
||||
void* realloc(void *ptr, size_t size)
|
||||
{
|
||||
if (!ptr)
|
||||
return malloc(size);
|
||||
validate_mallocation(ptr, "realloc()");
|
||||
auto* header = (MallocHeader*)((((byte*)ptr) - sizeof(MallocHeader)));
|
||||
size_t old_size = header->size;
|
||||
|
@ -288,6 +290,12 @@ long atol(const char* str)
|
|||
return atoi(str);
|
||||
}
|
||||
|
||||
long long atoll(const char* str)
|
||||
{
|
||||
dbgprintf("FIXME(Libc): atoll('%s') passing through to atol()\n", str);
|
||||
return atol(str);
|
||||
}
|
||||
|
||||
static char ptsname_buf[32];
|
||||
char* ptsname(int fd)
|
||||
{
|
||||
|
@ -335,9 +343,32 @@ int system(const char* command)
|
|||
return execl("/bin/sh", "sh", "-c", command, nullptr);
|
||||
}
|
||||
|
||||
char* mktemp(char*)
|
||||
char* mktemp(char* pattern)
|
||||
{
|
||||
ASSERT_NOT_REACHED();
|
||||
int length = strlen(pattern);
|
||||
|
||||
// FIXME: Check for an invalid template pattern and return EINVAL.
|
||||
if (length < 6) {
|
||||
pattern[0] = '\0';
|
||||
errno = EINVAL;
|
||||
return pattern;
|
||||
}
|
||||
|
||||
int start = length - 6;
|
||||
|
||||
static constexpr char random_characters[] = "abcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
for (int attempt = 0; attempt < 100; ++attempt) {
|
||||
for (int i = 0; i < 6; ++i)
|
||||
pattern[start + i] = random_characters[(rand() % sizeof(random_characters))];
|
||||
struct stat st;
|
||||
int rc = lstat(pattern, &st);
|
||||
if (rc < 0 && errno == ENOENT)
|
||||
return pattern;
|
||||
}
|
||||
pattern[0] = '\0';
|
||||
errno = EEXIST;
|
||||
return pattern;
|
||||
}
|
||||
|
||||
void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void *, const void *))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue