1 --- tempnam.c.orig 2006-09-15 00:33:51.000000000 -0700
2 +++ tempnam.c 2006-09-15 01:19:22.000000000 -0700
4 __FBSDID("$FreeBSD: src/lib/libc/stdio/tempnam.c,v 1.10 2002/03/22 21:53:04 obrien Exp $");
15 - if (!(name = malloc(MAXPATHLEN)))
18 +#endif /* __DARWIN_UNIX03 */
19 + if (!(name = malloc(MAXPATHLEN))) {
27 if (issetugid() == 0 && (f = getenv("TMPDIR"))) {
28 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
29 *(f + strlen(f) - 1) == '/'? "": "/", pfx);
30 - if ((f = _mktemp(name)))
31 + if ((f = _mktemp(name))) {
36 +#endif /* !__DARWIN_UNIX03 */
37 if ((f = (char *)dir)) {
39 + if (!access(dir, W_OK)) {
40 +#endif /* __DARWIN_UNIX03 */
41 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
42 *(f + strlen(f) - 1) == '/'? "": "/", pfx);
43 - if ((f = _mktemp(name)))
44 + if ((f = _mktemp(name))) {
49 +#endif /* __DARWIN_UNIX03 */
54 + if (stat(f, &sb) == 0) { /* directory accessible? */
55 +#endif /* __DARWIN_UNIX03 */
56 (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
57 - if ((f = _mktemp(name)))
58 + if ((f = _mktemp(name))) {
64 +#endif /* __DARWIN_UNIX03 */
67 + if (stat(f, &sb) < 0) {
68 + f = "./"; /* directory inaccessible */
70 +#endif /* __DARWIN_UNIX03 */
71 (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
72 - if ((f = _mktemp(name)))
73 + if ((f = _mktemp(name))) {