diff options
-rw-r--r-- | embed.fnc | 4 | ||||
-rw-r--r-- | proto.h | 5 | ||||
-rw-r--r-- | util.c | 34 | ||||
-rw-r--r-- | util.h | 4 |
4 files changed, 47 insertions, 0 deletions
@@ -3053,6 +3053,10 @@ Apnod |Size_t |my_strlcat |NULLOK char *dst|NULLOK const char *src|Size_t size Apnod |Size_t |my_strlcpy |NULLOK char *dst|NULLOK const char *src|Size_t size #endif +#ifndef HAS_MKSTEMP +pno |int |my_mkstemp |NN char *templte +#endif + APpdn |bool |isinfnan |NV nv p |bool |isinfnansv |NN SV *sv @@ -3856,6 +3856,11 @@ STATIC int S_dooneliner(pTHX_ const char *cmd, const char *filename) # endif #endif +#if !defined(HAS_MKSTEMP) +PERL_CALLCONV int Perl_my_mkstemp(char *templte); +#define PERL_ARGS_ASSERT_MY_MKSTEMP \ + assert(templte) +#endif #if !defined(HAS_RENAME) PERL_CALLCONV I32 Perl_same_dirent(pTHX_ const char* a, const char* b); #define PERL_ARGS_ASSERT_SAME_DIRENT \ @@ -5789,6 +5789,40 @@ Perl_my_dirfd(DIR * dir) { #endif } +#ifndef HAS_MKSTEMP + +#define TEMP_FILE_CH "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz0123456789" +#define TEMP_FILE_CH_COUNT (sizeof(TEMP_FILE_CH)-1) + +int +Perl_my_mkstemp(char *templte) { + dTHX; + STRLEN len = strlen(templte); + int fd; + int attempts = 0; + + PERL_ARGS_ASSERT_MY_MKSTEMP; + + if (len < 6 || + templte[len-1] != 'X' || templte[len-2] != 'X' || templte[len-3] != 'X' || + templte[len-4] != 'X' || templte[len-5] != 'X' || templte[len-6] != 'X') { + errno = EINVAL; + return -1; + } + + do { + int i; + for (i = 1; i <= 6; ++i) { + templte[len-i] = TEMP_FILE_CH[(int)(Perl_internal_drand48() * TEMP_FILE_CH_COUNT)]; + } + fd = PerlLIO_open3(templte, O_RDWR | O_CREAT | O_EXCL, 0600); + } while (fd == -1 && errno == EEXIST && ++attempts <= 100); + + return fd; +} + +#endif + REGEXP * Perl_get_re_arg(pTHX_ SV *sv) { @@ -246,6 +246,10 @@ means arg not present, 1 is empty string/null byte */ ((char *) memmem(big, bigend - big, little, lend - little)) #endif +#if defined(HAS_MKSTEMP) && defined(PERL_CORE) +# define Perl_my_mkstemp(templte) mkstemp(templte) +#endif + #endif /* PERL_UTIL_H_ */ /* |