From 1f8653eb229691a34b3470350ff38a8705228129 Mon Sep 17 00:00:00 2001 From: "Richard M. Stallman" Date: Tue, 10 Sep 1996 19:54:02 +0000 Subject: [PATCH] (Faccess_file): New function. (Qaccess_file): New variable. (syms_of_fileio): defsubr function; init and staticpro Qaccess_file. --- src/fileio.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/fileio.c b/src/fileio.c index 88fac439231..7c7cf7a13f8 100644 --- a/src/fileio.c +++ b/src/fileio.c @@ -249,8 +249,9 @@ Lisp_Object Qmake_symbolic_link; Lisp_Object Qfile_exists_p; Lisp_Object Qfile_executable_p; Lisp_Object Qfile_readable_p; -Lisp_Object Qfile_symlink_p; Lisp_Object Qfile_writable_p; +Lisp_Object Qfile_symlink_p; +Lisp_Object Qaccess_file; Lisp_Object Qfile_directory_p; Lisp_Object Qfile_regular_p; Lisp_Object Qfile_accessible_directory_p; @@ -2694,6 +2695,32 @@ DEFUN ("file-writable-p", Ffile_writable_p, Sfile_writable_p, 1, 1, 0, ? Qt : Qnil); } +DEFUN ("access-file", Faccess_file, Saccess_file, 2, 2, 0, + "Access file FILENAME, and get an error if that does not work.\n\ +The second argument STRING is used in the error message.\n\ +If there is no error, we return nil.") + (filename, string) + Lisp_Object filename, string; +{ + Lisp_Object handler; + int fd; + + CHECK_STRING (filename, 0); + + /* If the file name has special constructs in it, + call the corresponding file handler. */ + handler = Ffind_file_name_handler (filename, Qaccess_file); + if (!NILP (handler)) + return call3 (handler, Qaccess_file, filename, string); + + fd = open (XSTRING (filename)->data, O_RDONLY); + if (fd < 0) + report_file_error (XSTRING (string)->data, Fcons (filename, Qnil)); + close (fd); + + return 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\ @@ -4509,8 +4536,9 @@ syms_of_fileio () Qfile_exists_p = intern ("file-exists-p"); Qfile_executable_p = intern ("file-executable-p"); Qfile_readable_p = intern ("file-readable-p"); - Qfile_symlink_p = intern ("file-symlink-p"); Qfile_writable_p = intern ("file-writable-p"); + Qfile_symlink_p = intern ("file-symlink-p"); + Qaccess_file = intern ("access-file"); Qfile_directory_p = intern ("file-directory-p"); Qfile_regular_p = intern ("file-regular-p"); Qfile_accessible_directory_p = intern ("file-accessible-directory-p"); @@ -4539,8 +4567,9 @@ syms_of_fileio () staticpro (&Qfile_exists_p); staticpro (&Qfile_executable_p); staticpro (&Qfile_readable_p); - staticpro (&Qfile_symlink_p); staticpro (&Qfile_writable_p); + staticpro (&Qaccess_file); + staticpro (&Qfile_symlink_p); staticpro (&Qfile_directory_p); staticpro (&Qfile_regular_p); staticpro (&Qfile_accessible_directory_p); @@ -4695,6 +4724,7 @@ a non-nil value."); defsubr (&Sfile_executable_p); defsubr (&Sfile_readable_p); defsubr (&Sfile_writable_p); + defsubr (&Saccess_file); defsubr (&Sfile_symlink_p); defsubr (&Sfile_directory_p); defsubr (&Sfile_accessible_directory_p); -- 2.39.2