diff options
author | Brandon Scott <xeons@users.noreply.github.com> | 2019-11-16 04:34:20 -0600 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-16 12:50:50 +0100 |
commit | bda36853c984633adc894e204d9fcef42ac3aa24 (patch) | |
tree | f98c6a7840e9e028fe89f926138cc1b9acd53a4a /Libraries/LibC | |
parent | 48b1c82d53ff10906849ebd7125534871a96870c (diff) | |
download | serenity-bda36853c984633adc894e204d9fcef42ac3aa24.zip |
LibC: Implemented mkstemp in stdlib
Implemented mkstemp method in stdlib.
Diffstat (limited to 'Libraries/LibC')
-rw-r--r-- | Libraries/LibC/stdlib.cpp | 11 | ||||
-rw-r--r-- | Libraries/LibC/stdlib.h | 1 |
2 files changed, 12 insertions, 0 deletions
diff --git a/Libraries/LibC/stdlib.cpp b/Libraries/LibC/stdlib.cpp index fee9604642..b4d2a97fa4 100644 --- a/Libraries/LibC/stdlib.cpp +++ b/Libraries/LibC/stdlib.cpp @@ -382,6 +382,17 @@ char* mktemp(char* pattern) return pattern; } +int mkstemp(char* pattern) +{ + char* path = mktemp(pattern); + + int fd = open(path, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR); // I'm using the flags I saw glibc using. + if (fd >= 0) + return fd; + + return -1; +} + char* mkdtemp(char* pattern) { int length = strlen(pattern); diff --git a/Libraries/LibC/stdlib.h b/Libraries/LibC/stdlib.h index 3cf039abdc..529d4a99b7 100644 --- a/Libraries/LibC/stdlib.h +++ b/Libraries/LibC/stdlib.h @@ -41,6 +41,7 @@ long labs(long); double atof(const char*); int system(const char* command); char* mktemp(char*); +int mkstemp(char*); char* mkdtemp(char*); void* bsearch(const void* key, const void* base, size_t nmemb, size_t size, int (*compar)(const void*, const void*)); size_t mbstowcs(wchar_t*, const char*, size_t); |