Function: file-writable-p
file-writable-p is a function defined in fileio.c.
Signature
(file-writable-p FILENAME)
Documentation
Return t if file FILENAME can be written or created by you.
Other relevant functions are documented in the file group.
Shortdoc
;; file
(file-writable-p "/tmp/foo")
e.g. => t
Aliases
Source Code
// Defined in /usr/src/emacs/src/fileio.c
{
Lisp_Object absname, dir, encoded;
Lisp_Object handler;
absname = Fexpand_file_name (filename, Qnil);
/* If the file name has special constructs in it,
call the corresponding file name handler. */
handler = Ffind_file_name_handler (absname, Qfile_writable_p);
if (!NILP (handler))
return calln (handler, Qfile_writable_p, absname);
encoded = ENCODE_FILE (absname);
if (file_access_p (SSDATA (encoded), W_OK))
return Qt;
if (errno != ENOENT)
return Qnil;
dir = file_name_directory (absname);
eassert (!NILP (dir));
#ifdef MSDOS
dir = Fdirectory_file_name (dir);
#endif /* MSDOS */
encoded = ENCODE_FILE (dir);
#ifdef WINDOWSNT
/* The read-only attribute of the parent directory doesn't affect
whether a file or directory can be created within it. Some day we
should check ACLs though, which do affect this. */
return file_directory_p (encoded) ? Qt : Qnil;
#else
return file_access_p (SSDATA (encoded), W_OK | X_OK) ? Qt : Qnil;
#endif
}