Mercurial > emacs
changeset 9346:fec27dfc0684
(Ffile_regular_p): New function.
(syms_of_fileio): defsubr it.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 05 Oct 1994 09:33:33 +0000 |
parents | 832197fec54d |
children | 1a69634e3477 |
files | src/fileio.c |
diffstat | 1 files changed, 61 insertions(+), 37 deletions(-) [+] |
line wrap: on
line diff
--- a/src/fileio.c Wed Oct 05 06:29:50 1994 +0000 +++ b/src/fileio.c Wed Oct 05 09:33:33 1994 +0000 @@ -2274,6 +2274,42 @@ return Qt; } +/* Having this before file-symlink-p mysteriously caused it to be forgotten + on the RT/PC. */ +DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, + "Return t if file FILENAME can be written or created by you.") + (filename) + Lisp_Object filename; +{ + Lisp_Object abspath, dir; + Lisp_Object handler; + struct stat statbuf; + + CHECK_STRING (filename, 0); + abspath = Fexpand_file_name (filename, Qnil); + + /* If the file name has special constructs in it, + call the corresponding file handler. */ + handler = Ffind_file_name_handler (abspath, Qfile_writable_p); + if (!NILP (handler)) + return call2 (handler, Qfile_writable_p, abspath); + + if (stat (XSTRING (abspath)->data, &statbuf) >= 0) + return (check_writable (XSTRING (abspath)->data) + ? Qt : Qnil); + dir = Ffile_name_directory (abspath); +#ifdef VMS + if (!NILP (dir)) + dir = Fdirectory_file_name (dir); +#endif /* VMS */ +#ifdef MSDOS + if (!NILP (dir)) + dir = Fdirectory_file_name (dir); +#endif /* MSDOS */ + return (check_writable (!NILP (dir) ? (char *) XSTRING (dir)->data : "") + ? Qt : Qnil); +} + DEFUN ("file-symlink-p", Ffile_symlink_p, Sfile_symlink_p, 1, 1, 0, "Return non-nil if file FILENAME is the name of a symbolic link.\n\ The value is the name of the file to which it is linked.\n\ @@ -2321,42 +2357,6 @@ #endif /* not S_IFLNK */ } -/* Having this before file-symlink-p mysteriously caused it to be forgotten - on the RT/PC. */ -DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, - "Return t if file FILENAME can be written or created by you.") - (filename) - Lisp_Object filename; -{ - Lisp_Object abspath, dir; - Lisp_Object handler; - struct stat statbuf; - - CHECK_STRING (filename, 0); - abspath = Fexpand_file_name (filename, Qnil); - - /* If the file name has special constructs in it, - call the corresponding file handler. */ - handler = Ffind_file_name_handler (abspath, Qfile_writable_p); - if (!NILP (handler)) - return call2 (handler, Qfile_writable_p, abspath); - - if (stat (XSTRING (abspath)->data, &statbuf) >= 0) - return (check_writable (XSTRING (abspath)->data) - ? Qt : Qnil); - dir = Ffile_name_directory (abspath); -#ifdef VMS - if (!NILP (dir)) - dir = Fdirectory_file_name (dir); -#endif /* VMS */ -#ifdef MSDOS - if (!NILP (dir)) - dir = Fdirectory_file_name (dir); -#endif /* MSDOS */ - return (check_writable (!NILP (dir) ? (char *) XSTRING (dir)->data : "") - ? Qt : Qnil); -} - DEFUN ("file-directory-p", Ffile_directory_p, Sfile_directory_p, 1, 1, 0, "Return t if file FILENAME is the name of a directory as a file.\n\ A directory name spec may be given instead; then the value is t\n\ @@ -2414,6 +2414,29 @@ return tem ? Qnil : Qt; } +DEFUN ("file-regular-p", Ffile_regular_p, Sfile_regular_p, 1, 1, 0, + "Return t if file FILENAME is the name of a regular file.\n\ +This is the sort of file that holds an ordinary stream of data bytes.") + (filename) + Lisp_Object filename; +{ + register Lisp_Object abspath; + struct stat st; + Lisp_Object handler; + + abspath = expand_and_dir_to_file (filename, current_buffer->directory); + + /* If the file name has special constructs in it, + call the corresponding file handler. */ + handler = Ffind_file_name_handler (abspath, Qfile_directory_p); + if (!NILP (handler)) + return call2 (handler, Qfile_directory_p, abspath); + + if (stat (XSTRING (abspath)->data, &st) < 0) + return Qnil; + return (st.st_mode & S_IFMT) == S_IFREG ? Qt : Qnil; +} + DEFUN ("file-modes", Ffile_modes, Sfile_modes, 1, 1, 0, "Return mode bits of FILE, as an integer.") (filename) @@ -2529,7 +2552,7 @@ XSETINT (value, (~ realmask) & 0777); return value; } - + #ifdef unix DEFUN ("unix-sync", Funix_sync, Sunix_sync, 0, 0, "", @@ -4210,6 +4233,7 @@ defsubr (&Sfile_symlink_p); defsubr (&Sfile_directory_p); defsubr (&Sfile_accessible_directory_p); + defsubr (&Sfile_regular_p); defsubr (&Sfile_modes); defsubr (&Sset_file_modes); defsubr (&Sset_default_file_modes);