| OLD | NEW |
| 1 #define _BSD_SOURCE | 1 #define _BSD_SOURCE |
| 2 #include <string.h> | 2 #include <string.h> |
| 3 #include <fcntl.h> | 3 #include <fcntl.h> |
| 4 #include <unistd.h> | 4 #include <unistd.h> |
| 5 #include <errno.h> | 5 #include <errno.h> |
| 6 #include "libc.h" | 6 #include "libc.h" |
| 7 | 7 |
| 8 char *__randname(char *); | 8 char* __randname(char*); |
| 9 | 9 |
| 10 int __mkostemps(char *template, int len, int flags) | 10 int __mkostemps(char* template, int len, int flags) { |
| 11 { | 11 size_t l = strlen(template); |
| 12 » size_t l = strlen(template); | 12 if (l < 6 || len > l - 6 || memcmp(template + l - len - 6, "XXXXXX", 6)) { |
| 13 » if (l<6 || len>l-6 || memcmp(template+l-len-6, "XXXXXX", 6)) { | 13 errno = EINVAL; |
| 14 » » errno = EINVAL; | 14 return -1; |
| 15 » » return -1; | 15 } |
| 16 » } | |
| 17 | 16 |
| 18 » flags -= flags & O_ACCMODE; | 17 flags -= flags & O_ACCMODE; |
| 19 » int fd, retries = 100; | 18 int fd, retries = 100; |
| 20 » do { | 19 do { |
| 21 » » __randname(template+l-len-6); | 20 __randname(template + l - len - 6); |
| 22 » » if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600
))>=0) | 21 if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600)) >= 0) |
| 23 » » » return fd; | 22 return fd; |
| 24 » } while (--retries && errno == EEXIST); | 23 } while (--retries && errno == EEXIST); |
| 25 | 24 |
| 26 » memcpy(template+l-len-6, "XXXXXX", 6); | 25 memcpy(template + l - len - 6, "XXXXXX", 6); |
| 27 » return -1; | 26 return -1; |
| 28 } | 27 } |
| 29 | 28 |
| 30 weak_alias(__mkostemps, mkostemps); | 29 weak_alias(__mkostemps, mkostemps); |
| 31 weak_alias(__mkostemps, mkostemps64); | 30 weak_alias(__mkostemps, mkostemps64); |
| OLD | NEW |