X-Git-Url: https://git.saurik.com/apple/libc.git/blobdiff_plain/fbd86d4cc20b02a10edcca92fb7ae0a143e63cc4..1f2f436a38f7ae2d39a943ad2898d8fed4ed2e58:/stdio/FreeBSD/tmpnam.c.patch diff --git a/stdio/FreeBSD/tmpnam.c.patch b/stdio/FreeBSD/tmpnam.c.patch new file mode 100644 index 0000000..5ff86df --- /dev/null +++ b/stdio/FreeBSD/tmpnam.c.patch @@ -0,0 +1,41 @@ +--- tmpnam.c.orig 2010-07-06 16:02:20.000000000 -0700 ++++ tmpnam.c 2010-07-06 16:32:52.000000000 -0700 +@@ -40,21 +40,35 @@ __FBSDID("$FreeBSD: src/lib/libc/stdio/t + + #include + #include ++#include ++#include + + __warn_references(tmpnam, + "warning: tmpnam() possibly used unsafely; consider using mkstemp()"); + + extern char *_mktemp(char *); + ++static char *tmpnam_buf = NULL; ++static pthread_once_t tmpnam_buf_control = PTHREAD_ONCE_INIT; ++ ++static void tmpnam_buf_allocate(void) ++{ ++ tmpnam_buf = malloc(L_tmpnam); ++} ++ + char * + tmpnam(s) + char *s; + { + static u_long tmpcount; +- static char buf[L_tmpnam]; + +- if (s == NULL) +- s = buf; ++ if (s == NULL) { ++ if (pthread_once(&tmpnam_buf_control, tmpnam_buf_allocate) ++ || !tmpnam_buf) { ++ return NULL; ++ } ++ s = tmpnam_buf; ++ } + (void)snprintf(s, L_tmpnam, "%stmp.%lu.XXXXXX", P_tmpdir, tmpcount); + ++tmpcount; + return (_mktemp(s));