return Qnil;
}
-/* Function shared by Fdirectory_files and Fdirectory_files_and_attributes.
+/* 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. */
Ffuncall, and cause a GC. */
list = encoded_directory = dirfilename = Qnil;
GCPRO5 (match, directory, list, dirfilename, encoded_directory);
- directory = Fexpand_file_name (directory, Qnil);
dirfilename = Fdirectory_file_name (directory);
if (!NILP (match))
have to make sure it gets closed, and setting up an
unwind_protect to do so would be a pain. */
retry:
-
+
d = opendir (SDATA (dirfilename));
if (d == NULL)
report_file_error ("Opening directory", Fcons (directory, Qnil));
if (dp == NULL && errno == EAGAIN)
continue;
#endif
-
+
if (dp == NULL)
break;
len = NAMLEN (dp);
name = finalname = make_unibyte_string (dp->d_name, len);
GCPRO2 (finalname, name);
-
+
/* Note: ENCODE_FILE can GC; it should protect its argument,
though. */
name = DECODE_FILE (name);
fullname = make_uninit_multibyte_string (nbytes, nbytes);
bcopy (SDATA (directory), SDATA (fullname),
directory_nbytes);
-
+
if (needsep)
- SREF (fullname, directory_nbytes) = DIRECTORY_SEP;
-
+ SSET (fullname, directory_nbytes, DIRECTORY_SEP);
+
bcopy (SDATA (name),
SDATA (fullname) + directory_nbytes + needsep,
len);
-
+
nchars = chars_in_text (SDATA (fullname), nbytes);
/* Some bug somewhere. */
if (nchars > nbytes)
abort ();
-
- SCHARS (fullname) = nchars;
+
+ STRING_SET_CHARS (fullname, nchars);
if (nchars == nbytes)
STRING_SET_UNIBYTE (fullname);
-
+
finalname = fullname;
}
else
if (NILP (nosort))
list = Fsort (Fnreverse (list),
attrs ? Qfile_attributes_lessp : Qstring_lessp);
-
+
RETURN_UNGCPRO (list);
}
Lisp_Object directory, full, match, nosort;
{
Lisp_Object handler;
+ directory = Fexpand_file_name (directory, Qnil);
/* If the file name has special constructs in it,
call the corresponding file handler. */
Lisp_Object directory, full, match, nosort;
{
Lisp_Object handler;
+ directory = Fexpand_file_name (directory, Qnil);
/* If the file name has special constructs in it,
call the corresponding file handler. */
for (passcount = !!all_flag; NILP (bestmatch) && passcount < 2; passcount++)
{
+ int inner_count = SPECPDL_INDEX ();
+
d = opendir (SDATA (Fdirectory_file_name (encoded_dir)));
if (!d)
report_file_error ("Opening directory", Fcons (dirname, Qnil));
+ record_unwind_protect (directory_files_internal_unwind,
+ Fcons (make_number (((unsigned long) d) >> 16),
+ make_number (((unsigned long) d) & 0xffff)));
+
/* Loop reading blocks */
/* (att3b compiler bug requires do a null comparison this way) */
while (1)
len = NAMLEN (dp);
- if (!NILP (Vquit_flag) && NILP (Vinhibit_quit))
- goto quit;
+ QUIT;
if (! DIRENTRY_NONEMPTY (dp)
|| len < SCHARS (encoded_file)
|| 0 <= scmp (dp->d_name, SDATA (encoded_file),
/* This tests that the current file is an exact match
but BESTMATCH is not (it is too long). */
if ((matchsize == len
- && matchsize + !!directoryp
+ && matchsize + !!directoryp
< SCHARS (bestmatch))
||
/* If there is no exact match ignoring case,
either both or neither are exact. */
(((matchsize == len)
==
- (matchsize + !!directoryp
+ (matchsize + !!directoryp
== SCHARS (bestmatch)))
&& !bcmp (p2, SDATA (encoded_file), SCHARS (encoded_file))
&& bcmp (p1, SDATA (encoded_file), SCHARS (encoded_file))))
bestmatchsize = matchsize;
}
}
- closedir (d);
+ /* This closes the directory. */
+ bestmatch = unbind_to (inner_count, bestmatch);
}
UNGCPRO;
decode it from the coding system in use. */
bestmatch = DECODE_FILE (bestmatch);
return bestmatch;
-
- quit:
- if (d) closedir (d);
- Vquit_flag = Qnil;
- return Fsignal (Qquit, Qnil);
}
/* Compare exactly LEN chars of strings at S1 and S2,
/* If the size is out of range for an integer, return a float. */
if (XINT (values[7]) != s.st_size)
values[7] = make_float ((double)s.st_size);
+ /* If the size is negative, and its type is long, convert it back to
+ positive. */
+ if (s.st_size < 0 && sizeof (s.st_size) == sizeof (long))
+ values[7] = make_float ((double) ((unsigned long) s.st_size));
+
filemodestring (&s, modes);
values[8] = make_string (modes, 10);
#if defined (BSD4_2) || defined (BSD4_3) /* file gid will be dir gid */
#else /* file gid will be egid */
values[9] = (s.st_gid != getegid ()) ? Qt : Qnil;
#endif /* BSD4_2 (or BSD4_3) */
- /* Cast -1 to avoid warning if int is not as wide as VALBITS. */
if (FIXNUM_OVERFLOW_P (s.st_ino))
/* To allow inode numbers larger than VALBITS, separate the bottom
16 bits. */