1 --- tempnam.c.orig 2008-11-12 17:08:45.000000000 -0800
2 +++ tempnam.c 2008-11-12 17:41:23.000000000 -0800
3 @@ -57,35 +57,68 @@ tempnam(dir, pfx)
7 - if (!(name = malloc(MAXPATHLEN)))
8 + if (!(name = malloc(MAXPATHLEN))) {
16 if (issetugid() == 0 && (f = getenv("TMPDIR"))) {
17 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
18 *(f + strlen(f) - 1) == '/'? "": "/", pfx);
19 - if ((f = _mktemp(name)))
20 + if ((f = _mktemp(name))) {
25 +#endif /* !__DARWIN_UNIX03 */
26 if ((f = (char *)dir)) {
28 + if (access(dir, W_OK) == 0) {
29 +#endif /* __DARWIN_UNIX03 */
30 (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
31 *(f + strlen(f) - 1) == '/'? "": "/", pfx);
32 - if ((f = _mktemp(name)))
33 + if ((f = _mktemp(name))) {
38 +#endif /* __DARWIN_UNIX03 */
43 + if (access(f, W_OK) == 0) { /* directory accessible? */
44 +#endif /* __DARWIN_UNIX03 */
45 (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
46 - if ((f = _mktemp(name)))
47 + if ((f = _mktemp(name))) {
53 + if (issetugid() == 0 && (f = getenv("TMPDIR")) && access(f, W_OK) == 0) {
54 + (void)snprintf(name, MAXPATHLEN, "%s%s%sXXXXXX", f,
55 + *(f + strlen(f) - 1) == '/'? "": "/", pfx);
56 + if ((f = _mktemp(name))) {
60 +#endif /* __DARWIN_UNIX03 */
63 + if (access(f, W_OK) < 0) {
64 + f = "./"; /* directory inaccessible */
65 + if (access(f, W_OK) < 0) {
69 +#endif /* __DARWIN_UNIX03 */
70 (void)snprintf(name, MAXPATHLEN, "%s%sXXXXXX", f, pfx);
71 - if ((f = _mktemp(name)))
72 + if ((f = _mktemp(name))) {