aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-01-30 23:11:55 -0800
committerPaul Eggert2015-01-30 23:12:18 -0800
commit512cdb9f2ba6dde0c24bfed13d095ea37e38a6ec (patch)
tree194a692680b2083dfc4b065cd17115a2ab0873d0
parente0be229d5f5e790338a71617a1c244029da4c75b (diff)
downloademacs-512cdb9f2ba6dde0c24bfed13d095ea37e38a6ec.tar.gz
emacs-512cdb9f2ba6dde0c24bfed13d095ea37e38a6ec.zip
Simplify read_dirent's MSDOS hacks
* dired.c (read_dirent): Simplify by removing the need for the DIR_ENTRY argument. All callers changed. This separates the MS-DOS idiosyncrasies better from the rest of the code.
-rw-r--r--src/ChangeLog7
-rw-r--r--src/dired.c21
2 files changed, 15 insertions, 13 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 2130312ccf2..ab1a748abce 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,10 @@
12015-01-31 Paul Eggert <eggert@cs.ucla.edu>
2
3 Simplify read_dirent's MSDOS hacks
4 * dired.c (read_dirent): Simplify by removing the need for the
5 DIR_ENTRY argument. All callers changed. This separates the
6 MS-DOS idiosyncrasies better from the rest of the code.
7
12015-01-30 Eli Zaretskii <eliz@gnu.org> 82015-01-30 Eli Zaretskii <eliz@gnu.org>
2 9
3 * dired.c (read_dirent): Accept an additional argument 10 * dired.c (read_dirent): Accept an additional argument
diff --git a/src/dired.c b/src/dired.c
index 56d6de2d352..931279a0764 100644
--- a/src/dired.c
+++ b/src/dired.c
@@ -124,11 +124,10 @@ directory_files_internal_unwind (void *dh)
124 124
125/* Return the next directory entry from DIR; DIR's name is DIRNAME. 125/* Return the next directory entry from DIR; DIR's name is DIRNAME.
126 If there are no more directory entries, return a null pointer. 126 If there are no more directory entries, return a null pointer.
127 Signal any unrecoverable errors. FIRST_ENTRY true means this is 127 Signal any unrecoverable errors. */
128 the first call after open_directory. */
129 128
130static struct dirent * 129static struct dirent *
131read_dirent (DIR *dir, Lisp_Object dirname, bool first_entry) 130read_dirent (DIR *dir, Lisp_Object dirname)
132{ 131{
133 while (true) 132 while (true)
134 { 133 {
@@ -138,14 +137,15 @@ read_dirent (DIR *dir, Lisp_Object dirname, bool first_entry)
138 return dp; 137 return dp;
139 if (! (errno == EAGAIN || errno == EINTR)) 138 if (! (errno == EAGAIN || errno == EINTR))
140 { 139 {
140#ifdef MSDOS
141 /* The MS-Windows implementation of 'opendir' doesn't 141 /* The MS-Windows implementation of 'opendir' doesn't
142 actually open a directory until the first call to 142 actually open a directory until the first call to
143 'readdir'. If 'readdir' fails to open the directory, it 143 'readdir'. If 'readdir' fails to open the directory, it
144 sets errno to ENOENT or EACCES, see w32.c. */ 144 sets errno to ENOENT or EACCES, see w32.c. */
145 if (first_entry && (errno == ENOENT || errno == EACCES)) 145 if (errno == ENOENT || errno == EACCES)
146 report_file_error ("Opening directory", dirname); 146 report_file_error ("Opening directory", dirname);
147 else 147#endif
148 report_file_error ("Reading directory", dirname); 148 report_file_error ("Reading directory", dirname);
149 } 149 }
150 QUIT; 150 QUIT;
151 } 151 }
@@ -249,8 +249,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
249 needsep = 1; 249 needsep = 1;
250 250
251 /* Loop reading directory entries. */ 251 /* Loop reading directory entries. */
252 bool first_entry = true; 252 for (struct dirent *dp; (dp = read_dirent (d, directory)); )
253 for (struct dirent *dp; (dp = read_dirent (d, directory, first_entry)); )
254 { 253 {
255 ptrdiff_t len = dirent_namelen (dp); 254 ptrdiff_t len = dirent_namelen (dp);
256 Lisp_Object name = make_unibyte_string (dp->d_name, len); 255 Lisp_Object name = make_unibyte_string (dp->d_name, len);
@@ -258,8 +257,6 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
258 struct gcpro gcpro1, gcpro2; 257 struct gcpro gcpro1, gcpro2;
259 GCPRO2 (finalname, name); 258 GCPRO2 (finalname, name);
260 259
261 first_entry = false;
262
263 /* Note: DECODE_FILE can GC; it should protect its argument, 260 /* Note: DECODE_FILE can GC; it should protect its argument,
264 though. */ 261 though. */
265 name = DECODE_FILE (name); 262 name = DECODE_FILE (name);
@@ -499,13 +496,11 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
499 record_unwind_protect_ptr (directory_files_internal_unwind, d); 496 record_unwind_protect_ptr (directory_files_internal_unwind, d);
500 497
501 /* Loop reading directory entries. */ 498 /* Loop reading directory entries. */
502 bool first_entry = true; 499 for (struct dirent *dp; (dp = read_dirent (d, dirname)); )
503 for (struct dirent *dp; (dp = read_dirent (d, dirname, first_entry)); )
504 { 500 {
505 ptrdiff_t len = dirent_namelen (dp); 501 ptrdiff_t len = dirent_namelen (dp);
506 bool canexclude = 0; 502 bool canexclude = 0;
507 503
508 first_entry = false;
509 QUIT; 504 QUIT;
510 if (len < SCHARS (encoded_file) 505 if (len < SCHARS (encoded_file)
511 || (scmp (dp->d_name, SSDATA (encoded_file), 506 || (scmp (dp->d_name, SSDATA (encoded_file),