diff options
| author | Paul Eggert | 2015-01-29 19:01:28 -0800 |
|---|---|---|
| committer | Paul Eggert | 2015-01-29 19:02:01 -0800 |
| commit | 34d0859c4b092b6a1daed3c674f1f4e3f05d5189 (patch) | |
| tree | c7f9d7e3dcedf0f2c9a80f2026c68a0b9706ca98 /src | |
| parent | 9242cdcda95e0fcb57233a8665d251e280eddec6 (diff) | |
| download | emacs-34d0859c4b092b6a1daed3c674f1f4e3f05d5189.tar.gz emacs-34d0859c4b092b6a1daed3c674f1f4e3f05d5189.zip | |
Refactor calls to opendir for simplicity
* dired.c (open_directory): Accept Lisp_Object, not char *, for
dirname. Signal an error if the open fails. All callers changed.
Diffstat (limited to 'src')
| -rw-r--r-- | src/ChangeLog | 6 | ||||
| -rw-r--r-- | src/dired.c | 23 |
2 files changed, 14 insertions, 15 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 029ac88a28f..67b6fa01b59 100644 --- a/src/ChangeLog +++ b/src/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2015-01-30 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Refactor calls to opendir for simplicity | ||
| 4 | * dired.c (open_directory): Accept Lisp_Object, not char *, for | ||
| 5 | dirname. Signal an error if the open fails. All callers changed. | ||
| 6 | |||
| 1 | 2015-01-29 Paul Eggert <eggert@cs.ucla.edu> | 7 | 2015-01-29 Paul Eggert <eggert@cs.ucla.edu> |
| 2 | 8 | ||
| 3 | Report readdir failures | 9 | Report readdir failures |
diff --git a/src/dired.c b/src/dired.c index 23a867463f4..7982c1fb8eb 100644 --- a/src/dired.c +++ b/src/dired.c | |||
| @@ -66,8 +66,9 @@ dirent_namelen (struct dirent *dp) | |||
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | static DIR * | 68 | static DIR * |
| 69 | open_directory (char const *name, int *fdp) | 69 | open_directory (Lisp_Object dirname, int *fdp) |
| 70 | { | 70 | { |
| 71 | char *name = SSDATA (dirname); | ||
| 71 | DIR *d; | 72 | DIR *d; |
| 72 | int fd, opendir_errno; | 73 | int fd, opendir_errno; |
| 73 | 74 | ||
| @@ -98,8 +99,9 @@ open_directory (char const *name, int *fdp) | |||
| 98 | 99 | ||
| 99 | unblock_input (); | 100 | unblock_input (); |
| 100 | 101 | ||
| 102 | if (!d) | ||
| 103 | report_file_errno ("Opening directory", dirname, opendir_errno); | ||
| 101 | *fdp = fd; | 104 | *fdp = fd; |
| 102 | errno = opendir_errno; | ||
| 103 | return d; | 105 | return d; |
| 104 | } | 106 | } |
| 105 | 107 | ||
| @@ -149,8 +151,6 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, | |||
| 149 | Lisp_Object match, Lisp_Object nosort, bool attrs, | 151 | Lisp_Object match, Lisp_Object nosort, bool attrs, |
| 150 | Lisp_Object id_format) | 152 | Lisp_Object id_format) |
| 151 | { | 153 | { |
| 152 | DIR *d; | ||
| 153 | int fd; | ||
| 154 | ptrdiff_t directory_nbytes; | 154 | ptrdiff_t directory_nbytes; |
| 155 | Lisp_Object list, dirfilename, encoded_directory; | 155 | Lisp_Object list, dirfilename, encoded_directory; |
| 156 | struct re_pattern_buffer *bufp = NULL; | 156 | struct re_pattern_buffer *bufp = NULL; |
| @@ -200,9 +200,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, | |||
| 200 | /* Now *bufp is the compiled form of MATCH; don't call anything | 200 | /* Now *bufp is the compiled form of MATCH; don't call anything |
| 201 | which might compile a new regexp until we're done with the loop! */ | 201 | which might compile a new regexp until we're done with the loop! */ |
| 202 | 202 | ||
| 203 | d = open_directory (SSDATA (dirfilename), &fd); | 203 | int fd; |
| 204 | if (d == NULL) | 204 | DIR *d = open_directory (dirfilename, &fd); |
| 205 | report_file_error ("Opening directory", directory); | ||
| 206 | 205 | ||
| 207 | /* Unfortunately, we can now invoke expand-file-name and | 206 | /* Unfortunately, we can now invoke expand-file-name and |
| 208 | file-attributes on filenames, both of which can throw, so we must | 207 | file-attributes on filenames, both of which can throw, so we must |
| @@ -448,8 +447,6 @@ static Lisp_Object | |||
| 448 | file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, | 447 | file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, |
| 449 | Lisp_Object predicate) | 448 | Lisp_Object predicate) |
| 450 | { | 449 | { |
| 451 | DIR *d; | ||
| 452 | int fd; | ||
| 453 | ptrdiff_t bestmatchsize = 0; | 450 | ptrdiff_t bestmatchsize = 0; |
| 454 | int matchcount = 0; | 451 | int matchcount = 0; |
| 455 | /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded. | 452 | /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded. |
| @@ -483,13 +480,9 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, | |||
| 483 | work with decoded file names, but we still do some filtering based | 480 | work with decoded file names, but we still do some filtering based |
| 484 | on the encoded file name. */ | 481 | on the encoded file name. */ |
| 485 | encoded_file = ENCODE_FILE (file); | 482 | encoded_file = ENCODE_FILE (file); |
| 486 | |||
| 487 | encoded_dir = ENCODE_FILE (Fdirectory_file_name (dirname)); | 483 | encoded_dir = ENCODE_FILE (Fdirectory_file_name (dirname)); |
| 488 | 484 | int fd; | |
| 489 | d = open_directory (SSDATA (encoded_dir), &fd); | 485 | DIR *d = open_directory (encoded_dir, &fd); |
| 490 | if (!d) | ||
| 491 | report_file_error ("Opening directory", dirname); | ||
| 492 | |||
| 493 | record_unwind_protect_ptr (directory_files_internal_unwind, d); | 486 | record_unwind_protect_ptr (directory_files_internal_unwind, d); |
| 494 | 487 | ||
| 495 | /* Loop reading directory entries. */ | 488 | /* Loop reading directory entries. */ |