mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 18:57:34 +00:00
LibC: Oops x2, we can't use "bool" in stdlib.h either
This commit is contained in:
parent
b1fc5d9143
commit
9d681beaf0
3 changed files with 8 additions and 8 deletions
|
@ -636,7 +636,7 @@ void funlockfile(FILE* filehandle)
|
||||||
FILE* tmpfile()
|
FILE* tmpfile()
|
||||||
{
|
{
|
||||||
char tmp_path[] = "/tmp/XXXXXX";
|
char tmp_path[] = "/tmp/XXXXXX";
|
||||||
if (!__generate_unique_filename(tmp_path))
|
if (__generate_unique_filename(tmp_path) < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
int fd = open(tmp_path, O_CREAT | O_EXCL | O_RDWR, S_IWUSR | S_IRUSR);
|
int fd = open(tmp_path, O_CREAT | O_EXCL | O_RDWR, S_IWUSR | S_IRUSR);
|
||||||
|
|
|
@ -104,13 +104,13 @@ static inline T strtol_impl(const char* nptr, char** endptr, int base)
|
||||||
return num;
|
return num;
|
||||||
}
|
}
|
||||||
|
|
||||||
[[nodiscard]] bool __generate_unique_filename(char* pattern)
|
[[nodiscard]] int __generate_unique_filename(char* pattern)
|
||||||
{
|
{
|
||||||
int length = strlen(pattern);
|
int length = strlen(pattern);
|
||||||
|
|
||||||
if (length < 6 || !String(pattern).ends_with("XXXXXX")) {
|
if (length < 6 || !String(pattern).ends_with("XXXXXX")) {
|
||||||
errno = EINVAL;
|
errno = EINVAL;
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int start = length - 6;
|
int start = length - 6;
|
||||||
|
@ -123,10 +123,10 @@ static inline T strtol_impl(const char* nptr, char** endptr, int base)
|
||||||
struct stat st;
|
struct stat st;
|
||||||
int rc = lstat(pattern, &st);
|
int rc = lstat(pattern, &st);
|
||||||
if (rc < 0 && errno == ENOENT)
|
if (rc < 0 && errno == ENOENT)
|
||||||
return true;
|
return 0;
|
||||||
}
|
}
|
||||||
errno = EEXIST;
|
errno = EEXIST;
|
||||||
return false;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -533,7 +533,7 @@ int system(const char* command)
|
||||||
|
|
||||||
char* mktemp(char* pattern)
|
char* mktemp(char* pattern)
|
||||||
{
|
{
|
||||||
if (!__generate_unique_filename(pattern))
|
if (__generate_unique_filename(pattern) < 0)
|
||||||
pattern[0] = '\0';
|
pattern[0] = '\0';
|
||||||
|
|
||||||
return pattern;
|
return pattern;
|
||||||
|
@ -552,7 +552,7 @@ int mkstemp(char* pattern)
|
||||||
|
|
||||||
char* mkdtemp(char* pattern)
|
char* mkdtemp(char* pattern)
|
||||||
{
|
{
|
||||||
if (!__generate_unique_filename(pattern))
|
if (__generate_unique_filename(pattern) < 0)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
if (mkdir(pattern, 0700) < 0)
|
if (mkdir(pattern, 0700) < 0)
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
__attribute__((warn_unused_result)) bool __generate_unique_filename(char* pattern);
|
__attribute__((warn_unused_result)) int __generate_unique_filename(char* pattern);
|
||||||
|
|
||||||
__BEGIN_DECLS
|
__BEGIN_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue