(run-hook-with-args-until-success 'write-file-functions)
;; If a hook returned t, file is already "written".
;; Otherwise, write it the usual way now.
- (let ((dir (file-name-directory
+ (let ((file (buffer-file-name))
+ (dir (file-name-directory
(expand-file-name buffer-file-name))))
- (unless (file-exists-p dir)
+ ;; Some systems have directories (like /content on
+ ;; Android) in which files can exist without a
+ ;; corresponding parent directory.
+ (unless (or (file-exists-p file)
+ (file-exists-p dir))
(if (y-or-n-p
(format-message
"Directory `%s' does not exist; create? " dir))
return -1;
}
+ /* If fd is -1, just assume that the file does not exist,
+ and return -1 with errno set to ENOENT. */
+
+ if (fd == -1)
+ {
+ errno = ENOENT;
+ goto skip;
+ }
+
if (mode & O_CLOEXEC)
android_close_on_exec (fd);
+ skip:
ANDROID_DELETE_LOCAL_REF (string);
return fd;
}