- printf("writable(%s) mode=%o\n", filename, s->st_mode);
- if (bitset(0111, s->st_mode))
+ printf("writable(%s)\n", filename);
+
+#ifdef HASLSTAT
+ if (lstat(filename, &stb) < 0)
+#else
+ if (stat(filename, &stb) < 0)
+#endif
+ {
+ /* file does not exist -- see if directory is safe */
+ p = strrchr(filename, '/');
+ if (p == NULL)
+ return FALSE;
+ *p = '\0';
+ if (safefile(filename, RealUid, RealGid, RealUserName,
+ SF_MUSTOWN, S_IWRITE|S_IEXEC) != 0)
+ {
+ *p = '/';
+ return FALSE;
+ }
+ *p = '/';
+ }
+
+ /*
+ ** File does exist -- check that it is writable.
+ */
+
+ if (bitset(0111, stb.st_mode))