comparison src/fileio.c @ 363:972bbb6d6ca2 r21-1-11

Import from CVS: tag r21-1-11
author cvs
date Mon, 13 Aug 2007 10:59:28 +0200
parents 7347b34c275b
children a4f53d9b3154
comparison
equal deleted inserted replaced
362:1e474c183006 363:972bbb6d6ca2
770 An initial `~USER/' expands to USER's home directory. 770 An initial `~USER/' expands to USER's home directory.
771 See also the function `substitute-in-file-name'. 771 See also the function `substitute-in-file-name'.
772 */ 772 */
773 (name, default_directory)) 773 (name, default_directory))
774 { 774 {
775 /* This function can GC */ 775 /* This function can GC. GC-checked 7-11-00 ben */
776 Bufbyte *nm; 776 Bufbyte *nm;
777 777
778 Bufbyte *newdir, *p, *o; 778 Bufbyte *newdir, *p, *o;
779 int tlen; 779 int tlen;
780 Bufbyte *target; 780 Bufbyte *target;
787 int length; 787 int length;
788 Lisp_Object handler; 788 Lisp_Object handler;
789 #ifdef __CYGWIN32__ 789 #ifdef __CYGWIN32__
790 char *user; 790 char *user;
791 #endif 791 #endif
792 struct gcpro gcpro1, gcpro2;
793
794 /* both of these get set below */
795 GCPRO2 (name, default_directory);
792 796
793 CHECK_STRING (name); 797 CHECK_STRING (name);
794 798
795 /* If the file name has special constructs in it, 799 /* If the file name has special constructs in it,
796 call the corresponding file handler. */ 800 call the corresponding file handler. */
797 handler = Ffind_file_name_handler (name, Qexpand_file_name); 801 handler = Ffind_file_name_handler (name, Qexpand_file_name);
798 if (!NILP (handler)) 802 if (!NILP (handler))
799 return call3_check_string (handler, Qexpand_file_name, name, 803 {
800 default_directory); 804 UNGCPRO;
805 return call3_check_string (handler, Qexpand_file_name, name,
806 default_directory);
807 }
801 808
802 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */ 809 /* Use the buffer's default-directory if DEFAULT_DIRECTORY is omitted. */
803 if (NILP (default_directory)) 810 if (NILP (default_directory))
804 default_directory = current_buffer->directory; 811 default_directory = current_buffer->directory;
805 if (! STRINGP (default_directory)) 812 if (! STRINGP (default_directory))
807 814
808 if (!NILP (default_directory)) 815 if (!NILP (default_directory))
809 { 816 {
810 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name); 817 handler = Ffind_file_name_handler (default_directory, Qexpand_file_name);
811 if (!NILP (handler)) 818 if (!NILP (handler))
812 return call3 (handler, Qexpand_file_name, name, default_directory); 819 {
820 UNGCPRO;
821 return call3 (handler, Qexpand_file_name, name, default_directory);
822 }
813 } 823 }
814 824
815 o = XSTRING_DATA (default_directory); 825 o = XSTRING_DATA (default_directory);
816 826
817 /* Make sure DEFAULT_DIRECTORY is properly expanded. 827 /* Make sure DEFAULT_DIRECTORY is properly expanded.
839 /* Detect Unix absolute file names (/... alone is not absolute on 849 /* Detect Unix absolute file names (/... alone is not absolute on
840 DOS or Windows). */ 850 DOS or Windows). */
841 && ! (IS_DIRECTORY_SEP (o[0])) 851 && ! (IS_DIRECTORY_SEP (o[0]))
842 #endif /* not WINDOWSNT */ 852 #endif /* not WINDOWSNT */
843 ) 853 )
844 { 854
845 struct gcpro gcpro1; 855 default_directory = Fexpand_file_name (default_directory, Qnil);
846
847 GCPRO1 (name);
848 default_directory = Fexpand_file_name (default_directory, Qnil);
849 UNGCPRO;
850 }
851 856
852 #ifdef FILE_SYSTEM_CASE 857 #ifdef FILE_SYSTEM_CASE
853 name = FILE_SYSTEM_CASE (name); 858 name = FILE_SYSTEM_CASE (name);
854 #endif 859 #endif
855 860
948 { 953 {
949 name = make_string (nm - 2, p - nm + 2); 954 name = make_string (nm - 2, p - nm + 2);
950 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive); 955 XSTRING_DATA (name)[0] = DRIVE_LETTER (drive);
951 XSTRING_DATA (name)[1] = ':'; 956 XSTRING_DATA (name)[1] = ':';
952 } 957 }
953 return name; 958 RETURN_UNGCPRO (name);
954 #else /* not WINDOWSNT */ 959 #else /* not WINDOWSNT */
955 if (nm == XSTRING_DATA (name)) 960 if (nm == XSTRING_DATA (name))
956 return name; 961 RETURN_UNGCPRO (name);
957 return build_string ((char *) nm); 962 RETURN_UNGCPRO (build_string ((char *) nm));
958 #endif /* not WINDOWSNT */ 963 #endif /* not WINDOWSNT */
959 } 964 }
960 } 965 }
961 966
962 /* At this point, nm might or might not be an absolute file name. We 967 /* At this point, nm might or might not be an absolute file name. We
1259 abort (); 1264 abort ();
1260 } 1265 }
1261 CORRECT_DIR_SEPS (target); 1266 CORRECT_DIR_SEPS (target);
1262 #endif /* WINDOWSNT */ 1267 #endif /* WINDOWSNT */
1263 1268
1264 return make_string (target, o - target); 1269 RETURN_UNGCPRO (make_string (target, o - target));
1265 } 1270 }
1266 1271
1267 #if 0 /* FSFmacs */ 1272 #if 0 /* FSFmacs */
1268 /* another older version of expand-file-name; */ 1273 /* another older version of expand-file-name; */
1269 #endif 1274 #endif
2218 Return t if file FILENAME exists. (This does not mean you can read it.) 2223 Return t if file FILENAME exists. (This does not mean you can read it.)
2219 See also `file-readable-p' and `file-attributes'. 2224 See also `file-readable-p' and `file-attributes'.
2220 */ 2225 */
2221 (filename)) 2226 (filename))
2222 { 2227 {
2223 /* This function can call lisp */ 2228 /* This function can call lisp; GC checked 7-11-00 ben */
2224 Lisp_Object abspath; 2229 Lisp_Object abspath;
2225 Lisp_Object handler; 2230 Lisp_Object handler;
2226 struct stat statbuf; 2231 struct stat statbuf;
2227 struct gcpro gcpro1; 2232 struct gcpro gcpro1;
2228 2233
2245 For a directory, this means you can access files in that directory. 2250 For a directory, this means you can access files in that directory.
2246 */ 2251 */
2247 (filename)) 2252 (filename))
2248 2253
2249 { 2254 {
2250 /* This function can GC. GC checked 1997.04.10. */ 2255 /* This function can GC. GC checked 07-11-2000 ben. */
2251 Lisp_Object abspath; 2256 Lisp_Object abspath;
2252 Lisp_Object handler; 2257 Lisp_Object handler;
2253 struct gcpro gcpro1; 2258 struct gcpro gcpro1;
2254 2259
2255 CHECK_STRING (filename); 2260 CHECK_STRING (filename);
3143 /* This function can call lisp */ 3148 /* This function can call lisp */
3144 int desc; 3149 int desc;
3145 int failure; 3150 int failure;
3146 int save_errno = 0; 3151 int save_errno = 0;
3147 struct stat st; 3152 struct stat st;
3148 Lisp_Object fn; 3153 Lisp_Object fn = Qnil;
3149 int speccount = specpdl_depth (); 3154 int speccount = specpdl_depth ();
3150 int visiting_other = STRINGP (visit); 3155 int visiting_other = STRINGP (visit);
3151 int visiting = (EQ (visit, Qt) || visiting_other); 3156 int visiting = (EQ (visit, Qt) || visiting_other);
3152 int quietly = (!visiting && !NILP (visit)); 3157 int quietly = (!visiting && !NILP (visit));
3153 Lisp_Object visit_file = Qnil; 3158 Lisp_Object visit_file = Qnil;
3154 Lisp_Object annotations = Qnil; 3159 Lisp_Object annotations = Qnil;
3155 struct buffer *given_buffer; 3160 struct buffer *given_buffer;
3156 Bufpos start1, end1; 3161 Bufpos start1, end1;
3157 3162 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3158 /* #### dmoore - if Fexpand_file_name or handlers kill the buffer, 3163 struct gcpro ngcpro1, ngcpro2;
3164 Lisp_Object curbuf;
3165
3166 XSETBUFFER (curbuf, current_buffer);
3167
3168 /* start, end, visit, and append are never modified in this fun
3169 so we don't protect them. */
3170 GCPRO5 (visit_file, filename, codesys, lockname, annotations);
3171 NGCPRO2 (curbuf, fn);
3172
3173 /* [[ dmoore - if Fexpand_file_name or handlers kill the buffer,
3159 we should signal an error rather than blissfully continuing 3174 we should signal an error rather than blissfully continuing
3160 along. ARGH, this function is going to lose lose lose. We need 3175 along. ARGH, this function is going to lose lose lose. We need
3161 to protect the current_buffer from being destroyed, but the 3176 to protect the current_buffer from being destroyed, but the
3162 multiple return points make this a pain in the butt. */ 3177 multiple return points make this a pain in the butt. ]] we do
3178 protect curbuf now. --ben */
3163 3179
3164 #ifdef FILE_CODING 3180 #ifdef FILE_CODING
3165 codesys = Fget_coding_system (codesys); 3181 codesys = Fget_coding_system (codesys);
3166 #endif /* FILE_CODING */ 3182 #endif /* FILE_CODING */
3167 3183
3171 if (!NILP (start) && !STRINGP (start)) 3187 if (!NILP (start) && !STRINGP (start))
3172 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0); 3188 get_buffer_range_char (current_buffer, start, end, &start1, &end1, 0);
3173 3189
3174 { 3190 {
3175 Lisp_Object handler; 3191 Lisp_Object handler;
3176 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3177
3178 GCPRO5 (start, filename, visit, visit_file, lockname);
3179 3192
3180 if (visiting_other) 3193 if (visiting_other)
3181 visit_file = Fexpand_file_name (visit, Qnil); 3194 visit_file = Fexpand_file_name (visit, Qnil);
3182 else 3195 else
3183 visit_file = filename; 3196 visit_file = filename;
3184 filename = Fexpand_file_name (filename, Qnil); 3197 filename = Fexpand_file_name (filename, Qnil);
3185 3198
3186 UNGCPRO;
3187
3188 if (NILP (lockname)) 3199 if (NILP (lockname))
3189 lockname = visit_file; 3200 lockname = visit_file;
3190 3201
3202 /* We used to UNGCPRO here. BAD! visit_file is used below after
3203 more Lisp calling. */
3191 /* If the file name has special constructs in it, 3204 /* If the file name has special constructs in it,
3192 call the corresponding file handler. */ 3205 call the corresponding file handler. */
3193 handler = Ffind_file_name_handler (filename, Qwrite_region); 3206 handler = Ffind_file_name_handler (filename, Qwrite_region);
3194 /* If FILENAME has no handler, see if VISIT has one. */ 3207 /* If FILENAME has no handler, see if VISIT has one. */
3195 if (NILP (handler) && STRINGP (visit)) 3208 if (NILP (handler) && STRINGP (visit))
3204 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer); 3217 BUF_SAVE_MODIFF (current_buffer) = BUF_MODIFF (current_buffer);
3205 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer)); 3218 current_buffer->saved_size = make_int (BUF_SIZE (current_buffer));
3206 current_buffer->filename = visit_file; 3219 current_buffer->filename = visit_file;
3207 MARK_MODELINE_CHANGED; 3220 MARK_MODELINE_CHANGED;
3208 } 3221 }
3222 NUNGCPRO;
3223 UNGCPRO;
3209 return val; 3224 return val;
3210 } 3225 }
3211 } 3226 }
3212 3227
3213 #ifdef CLASH_DETECTION 3228 #ifdef CLASH_DETECTION
3214 if (!auto_saving) 3229 if (!auto_saving)
3215 { 3230 lock_file (lockname);
3216 Lisp_Object curbuf;
3217 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
3218
3219 XSETBUFFER (curbuf, current_buffer);
3220 GCPRO5 (start, filename, visit_file, lockname, curbuf);
3221 lock_file (lockname);
3222 UNGCPRO;
3223 }
3224 #endif /* CLASH_DETECTION */ 3231 #endif /* CLASH_DETECTION */
3225 3232
3226 /* Special kludge to simplify auto-saving. */ 3233 /* Special kludge to simplify auto-saving. */
3227 if (NILP (start)) 3234 if (NILP (start))
3228 { 3235 {
3264 } 3271 }
3265 3272
3266 { 3273 {
3267 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil); 3274 Lisp_Object desc_locative = Fcons (make_int (desc), Qnil);
3268 Lisp_Object instream = Qnil, outstream = Qnil; 3275 Lisp_Object instream = Qnil, outstream = Qnil;
3269 struct gcpro gcpro1, gcpro2; 3276 struct gcpro nngcpro1, nngcpro2;
3270 /* need to gcpro; QUIT could happen out of call to write() */ 3277 /* need to gcpro; QUIT could happen out of call to write() */
3271 GCPRO2 (instream, outstream); 3278 NNGCPRO2 (instream, outstream);
3272 3279
3273 record_unwind_protect (close_file_unwind, desc_locative); 3280 record_unwind_protect (close_file_unwind, desc_locative);
3274 3281
3275 if (!NILP (append)) 3282 if (!NILP (append))
3276 { 3283 {
3324 { 3331 {
3325 failure = 1; 3332 failure = 1;
3326 save_errno = errno; 3333 save_errno = errno;
3327 } 3334 }
3328 Lstream_close (XLSTREAM (instream)); 3335 Lstream_close (XLSTREAM (instream));
3329 UNGCPRO;
3330 3336
3331 #ifdef HAVE_FSYNC 3337 #ifdef HAVE_FSYNC
3332 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun). 3338 /* Note fsync appears to change the modtime on BSD4.2 (both vax and sun).
3333 Disk full in NFS may be reported here. */ 3339 Disk full in NFS may be reported here. */
3334 /* mib says that closing the file will try to write as fast as NFS can do 3340 /* mib says that closing the file will try to write as fast as NFS can do
3368 /* Discard the close unwind-protect. Execute the one for 3374 /* Discard the close unwind-protect. Execute the one for
3369 build_annotations (switches back to the original current buffer 3375 build_annotations (switches back to the original current buffer
3370 as necessary). */ 3376 as necessary). */
3371 XCAR (desc_locative) = Qnil; 3377 XCAR (desc_locative) = Qnil;
3372 unbind_to (speccount, Qnil); 3378 unbind_to (speccount, Qnil);
3379
3380 NNUNGCPRO;
3373 } 3381 }
3374 3382
3375 /* 3383 /*
3376 * stat the file after the file is closed to avoid having the 3384 * stat the file after the file is closed to avoid having the
3377 * modtime change on us when the file is closed. 3385 * modtime change on us when the file is closed.
3401 current_buffer->filename = visit_file; 3409 current_buffer->filename = visit_file;
3402 MARK_MODELINE_CHANGED; 3410 MARK_MODELINE_CHANGED;
3403 } 3411 }
3404 else if (quietly) 3412 else if (quietly)
3405 { 3413 {
3414 NUNGCPRO;
3415 UNGCPRO;
3406 return Qnil; 3416 return Qnil;
3407 } 3417 }
3408 3418
3409 if (!auto_saving) 3419 if (!auto_saving)
3410 { 3420 {
3411 if (visiting_other) 3421 if (visiting_other)
3412 message ("Wrote %s", XSTRING_DATA (visit_file)); 3422 message ("Wrote %s", XSTRING_DATA (visit_file));
3413 else 3423 else
3414 { 3424 {
3415 struct gcpro gcpro1;
3416 Lisp_Object fsp; 3425 Lisp_Object fsp;
3417 GCPRO1 (fn); 3426 struct gcpro nngcpro1;
3418 3427
3428 NNGCPRO1 (fsp);
3419 fsp = Ffile_symlink_p (fn); 3429 fsp = Ffile_symlink_p (fn);
3420 if (NILP (fsp)) 3430 if (NILP (fsp))
3421 message ("Wrote %s", XSTRING_DATA (fn)); 3431 message ("Wrote %s", XSTRING_DATA (fn));
3422 else 3432 else
3423 message ("Wrote %s (symlink to %s)", 3433 message ("Wrote %s (symlink to %s)",
3424 XSTRING_DATA (fn), XSTRING_DATA (fsp)); 3434 XSTRING_DATA (fn), XSTRING_DATA (fsp));
3425 UNGCPRO; 3435 NNUNGCPRO;
3426 } 3436 }
3427 } 3437 }
3438 NUNGCPRO;
3439 UNGCPRO;
3428 return Qnil; 3440 return Qnil;
3429 } 3441 }
3430 3442
3431 /* #### This is such a load of shit!!!! There is no way we should define 3443 /* #### This is such a load of shit!!!! There is no way we should define
3432 something so stupid as a subr, just sort the fucking list more 3444 something so stupid as a subr, just sort the fucking list more
3668 Return t if last mod time of BUF's visited file matches what BUF records. 3680 Return t if last mod time of BUF's visited file matches what BUF records.
3669 This means that the file has not been changed since it was visited or saved. 3681 This means that the file has not been changed since it was visited or saved.
3670 */ 3682 */
3671 (buf)) 3683 (buf))
3672 { 3684 {
3673 /* This function can call lisp */ 3685 /* This function can call lisp; GC checked 7-11-00 ben */
3674 struct buffer *b; 3686 struct buffer *b;
3675 struct stat st; 3687 struct stat st;
3676 Lisp_Object handler; 3688 Lisp_Object handler;
3677 3689
3678 CHECK_BUFFER (buf); 3690 CHECK_BUFFER (buf);