aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorPaul Eggert2012-10-19 12:25:18 -0700
committerPaul Eggert2012-10-19 12:25:18 -0700
commitf0a801750151bee7fdcf96dff272986e627fb3e3 (patch)
tree1374d53fe4cd23a04924db66005e7bb0c66ad2c7 /src/lread.c
parent8e8083185c417eedbaadf0b33c7089da72fe2250 (diff)
downloademacs-f0a801750151bee7fdcf96dff272986e627fb3e3.tar.gz
emacs-f0a801750151bee7fdcf96dff272986e627fb3e3.zip
Undo faccessat change.
Diffstat (limited to 'src/lread.c')
-rw-r--r--src/lread.c56
1 files changed, 27 insertions, 29 deletions
diff --git a/src/lread.c b/src/lread.c
index dedce50de2a..6d4c0d990af 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -1404,7 +1404,7 @@ Returns the file's name in absolute form, or nil if not found.
1404If SUFFIXES is non-nil, it should be a list of suffixes to append to 1404If SUFFIXES is non-nil, it should be a list of suffixes to append to
1405file name when searching. 1405file name when searching.
1406If non-nil, PREDICATE is used instead of `file-readable-p'. 1406If non-nil, PREDICATE is used instead of `file-readable-p'.
1407PREDICATE can also be an integer to pass to the faccessat(2) function, 1407PREDICATE can also be an integer to pass to the access(2) function,
1408in which case file-name-handlers are ignored. 1408in which case file-name-handlers are ignored.
1409This function will normally skip directories, so if you want it to find 1409This function will normally skip directories, so if you want it to find
1410directories, make sure the PREDICATE function returns `dir-ok' for them. */) 1410directories, make sure the PREDICATE function returns `dir-ok' for them. */)
@@ -1442,6 +1442,7 @@ static Lisp_Object Qdir_ok;
1442int 1442int
1443openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate) 1443openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *storeptr, Lisp_Object predicate)
1444{ 1444{
1445 int fd;
1445 ptrdiff_t fn_size = 100; 1446 ptrdiff_t fn_size = 100;
1446 char buf[100]; 1447 char buf[100];
1447 char *fn = buf; 1448 char *fn = buf;
@@ -1496,6 +1497,7 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1496 { 1497 {
1497 ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail)); 1498 ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail));
1498 Lisp_Object handler; 1499 Lisp_Object handler;
1500 bool exists;
1499 1501
1500 /* Concatenate path element/specified name with the suffix. 1502 /* Concatenate path element/specified name with the suffix.
1501 If the directory starts with /:, remove that. */ 1503 If the directory starts with /:, remove that. */
@@ -1519,7 +1521,6 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1519 handler = Ffind_file_name_handler (string, Qfile_exists_p); 1521 handler = Ffind_file_name_handler (string, Qfile_exists_p);
1520 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate)) 1522 if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
1521 { 1523 {
1522 bool exists;
1523 if (NILP (predicate)) 1524 if (NILP (predicate))
1524 exists = !NILP (Ffile_readable_p (string)); 1525 exists = !NILP (Ffile_readable_p (string));
1525 else 1526 else
@@ -1541,40 +1542,37 @@ openp (Lisp_Object path, Lisp_Object str, Lisp_Object suffixes, Lisp_Object *sto
1541 } 1542 }
1542 else 1543 else
1543 { 1544 {
1544 int fd; 1545#ifndef WINDOWSNT
1546 struct stat st;
1547#endif
1545 const char *pfn; 1548 const char *pfn;
1546 1549
1547 encoded_fn = ENCODE_FILE (string); 1550 encoded_fn = ENCODE_FILE (string);
1548 pfn = SSDATA (encoded_fn); 1551 pfn = SSDATA (encoded_fn);
1549 1552#ifdef WINDOWSNT
1550 /* Check that we can access or open it. */ 1553 exists = access (pfn, F_OK) == 0 && access (pfn, D_OK) < 0;
1551 if (NATNUMP (predicate)) 1554#else
1552 fd = (((XFASTINT (predicate) & ~INT_MAX) == 0 1555 exists = (stat (pfn, &st) == 0 && ! S_ISDIR (st.st_mode));
1553 && (faccessat (AT_FDCWD, pfn, XFASTINT (predicate), 1556#endif
1554 AT_EACCESS) 1557 if (exists)
1555 == 0)
1556 && ! file_directory_p (pfn))
1557 ? 1 : -1);
1558 else
1559 { 1558 {
1560 struct stat st; 1559 /* Check that we can access or open it. */
1561 fd = emacs_open (pfn, O_RDONLY, 0); 1560 if (NATNUMP (predicate))
1562 if (0 <= fd 1561 fd = (((XFASTINT (predicate) & ~INT_MAX) == 0
1563 && (fstat (fd, &st) != 0 || S_ISDIR (st.st_mode))) 1562 && access (pfn, XFASTINT (predicate)) == 0)
1563 ? 1 : -1);
1564 else
1565 fd = emacs_open (pfn, O_RDONLY, 0);
1566
1567 if (fd >= 0)
1564 { 1568 {
1565 emacs_close (fd); 1569 /* We succeeded; return this descriptor and filename. */
1566 fd = -1; 1570 if (storeptr)
1571 *storeptr = string;
1572 UNGCPRO;
1573 return fd;
1567 } 1574 }
1568 } 1575 }
1569
1570 if (fd >= 0)
1571 {
1572 /* We succeeded; return this descriptor and filename. */
1573 if (storeptr)
1574 *storeptr = string;
1575 UNGCPRO;
1576 return fd;
1577 }
1578 } 1576 }
1579 } 1577 }
1580 if (absolute) 1578 if (absolute)
@@ -4090,7 +4088,7 @@ load_path_check (void)
4090 if (STRINGP (dirfile)) 4088 if (STRINGP (dirfile))
4091 { 4089 {
4092 dirfile = Fdirectory_file_name (dirfile); 4090 dirfile = Fdirectory_file_name (dirfile);
4093 if (faccessat (AT_FDCWD, SSDATA (dirfile), F_OK, AT_EACCESS) != 0) 4091 if (access (SSDATA (dirfile), 0) < 0)
4094 dir_warning ("Warning: Lisp directory `%s' does not exist.\n", 4092 dir_warning ("Warning: Lisp directory `%s' does not exist.\n",
4095 XCAR (path_tail)); 4093 XCAR (path_tail));
4096 } 4094 }