comparison src/dired.c @ 60:2e6f5e180fb8 r19-16-pre5

Import from CVS: tag r19-16-pre5
author cvs
date Mon, 13 Aug 2007 08:58:59 +0200
parents 56c54cf7c5b6
children 131b0175ea99
comparison
equal deleted inserted replaced
59:37115eea810c 60:2e6f5e180fb8
56 /* This function can GC. GC checked 1997.04.06. */ 56 /* This function can GC. GC checked 1997.04.06. */
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;
61 struct re_pattern_buffer *bufp; 62 struct re_pattern_buffer *bufp;
62 63
63 char statbuf [MAXNAMLEN+2]; 64 char statbuf [4096]; /* BOGUS -- fixed in 20.3 */
64 char *statbuf_tail; 65 char *statbuf_tail;
65 Lisp_Object tail_cons = Qnil; 66 Lisp_Object tail_cons = Qnil;
66 char slashfilename[MAXNAMLEN+2]; 67 char slashfilename[4096]; /* BOGUS -- fixed in 20.3 */
67 char *filename = slashfilename; 68 char *filename = slashfilename;
68 69
69 struct gcpro gcpro1, gcpro2, gcpro3; 70 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
70 GCPRO3 (dirname, dirfilename, tail_cons); 71 GCPRO4 (dirname, dirfilename, tail_cons, errstring);
71 72
72 /* If the file name has special constructs in it, 73 /* If the file name has special constructs in it,
73 call the corresponding file handler. */ 74 call the corresponding file handler. */
74 handler = Ffind_file_name_handler (dirname, Qdirectory_files); 75 handler = Ffind_file_name_handler (dirname, Qdirectory_files);
75 if (!NILP (handler)) 76 if (!NILP (handler))
90 91
91 { 92 {
92 /* XEmacs: this should come before the opendir() because it might error. */ 93 /* XEmacs: this should come before the opendir() because it might error. */
93 Lisp_Object name_as_dir = Ffile_name_as_directory (dirname); 94 Lisp_Object name_as_dir = Ffile_name_as_directory (dirname);
94 CHECK_STRING (name_as_dir); 95 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 }
95 memcpy (statbuf, ((char *) XSTRING_DATA (name_as_dir)), 100 memcpy (statbuf, ((char *) XSTRING_DATA (name_as_dir)),
96 XSTRING_LENGTH (name_as_dir)); 101 XSTRING_LENGTH (name_as_dir));
97 statbuf_tail = statbuf + XSTRING_LENGTH (name_as_dir); 102 statbuf_tail = statbuf + XSTRING_LENGTH (name_as_dir);
98 } 103 }
99 104
134 dirname_length = XSTRING_LENGTH (dirname); 139 dirname_length = XSTRING_LENGTH (dirname);
135 #ifndef VMS 140 #ifndef VMS
136 if (dirname_length == 0 141 if (dirname_length == 0
137 || !IS_ANY_SEP (XSTRING_BYTE (dirname, dirname_length - 1))) 142 || !IS_ANY_SEP (XSTRING_BYTE (dirname, dirname_length - 1)))
138 { 143 {
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 }
139 *filename++ = DIRECTORY_SEP; 150 *filename++ = DIRECTORY_SEP;
140 dirname_length++; 151 dirname_length++;
141 } 152 }
142 #endif /* VMS */ 153 #endif /* VMS */
143 154
151 len = NAMLEN (dp); 162 len = NAMLEN (dp);
152 if (DIRENTRY_NONEMPTY (dp)) 163 if (DIRENTRY_NONEMPTY (dp))
153 { 164 {
154 int result; 165 int result;
155 Lisp_Object oinhibit_quit = Vinhibit_quit; 166 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 }
156 strncpy (filename, dp->d_name, len); 174 strncpy (filename, dp->d_name, len);
157 filename[len] = 0; 175 filename[len] = 0;
158 /* re_search can now QUIT, so prevent it to avoid 176 /* re_search can now QUIT, so prevent it to avoid
159 filedesc lossage */ 177 filedesc lossage */
160 Vinhibit_quit = Qt; 178 Vinhibit_quit = Qt;
166 if (!NILP (files_only)) 184 if (!NILP (files_only))
167 { 185 {
168 int dir_p; 186 int dir_p;
169 struct stat st; 187 struct stat st;
170 188
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 }
171 memcpy (statbuf_tail, filename, len); 197 memcpy (statbuf_tail, filename, len);
172 statbuf_tail [len] = 0; 198 statbuf_tail [len] = 0;
173 199
174 if (stat (statbuf, &st) < 0) 200 if (stat (statbuf, &st) < 0)
175 dir_p = 0; 201 dir_p = 0;