diff options
| author | Ron Yorston <rmy@pobox.com> | 2014-01-07 22:39:35 +0000 |
|---|---|---|
| committer | Ron Yorston <rmy@pobox.com> | 2014-01-07 22:39:35 +0000 |
| commit | 7f0cb741c77f74a48ffd10a1e7d36ff2adf95f03 (patch) | |
| tree | 11b7d44f8c42d7d39d641e56d6fdd5ef7aed94d6 | |
| parent | 94150aba92d308e417aa552a1b3a957be264b423 (diff) | |
| download | busybox-w32-7f0cb741c77f74a48ffd10a1e7d36ff2adf95f03.tar.gz busybox-w32-7f0cb741c77f74a48ffd10a1e7d36ff2adf95f03.tar.bz2 busybox-w32-7f0cb741c77f74a48ffd10a1e7d36ff2adf95f03.zip | |
Implement POSIX-compliant mktemp for WIN32
| -rw-r--r-- | debianutils/mktemp.c | 4 | ||||
| -rw-r--r-- | include/mingw.h | 2 | ||||
| -rw-r--r-- | win32/mingw.c | 14 |
3 files changed, 16 insertions, 4 deletions
diff --git a/debianutils/mktemp.c b/debianutils/mktemp.c index 7f60ca234..983d7a246 100644 --- a/debianutils/mktemp.c +++ b/debianutils/mktemp.c | |||
| @@ -94,11 +94,7 @@ int mktemp_main(int argc UNUSED_PARAM, char **argv) | |||
| 94 | 94 | ||
| 95 | if (opts & OPT_u) { | 95 | if (opts & OPT_u) { |
| 96 | chp = mktemp(chp); | 96 | chp = mktemp(chp); |
| 97 | #if !ENABLE_PLATFORM_MINGW32 | ||
| 98 | if (chp[0] == '\0') | 97 | if (chp[0] == '\0') |
| 99 | #else | ||
| 100 | if (chp == NULL || chp[0] == '\0') | ||
| 101 | #endif | ||
| 102 | goto error; | 98 | goto error; |
| 103 | } else if (opts & OPT_d) { | 99 | } else if (opts & OPT_d) { |
| 104 | if (mkdtemp(chp) == NULL) | 100 | if (mkdtemp(chp) == NULL) |
diff --git a/include/mingw.h b/include/mingw.h index b3fc603c0..d6eb5d22c 100644 --- a/include/mingw.h +++ b/include/mingw.h | |||
| @@ -164,12 +164,14 @@ int mingw_system(const char *cmd); | |||
| 164 | 164 | ||
| 165 | int clearenv(void); | 165 | int clearenv(void); |
| 166 | char *mingw_getenv(const char *name); | 166 | char *mingw_getenv(const char *name); |
| 167 | char *mingw_mktemp(char *template); | ||
| 167 | int mkstemp(char *template); | 168 | int mkstemp(char *template); |
| 168 | char *realpath(const char *path, char *resolved_path); | 169 | char *realpath(const char *path, char *resolved_path); |
| 169 | int setenv(const char *name, const char *value, int replace); | 170 | int setenv(const char *name, const char *value, int replace); |
| 170 | void unsetenv(const char *env); | 171 | void unsetenv(const char *env); |
| 171 | 172 | ||
| 172 | #define getenv mingw_getenv | 173 | #define getenv mingw_getenv |
| 174 | #define mktemp mingw_mktemp | ||
| 173 | 175 | ||
| 174 | /* | 176 | /* |
| 175 | * sys/ioctl.h | 177 | * sys/ioctl.h |
diff --git a/win32/mingw.c b/win32/mingw.c index b9f720e1a..70a8cb611 100644 --- a/win32/mingw.c +++ b/win32/mingw.c | |||
| @@ -435,6 +435,20 @@ unsigned int sleep (unsigned int seconds) | |||
| 435 | return 0; | 435 | return 0; |
| 436 | } | 436 | } |
| 437 | 437 | ||
| 438 | /* | ||
| 439 | * Windows' mktemp returns NULL on error whereas POSIX always returns the | ||
| 440 | * template and signals an error by making it an empty string. | ||
| 441 | */ | ||
| 442 | #undef mktemp | ||
| 443 | char *mingw_mktemp(char *template) | ||
| 444 | { | ||
| 445 | if ( mktemp(template) == NULL ) { | ||
| 446 | template[0] = '\0'; | ||
| 447 | } | ||
| 448 | |||
| 449 | return template; | ||
| 450 | } | ||
| 451 | |||
| 438 | int mkstemp(char *template) | 452 | int mkstemp(char *template) |
| 439 | { | 453 | { |
| 440 | char *filename = mktemp(template); | 454 | char *filename = mktemp(template); |
