X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/90207a152538c00b6c75b9774b528470dfb42717..2e7cddd30317b7951c5425a5769ac9f33136f72f:/src/dired.c diff --git a/src/dired.c b/src/dired.c index 367bcb4031..4986f84510 100644 --- a/src/dired.c +++ b/src/dired.c @@ -22,7 +22,6 @@ along with GNU Emacs. If not, see . */ #include #include #include -#include #ifdef HAVE_PWD_H #include @@ -62,6 +61,7 @@ extern struct direct *readdir (DIR *); #endif /* HAVE_DIRENT_H */ #include +#include #ifdef MSDOS #define DIRENTRY_NONEMPTY(p) ((p)->d_name[0] != 0) @@ -71,9 +71,9 @@ extern struct direct *readdir (DIR *); #include "lisp.h" #include "systime.h" +#include "character.h" #include "buffer.h" #include "commands.h" -#include "character.h" #include "charset.h" #include "coding.h" #include "regex.h" @@ -86,8 +86,7 @@ static Lisp_Object Qfile_name_all_completions; static Lisp_Object Qfile_attributes; static Lisp_Object Qfile_attributes_lessp; -static int scmp (const char *, const char *, int); -static Lisp_Object Ffile_attributes (Lisp_Object, Lisp_Object); +static ptrdiff_t scmp (const char *, const char *, ptrdiff_t); #ifdef WINDOWSNT Lisp_Object @@ -102,26 +101,28 @@ static Lisp_Object directory_files_internal_unwind (Lisp_Object dh) { DIR *d = (DIR *) XSAVE_VALUE (dh)->pointer; - BLOCK_INPUT; + block_input (); closedir (d); - UNBLOCK_INPUT; + unblock_input (); return Qnil; } /* Function shared by Fdirectory_files and Fdirectory_files_and_attributes. - When ATTRS is zero, return a list of directory filenames; when - non-zero, return a list of directory filenames and their attributes. + If not ATTRS, return a list of directory filenames; + if ATTRS, return a list of directory filenames and their attributes. In the latter case, ID_FORMAT is passed to Ffile_attributes. */ Lisp_Object -directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, int attrs, Lisp_Object id_format) +directory_files_internal (Lisp_Object directory, Lisp_Object full, + Lisp_Object match, Lisp_Object nosort, bool attrs, + Lisp_Object id_format) { DIR *d; - int directory_nbytes; + ptrdiff_t directory_nbytes; Lisp_Object list, dirfilename, encoded_directory; struct re_pattern_buffer *bufp = NULL; - int needsep = 0; - int count = SPECPDL_INDEX (); + bool needsep = 0; + ptrdiff_t count = SPECPDL_INDEX (); struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; DIRENTRY *dp; #ifdef WINDOWSNT @@ -163,9 +164,9 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m /* Now *bufp is the compiled form of MATCH; don't call anything which might compile a new regexp until we're done with the loop! */ - BLOCK_INPUT; + block_input (); d = opendir (SSDATA (dirfilename)); - UNBLOCK_INPUT; + unblock_input (); if (d == NULL) report_file_error ("Opening directory", Fcons (directory, Qnil)); @@ -226,8 +227,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m if (DIRENTRY_NONEMPTY (dp)) { - int len; - int wanted = 0; + ptrdiff_t len; + bool wanted = 0; Lisp_Object name, finalname; struct gcpro gcpro1, gcpro2; @@ -256,8 +257,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m if (!NILP (full)) { Lisp_Object fullname; - int nbytes = len + directory_nbytes + needsep; - int nchars; + ptrdiff_t nbytes = len + directory_nbytes + needsep; + ptrdiff_t nchars; fullname = make_uninit_multibyte_string (nbytes, nbytes); memcpy (SDATA (fullname), SDATA (directory), @@ -273,7 +274,7 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m /* Some bug somewhere. */ if (nchars > nbytes) - abort (); + emacs_abort (); STRING_SET_CHARS (fullname, nchars); if (nchars == nbytes) @@ -309,9 +310,9 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object m } } - BLOCK_INPUT; + block_input (); closedir (d); - UNBLOCK_INPUT; + unblock_input (); #ifdef WINDOWSNT if (attrs) Vw32_get_true_file_attributes = w32_save; @@ -381,9 +382,8 @@ which see. */) } -static Lisp_Object file_name_completion - (Lisp_Object file, Lisp_Object dirname, int all_flag, int ver_flag, - Lisp_Object predicate); +static Lisp_Object file_name_completion (Lisp_Object, Lisp_Object, bool, + Lisp_Object); DEFUN ("file-name-completion", Ffile_name_completion, Sfile_name_completion, 2, 3, 0, @@ -415,7 +415,7 @@ determined by the variable `completion-ignored-extensions', which see. */) if (!NILP (handler)) return call4 (handler, Qfile_name_completion, file, directory, predicate); - return file_name_completion (file, directory, 0, 0, predicate); + return file_name_completion (file, directory, 0, predicate); } DEFUN ("file-name-all-completions", Ffile_name_all_completions, @@ -439,17 +439,18 @@ These are all file names in directory DIRECTORY which begin with FILE. */) if (!NILP (handler)) return call3 (handler, Qfile_name_all_completions, file, directory); - return file_name_completion (file, directory, 1, 0, Qnil); + return file_name_completion (file, directory, 1, Qnil); } static int file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_addr); static Lisp_Object Qdefault_directory; static Lisp_Object -file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int ver_flag, Lisp_Object predicate) +file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, + Lisp_Object predicate) { DIR *d; - int bestmatchsize = 0; + ptrdiff_t bestmatchsize = 0; int matchcount = 0; /* If ALL_FLAG is 1, BESTMATCH is the list of all matches, decoded. If ALL_FLAG is 0, BESTMATCH is either nil @@ -458,21 +459,18 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v Lisp_Object encoded_file; Lisp_Object encoded_dir; struct stat st; - int directoryp; - /* If includeall is zero, exclude files in completion-ignored-extensions as + bool directoryp; + /* If not INCLUDEALL, exclude files in completion-ignored-extensions as well as "." and "..". Until shown otherwise, assume we can't exclude anything. */ - int includeall = 1; - int count = SPECPDL_INDEX (); + bool includeall = 1; + ptrdiff_t count = SPECPDL_INDEX (); struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; elt = Qnil; CHECK_STRING (file); -#ifdef FILE_SYSTEM_CASE - file = FILE_SYSTEM_CASE (file); -#endif bestmatch = Qnil; encoded_file = encoded_dir = Qnil; GCPRO5 (file, dirname, bestmatch, encoded_file, encoded_dir); @@ -488,9 +486,9 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v encoded_dir = ENCODE_FILE (dirname); - BLOCK_INPUT; + block_input (); d = opendir (SSDATA (Fdirectory_file_name (encoded_dir))); - UNBLOCK_INPUT; + unblock_input (); if (!d) report_file_error ("Opening directory", Fcons (dirname, Qnil)); @@ -502,8 +500,8 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v while (1) { DIRENTRY *dp; - int len; - int canexclude = 0; + ptrdiff_t len; + bool canexclude = 0; errno = 0; dp = readdir (d); @@ -531,14 +529,14 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v if (file_name_completion_stat (encoded_dir, dp, &st) < 0) continue; - directoryp = S_ISDIR (st.st_mode); + directoryp = S_ISDIR (st.st_mode) != 0; tem = Qnil; /* If all_flag is set, always include all. It would not actually be helpful to the user to ignore any possible completions when making a list of them. */ if (!all_flag) { - int skip; + ptrdiff_t skip; #if 0 /* FIXME: The `scmp' call compares an encoded and a decoded string. */ /* If this entry matches the current bestmatch, the only @@ -568,7 +566,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v for (tem = Vcompletion_ignored_extensions; CONSP (tem); tem = XCDR (tem)) { - int elt_len; + ptrdiff_t elt_len; char *p1; elt = XCAR (tem); @@ -685,7 +683,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v /* Suitably record this match. */ - matchcount++; + matchcount += matchcount <= 1; if (all_flag) bestmatch = Fcons (name, bestmatch); @@ -698,14 +696,14 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v { Lisp_Object zero = make_number (0); /* FIXME: This is a copy of the code in Ftry_completion. */ - int compare = min (bestmatchsize, SCHARS (name)); + ptrdiff_t compare = min (bestmatchsize, SCHARS (name)); Lisp_Object cmp = Fcompare_strings (bestmatch, zero, make_number (compare), name, zero, make_number (compare), completion_ignore_case ? Qt : Qnil); - int matchsize + ptrdiff_t matchsize = (EQ (cmp, Qt) ? compare : XINT (cmp) < 0 ? - XINT (cmp) - 1 : XINT (cmp) - 1); @@ -719,7 +717,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v /* This tests that the current file is an exact match but BESTMATCH is not (it is too long). */ if ((matchsize == SCHARS (name) - && matchsize + !!directoryp < SCHARS (bestmatch)) + && matchsize + directoryp < SCHARS (bestmatch)) || /* If there is no exact match ignoring case, prefer a match that does not change the case @@ -731,7 +729,7 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v either both or neither are exact. */ (((matchsize == SCHARS (name)) == - (matchsize + !!directoryp == SCHARS (bestmatch))) + (matchsize + directoryp == SCHARS (bestmatch))) && (cmp = Fcompare_strings (name, zero, make_number (SCHARS (file)), file, zero, @@ -784,10 +782,10 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, int all_flag, int v Return -1 if strings match, else number of chars that match at the beginning. */ -static int -scmp (const char *s1, const char *s2, int len) +static ptrdiff_t +scmp (const char *s1, const char *s2, ptrdiff_t len) { - register int l = len; + register ptrdiff_t l = len; if (completion_ignore_case) { @@ -810,10 +808,11 @@ scmp (const char *s1, const char *s2, int len) static int file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_addr) { - int len = NAMLEN (dp); - int pos = SCHARS (dirname); + ptrdiff_t len = NAMLEN (dp); + ptrdiff_t pos = SCHARS (dirname); int value; - char *fullname = (char *) alloca (len + pos + 2); + USE_SAFE_ALLOCA; + char *fullname = SAFE_ALLOCA (len + pos + 2); #ifdef MSDOS /* Some fields of struct stat are *very* expensive to compute on MS-DOS, @@ -842,6 +841,7 @@ file_name_completion_stat (Lisp_Object dirname, DIRENTRY *dp, struct stat *st_ad #ifdef MSDOS _djstat_flags = save_djstat_flags; #endif /* MSDOS */ + SAFE_FREE (); return value; } @@ -890,8 +890,8 @@ Elements of the attribute list are: 2. File uid as a string or a number. If a string value cannot be looked up, a numeric value, either an integer or a float, is returned. 3. File gid, likewise. - 4. Last access time, as a list of two integers. - First integer has high-order 16 bits of time, second has low 16 bits. + 4. Last access time, as a list of integers (HIGH LOW USEC PSEC) in the + same style as (current-time). (See a note below about access time on FAT-based filesystems.) 5. Last modification time, likewise. This is the time of the last change to the file's contents. @@ -962,10 +962,10 @@ so last access time will always be midnight of that day. */) if (!(NILP (id_format) || EQ (id_format, Qinteger))) { - BLOCK_INPUT; + block_input (); uname = stat_uname (&s); gname = stat_gname (&s); - UNBLOCK_INPUT; + unblock_input (); } if (uname) values[2] = DECODE_SYSTEM (build_string (uname)); @@ -976,9 +976,9 @@ so last access time will always be midnight of that day. */) else values[3] = make_fixnum_or_float (s.st_gid); - values[4] = make_time (s.st_atime); - values[5] = make_time (s.st_mtime); - values[6] = make_time (s.st_ctime); + values[4] = make_lisp_time (get_stat_atime (&s)); + values[5] = make_lisp_time (get_stat_mtime (&s)); + values[6] = make_lisp_time (get_stat_ctime (&s)); /* If the file size is a 4-byte type, assume that files of sizes in the 2-4 GiB range wrap around to negative values, as this is a