comparison src/dired.c @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 2e6f5e180fb8
children 1ce6082ce73f
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
51 if FILES-ONLY is nil (the default) then both files and subdirectories will 51 if FILES-ONLY is nil (the default) then both files and subdirectories will
52 be returned. 52 be returned.
53 */ 53 */
54 (dirname, full, match, nosort, files_only)) 54 (dirname, full, match, nosort, files_only))
55 { 55 {
56 /* This function can GC. GC checked 1997.04.06. */ 56 /* This function can GC */
57 DIR *d; 57 DIR *d;
58 Bytecount dirname_length; 58 Bytecount dirname_length;
59 Lisp_Object list, name, dirfilename = Qnil; 59 Lisp_Object list, name, dirfilename = Qnil;
60 Lisp_Object handler; 60 Lisp_Object handler;
61 Lisp_Object errstring;
62 struct re_pattern_buffer *bufp; 61 struct re_pattern_buffer *bufp;
63 62
64 char statbuf [4096]; /* BOGUS -- fixed in 20.3 */ 63 char statbuf [MAXNAMLEN+2];
65 char *statbuf_tail; 64 char *statbuf_tail;
66 Lisp_Object tail_cons = Qnil; 65 Lisp_Object tail_cons = Qnil;
67 char slashfilename[4096]; /* BOGUS -- fixed in 20.3 */ 66 char slashfilename[MAXNAMLEN+2];
68 char *filename = slashfilename; 67 char *filename = slashfilename;
69 68
70 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4; 69 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
71 GCPRO4 (dirname, dirfilename, tail_cons, errstring); 70
71 /* #### Needs more gcpro's */
72 GCPRO5 (dirname, match, files_only, tail_cons, dirfilename);
72 73
73 /* If the file name has special constructs in it, 74 /* If the file name has special constructs in it,
74 call the corresponding file handler. */ 75 call the corresponding file handler. */
75 handler = Ffind_file_name_handler (dirname, Qdirectory_files); 76 handler = Ffind_file_name_handler (dirname, Qdirectory_files);
76 if (!NILP (handler)) 77 if (!NILP (handler))
82 else 83 else
83 return call5 (handler, Qdirectory_files, dirname, full, match, 84 return call5 (handler, Qdirectory_files, dirname, full, match,
84 nosort); 85 nosort);
85 } 86 }
86 87
87 /* #### why do we do Fexpand_file_name after file handlers here,
88 but earlier everywhere else? */
89 dirname = Fexpand_file_name (dirname, Qnil); 88 dirname = Fexpand_file_name (dirname, Qnil);
90 dirfilename = Fdirectory_file_name (dirname); 89 dirfilename = Fdirectory_file_name (dirname);
91 90
92 { 91 {
93 /* XEmacs: this should come before the opendir() because it might error. */ 92 /* XEmacs: this should come before the opendir() because it might error. */
94 Lisp_Object name_as_dir = Ffile_name_as_directory (dirname); 93 Lisp_Object name_as_dir = Ffile_name_as_directory (dirname);
95 CHECK_STRING (name_as_dir); 94 CHECK_STRING (name_as_dir);
96 if (XSTRING_LENGTH(name_as_dir) >= sizeof (statbuf))
97 {
98 report_file_error("Directory name too long", list1(name_as_dir));
99 }
100 memcpy (statbuf, ((char *) XSTRING_DATA (name_as_dir)), 95 memcpy (statbuf, ((char *) XSTRING_DATA (name_as_dir)),
101 XSTRING_LENGTH (name_as_dir)); 96 XSTRING_LENGTH (name_as_dir));
102 statbuf_tail = statbuf + XSTRING_LENGTH (name_as_dir); 97 statbuf_tail = statbuf + XSTRING_LENGTH (name_as_dir);
103 } 98 }
104 99
137 list = Qnil; 132 list = Qnil;
138 tail_cons = Qnil; 133 tail_cons = Qnil;
139 dirname_length = XSTRING_LENGTH (dirname); 134 dirname_length = XSTRING_LENGTH (dirname);
140 #ifndef VMS 135 #ifndef VMS
141 if (dirname_length == 0 136 if (dirname_length == 0
142 || !IS_ANY_SEP (XSTRING_BYTE (dirname, dirname_length - 1))) 137 || !IS_ANY_SEP (string_byte (XSTRING (dirname), dirname_length - 1)))
143 { 138 {
144 if ((filename - slashfilename) >= (sizeof (slashfilename) - 1))
145 {
146 closedir(d);
147 errstring = make_string(statbuf, 255);
148 report_file_error("Directory name too long", list1(errstring));
149 }
150 *filename++ = DIRECTORY_SEP; 139 *filename++ = DIRECTORY_SEP;
151 dirname_length++; 140 dirname_length++;
152 } 141 }
153 #endif /* VMS */ 142 #endif /* VMS */
154 143
162 len = NAMLEN (dp); 151 len = NAMLEN (dp);
163 if (DIRENTRY_NONEMPTY (dp)) 152 if (DIRENTRY_NONEMPTY (dp))
164 { 153 {
165 int result; 154 int result;
166 Lisp_Object oinhibit_quit = Vinhibit_quit; 155 Lisp_Object oinhibit_quit = Vinhibit_quit;
167 if (((filename - slashfilename) + len) >=
168 (sizeof (slashfilename) - 1))
169 {
170 closedir(d);
171 errstring = make_string(slashfilename, 255);
172 report_file_error("Directory name too long", list1(errstring));
173 }
174 strncpy (filename, dp->d_name, len); 156 strncpy (filename, dp->d_name, len);
175 filename[len] = 0; 157 filename[len] = 0;
176 /* re_search can now QUIT, so prevent it to avoid 158 /* re_search can now QUIT, so prevent it to avoid
177 filedesc lossage */ 159 filedesc lossage */
178 Vinhibit_quit = Qt; 160 Vinhibit_quit = Qt;
184 if (!NILP (files_only)) 166 if (!NILP (files_only))
185 { 167 {
186 int dir_p; 168 int dir_p;
187 struct stat st; 169 struct stat st;
188 170
189 if (((statbuf_tail - statbuf) + len) >=
190 (sizeof (statbuf) - 1))
191 {
192 closedir(d);
193 errstring = make_string(statbuf, 255);
194 report_file_error("Directory name too long",
195 list1(errstring));
196 }
197 memcpy (statbuf_tail, filename, len); 171 memcpy (statbuf_tail, filename, len);
198 statbuf_tail [len] = 0; 172 statbuf_tail [len] = 0;
199 173
200 if (stat (statbuf, &st) < 0) 174 if (stat (statbuf, &st) < 0)
201 dir_p = 0; 175 dir_p = 0;
249 other possible completion. `completion-ignored-extensions' is not applied 223 other possible completion. `completion-ignored-extensions' is not applied
250 to the names of directories. 224 to the names of directories.
251 */ 225 */
252 (file, dirname)) 226 (file, dirname))
253 { 227 {
254 /* This function can GC. GC checked 1996.04.06. */ 228 /* This function can GC */
255 Lisp_Object handler; 229 Lisp_Object handler;
256 230
257 /* If the directory name has special constructs in it, 231 /* If the directory name has special constructs in it,
258 call the corresponding file handler. */ 232 call the corresponding file handler. */
259 handler = Ffind_file_name_handler (dirname, Qfile_name_completion); 233 handler = Ffind_file_name_handler (dirname, Qfile_name_completion);
278 other possible completion. `completion-ignored-extensions' is not applied 252 other possible completion. `completion-ignored-extensions' is not applied
279 to the names of directories. 253 to the names of directories.
280 */ 254 */
281 (file, dirname)) 255 (file, dirname))
282 { 256 {
283 /* This function can GC. GC checked 1997.06.04. */ 257 /* This function can GC */
284 Lisp_Object handler; 258 Lisp_Object handler;
285 struct gcpro gcpro1; 259
286
287 GCPRO1 (dirname);
288 dirname = Fexpand_file_name (dirname, Qnil);
289 /* If the file name has special constructs in it, 260 /* If the file name has special constructs in it,
290 call the corresponding file handler. */ 261 call the corresponding file handler. */
291 handler = Ffind_file_name_handler (dirname, Qfile_name_all_completions); 262 handler = Ffind_file_name_handler (dirname, Qfile_name_all_completions);
292 UNGCPRO;
293 if (!NILP (handler)) 263 if (!NILP (handler))
294 return call3 (handler, Qfile_name_all_completions, file, 264 return call3 (handler, Qfile_name_all_completions, file,
295 dirname); 265 dirname);
296 266
297 return file_name_completion (file, dirname, 1, 0); 267 return file_name_completion (file, dirname, 1, 0);
643 613
644 If file does not exist, returns nil. 614 If file does not exist, returns nil.
645 */ 615 */
646 (filename)) 616 (filename))
647 { 617 {
648 /* This function can GC. GC checked 1997.06.04. */ 618 /* This function can GC */
649 Lisp_Object values[12]; 619 Lisp_Object values[12];
650 Lisp_Object dirname = Qnil; 620 Lisp_Object dirname = Qnil;
651 struct stat s; 621 struct stat s;
652 char modes[10]; 622 char modes[10];
653 Lisp_Object handler; 623 Lisp_Object handler;
654 struct gcpro gcpro1, gcpro2; 624 struct gcpro gcpro1, gcpro2;
655 625
656 GCPRO2 (filename, dirname); 626 GCPRO1 (filename);
657 filename = Fexpand_file_name (filename, Qnil); 627 filename = Fexpand_file_name (filename, Qnil);
658 628
659 /* If the file name has special constructs in it, 629 /* If the file name has special constructs in it,
660 call the corresponding file handler. */ 630 call the corresponding file handler. */
661 handler = Ffind_file_name_handler (filename, Qfile_attributes); 631 handler = Ffind_file_name_handler (filename, Qfile_attributes);
632 UNGCPRO;
662 if (!NILP (handler)) 633 if (!NILP (handler))
663 { 634 return call2 (handler, Qfile_attributes, filename);
664 UNGCPRO;
665 return call2 (handler, Qfile_attributes, filename);
666 }
667 635
668 if (lstat ((char *) XSTRING_DATA (filename), &s) < 0) 636 if (lstat ((char *) XSTRING_DATA (filename), &s) < 0)
669 { 637 return Qnil;
670 UNGCPRO; 638
671 return Qnil; 639 GCPRO2 (filename, dirname);
672 }
673 640
674 #ifdef BSD4_2 641 #ifdef BSD4_2
675 dirname = Ffile_name_directory (filename); 642 dirname = Ffile_name_directory (filename);
676 #endif 643 #endif
677 644