comparison src/fileio.c @ 173:8eaf7971accc r20-3b13

Import from CVS: tag r20-3b13
author cvs
date Mon, 13 Aug 2007 09:49:09 +0200
parents 15872534500d
children e121b013d1f0
comparison
equal deleted inserted replaced
172:a38aed19690b 173:8eaf7971accc
247 247
248 static Lisp_Object 248 static Lisp_Object
249 restore_point_unwind (Lisp_Object point_marker) 249 restore_point_unwind (Lisp_Object point_marker)
250 { 250 {
251 BUF_SET_PT (current_buffer, marker_position (point_marker)); 251 BUF_SET_PT (current_buffer, marker_position (point_marker));
252 return (Fset_marker (point_marker, Qnil, Qnil)); 252 return Fset_marker (point_marker, Qnil, Qnil);
253 } 253 }
254 254
255 /* Versions of read() and write() that allow quitting out of the actual 255 /* Versions of read() and write() that allow quitting out of the actual
256 I/O. We don't use immediate_quit (i.e. direct longjmp() out of the 256 I/O. We don't use immediate_quit (i.e. direct longjmp() out of the
257 signal handler) because that's way too losing. 257 signal handler) because that's way too losing.
352 if (STRINGP (string) 352 if (STRINGP (string)
353 && (fast_lisp_string_match (string, filename) >= 0)) 353 && (fast_lisp_string_match (string, filename) >= 0))
354 { 354 {
355 Lisp_Object handler = XCDR (elt); 355 Lisp_Object handler = XCDR (elt);
356 if (NILP (Fmemq (handler, inhibited_handlers))) 356 if (NILP (Fmemq (handler, inhibited_handlers)))
357 return (handler); 357 return handler;
358 } 358 }
359 } 359 }
360 QUIT; 360 QUIT;
361 } 361 }
362 return Qnil; 362 return Qnil;
366 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) 366 call2_check_string (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
367 { 367 {
368 /* This function can call lisp */ 368 /* This function can call lisp */
369 Lisp_Object result = call2 (fn, arg0, arg1); 369 Lisp_Object result = call2 (fn, arg0, arg1);
370 CHECK_STRING (result); 370 CHECK_STRING (result);
371 return (result); 371 return result;
372 } 372 }
373 373
374 static Lisp_Object 374 static Lisp_Object
375 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1) 375 call2_check_string_or_nil (Lisp_Object fn, Lisp_Object arg0, Lisp_Object arg1)
376 { 376 {
377 /* This function can call lisp */ 377 /* This function can call lisp */
378 Lisp_Object result = call2 (fn, arg0, arg1); 378 Lisp_Object result = call2 (fn, arg0, arg1);
379 if (!NILP (result)) 379 if (!NILP (result))
380 CHECK_STRING (result); 380 CHECK_STRING (result);
381 return (result); 381 return result;
382 } 382 }
383 383
384 static Lisp_Object 384 static Lisp_Object
385 call3_check_string (Lisp_Object fn, Lisp_Object arg0, 385 call3_check_string (Lisp_Object fn, Lisp_Object arg0,
386 Lisp_Object arg1, Lisp_Object arg2) 386 Lisp_Object arg1, Lisp_Object arg2)
387 { 387 {
388 /* This function can call lisp */ 388 /* This function can call lisp */
389 Lisp_Object result = call3 (fn, arg0, arg1, arg2); 389 Lisp_Object result = call3 (fn, arg0, arg1, arg2);
390 CHECK_STRING (result); 390 CHECK_STRING (result);
391 return (result); 391 return result;
392 } 392 }
393 393
394 394
395 DEFUN ("file-name-directory", Ffile_name_directory, 1, 1, 0, /* 395 DEFUN ("file-name-directory", Ffile_name_directory, 1, 1, 0, /*
396 Return the directory component in file name NAME. 396 Return the directory component in file name NAME.
410 410
411 /* If the file name has special constructs in it, 411 /* If the file name has special constructs in it,
412 call the corresponding file handler. */ 412 call the corresponding file handler. */
413 handler = Ffind_file_name_handler (file, Qfile_name_directory); 413 handler = Ffind_file_name_handler (file, Qfile_name_directory);
414 if (!NILP (handler)) 414 if (!NILP (handler))
415 return (call2_check_string_or_nil (handler, Qfile_name_directory, 415 return call2_check_string_or_nil (handler, Qfile_name_directory, file);
416 file));
417 416
418 #ifdef FILE_SYSTEM_CASE 417 #ifdef FILE_SYSTEM_CASE
419 file = FILE_SYSTEM_CASE (file); 418 file = FILE_SYSTEM_CASE (file);
420 #endif 419 #endif
421 beg = XSTRING_DATA (file); 420 beg = XSTRING_DATA (file);
477 476
478 /* If the file name has special constructs in it, 477 /* If the file name has special constructs in it,
479 call the corresponding file handler. */ 478 call the corresponding file handler. */
480 handler = Ffind_file_name_handler (file, Qfile_name_nondirectory); 479 handler = Ffind_file_name_handler (file, Qfile_name_nondirectory);
481 if (!NILP (handler)) 480 if (!NILP (handler))
482 return (call2_check_string (handler, Qfile_name_nondirectory, 481 return call2_check_string (handler, Qfile_name_nondirectory, file);
483 file));
484 482
485 beg = XSTRING_DATA (file); 483 beg = XSTRING_DATA (file);
486 end = p = beg + XSTRING_LENGTH (file); 484 end = p = beg + XSTRING_LENGTH (file);
487 485
488 while (p != beg && !IS_ANY_SEP (p[-1]) 486 while (p != beg && !IS_ANY_SEP (p[-1])
613 611
614 /* If the file name has special constructs in it, 612 /* If the file name has special constructs in it,
615 call the corresponding file handler. */ 613 call the corresponding file handler. */
616 handler = Ffind_file_name_handler (file, Qfile_name_as_directory); 614 handler = Ffind_file_name_handler (file, Qfile_name_as_directory);
617 if (!NILP (handler)) 615 if (!NILP (handler))
618 return (call2_check_string (handler, Qfile_name_as_directory, 616 return call2_check_string (handler, Qfile_name_as_directory, file);
619 file));
620 617
621 buf = (char *) alloca (XSTRING_LENGTH (file) + 10); 618 buf = (char *) alloca (XSTRING_LENGTH (file) + 10);
622 return build_string (file_name_as_directory 619 return build_string (file_name_as_directory
623 (buf, (char *) XSTRING_DATA (file))); 620 (buf, (char *) XSTRING_DATA (file)));
624 } 621 }
804 801
805 /* If the file name has special constructs in it, 802 /* If the file name has special constructs in it,
806 call the corresponding file handler. */ 803 call the corresponding file handler. */
807 handler = Ffind_file_name_handler (directory, Qdirectory_file_name); 804 handler = Ffind_file_name_handler (directory, Qdirectory_file_name);
808 if (!NILP (handler)) 805 if (!NILP (handler))
809 return (call2_check_string (handler, Qdirectory_file_name, 806 return call2_check_string (handler, Qdirectory_file_name, directory);
810 directory));
811 #ifdef VMS 807 #ifdef VMS
812 /* 20 extra chars is insufficient for VMS, since we might perform a 808 /* 20 extra chars is insufficient for VMS, since we might perform a
813 logical name translation. an equivalence string can be up to 255 809 logical name translation. an equivalence string can be up to 255
814 chars long, so grab that much extra space... - sss */ 810 chars long, so grab that much extra space... - sss */
815 buf = (char *) alloca (XSTRING_LENGTH (directory) + 20 + 255); 811 buf = (char *) alloca (XSTRING_LENGTH (directory) + 20 + 255);
855 paths in the file system. 851 paths in the file system.
856 An initial `~/' expands to your home directory. 852 An initial `~/' expands to your home directory.
857 An initial `~USER/' expands to USER's home directory. 853 An initial `~USER/' expands to USER's home directory.
858 See also the function `substitute-in-file-name'. 854 See also the function `substitute-in-file-name'.
859 */ 855 */
860 (name, defalt)) 856 (name, default_))
861 { 857 {
862 /* This function can GC. GC checked 1997.04.06. */ 858 /* This function can GC. GC checked 1997.04.06. */
863 Bufbyte *nm; 859 Bufbyte *nm;
864 860
865 Bufbyte *newdir, *p, *o; 861 Bufbyte *newdir, *p, *o;
886 882
887 /* If the file name has special constructs in it, 883 /* If the file name has special constructs in it,
888 call the corresponding file handler. */ 884 call the corresponding file handler. */
889 handler = Ffind_file_name_handler (name, Qexpand_file_name); 885 handler = Ffind_file_name_handler (name, Qexpand_file_name);
890 if (!NILP (handler)) 886 if (!NILP (handler))
891 return (call3_check_string (handler, Qexpand_file_name, name, 887 return call3_check_string (handler, Qexpand_file_name, name, default_);
892 defalt)); 888
893 889 /* Use the buffer's default-directory if DEFAULT_ is omitted. */
894 /* Use the buffer's default-directory if DEFALT is omitted. */ 890 if (NILP (default_))
895 if (NILP (defalt)) 891 default_ = current_buffer->directory;
896 defalt = current_buffer->directory; 892 if (NILP (default_)) /* this should be a meaningful error */
897 if (NILP (defalt)) /* this should be a meaningful error */
898 { 893 {
899 /* #### If we had a minibuffer-only frame up then current_buffer 894 /* #### If we had a minibuffer-only frame up then current_buffer
900 is likely to not have a directory setting. We should 895 is likely to not have a directory setting. We should
901 probably redo things to make sure that current_buffer stays 896 probably redo things to make sure that current_buffer stays
902 set to something sensible. */ 897 set to something sensible. */
903 if (!preparing_for_armageddon) 898 if (!preparing_for_armageddon)
904 signal_simple_error ("default-directory is not set", 899 signal_simple_error ("default-directory is not set",
905 make_buffer (current_buffer)); 900 make_buffer (current_buffer));
906 } 901 }
907 else 902 else
908 CHECK_STRING (defalt); 903 CHECK_STRING (default_);
909 904
910 if (!NILP (defalt)) 905 if (!NILP (default_))
911 { 906 {
912 struct gcpro gcpro1; 907 struct gcpro gcpro1;
913 908
914 GCPRO1 (defalt); /* might be current_buffer->directory */ 909 GCPRO1 (default_); /* might be current_buffer->directory */
915 handler = Ffind_file_name_handler (defalt, Qexpand_file_name); 910 handler = Ffind_file_name_handler (default_, Qexpand_file_name);
916 UNGCPRO; 911 UNGCPRO;
917 if (!NILP (handler)) 912 if (!NILP (handler))
918 return call3 (handler, Qexpand_file_name, name, defalt); 913 return call3 (handler, Qexpand_file_name, name, default_);
919 } 914 }
920 915
921 /* Make sure DEFALT is properly expanded. 916 /* Make sure DEFAULT_ is properly expanded.
922 It would be better to do this down below where we actually use 917 It would be better to do this down below where we actually use
923 defalt. Unfortunately, calling Fexpand_file_name recursively 918 default_. Unfortunately, calling Fexpand_file_name recursively
924 could invoke GC, and the strings might be relocated. This would 919 could invoke GC, and the strings might be relocated. This would
925 be annoying because we have pointers into strings lying around 920 be annoying because we have pointers into strings lying around
926 that would need adjusting, and people would add new pointers to 921 that would need adjusting, and people would add new pointers to
927 the code and forget to adjust them, resulting in intermittent bugs. 922 the code and forget to adjust them, resulting in intermittent bugs.
928 Putting this call here avoids all that crud. 923 Putting this call here avoids all that crud.
929 924
930 The EQ test avoids infinite recursion. */ 925 The EQ test avoids infinite recursion. */
931 if (! NILP(defalt) && !EQ (defalt, name) 926 if (! NILP(default_) && !EQ (default_, name)
932 /* This saves time in a common case. */ 927 /* This saves time in a common case. */
933 && ! (XSTRING_LENGTH (defalt) >= 3 928 && ! (XSTRING_LENGTH (default_) >= 3
934 && (IS_DIRECTORY_SEP (XSTRING_BYTE (defalt, 0)) 929 && (IS_DIRECTORY_SEP (XSTRING_BYTE (default_, 0))
935 || IS_DEVICE_SEP (XSTRING_BYTE (defalt, 1))))) 930 || IS_DEVICE_SEP (XSTRING_BYTE (default_, 1)))))
936 { 931 {
937 struct gcpro gcpro1; 932 struct gcpro gcpro1;
938 933
939 GCPRO1 (defalt); /* may be current_buffer->directory */ 934 GCPRO1 (default_); /* may be current_buffer->directory */
940 defalt = Fexpand_file_name (defalt, Qnil); 935 default_ = Fexpand_file_name (default_, Qnil);
941 UNGCPRO; 936 UNGCPRO;
942 } 937 }
943 938
944 #ifdef VMS 939 #ifdef VMS
945 /* Filenames on VMS are always upper case. */ 940 /* Filenames on VMS are always upper case. */
1192 #endif /* not VMS */ 1187 #endif /* not VMS */
1193 #ifdef DOS_NT 1188 #ifdef DOS_NT
1194 && drive == -1 1189 && drive == -1
1195 #endif /* DOS_NT */ 1190 #endif /* DOS_NT */
1196 && !newdir 1191 && !newdir
1197 && STRINGP (defalt)) 1192 && STRINGP (default_))
1198 { 1193 {
1199 newdir = XSTRING_DATA (defalt); 1194 newdir = XSTRING_DATA (default_);
1200 } 1195 }
1201 1196
1202 #ifdef DOS_NT 1197 #ifdef DOS_NT
1203 if (newdir == 0 && relpath) 1198 if (newdir == 0 && relpath)
1204 newdir = defdir; 1199 newdir = defdir;
1380 (does not start with slash); if DEFAULT is nil or missing, 1375 (does not start with slash); if DEFAULT is nil or missing,
1381 the current buffer's value of default-directory is used. 1376 the current buffer's value of default-directory is used.
1382 No component of the resulting pathname will be a symbolic link, as 1377 No component of the resulting pathname will be a symbolic link, as
1383 in the realpath() function. 1378 in the realpath() function.
1384 */ 1379 */
1385 (filename, defalt)) 1380 (filename, default_))
1386 { 1381 {
1387 /* This function can GC. GC checked 1997.04.06. */ 1382 /* This function can GC. GC checked 1997.04.06. */
1388 Lisp_Object expanded_name; 1383 Lisp_Object expanded_name;
1389 Lisp_Object handler; 1384 Lisp_Object handler;
1390 struct gcpro gcpro1; 1385 struct gcpro gcpro1;
1391 1386
1392 CHECK_STRING (filename); 1387 CHECK_STRING (filename);
1393 1388
1394 expanded_name = Fexpand_file_name (filename, defalt); 1389 expanded_name = Fexpand_file_name (filename, default_);
1395 1390
1396 if (!STRINGP (expanded_name)) 1391 if (!STRINGP (expanded_name))
1397 return Qnil; 1392 return Qnil;
1398 1393
1399 GCPRO1 (expanded_name); 1394 GCPRO1 (expanded_name);
1400 handler = Ffind_file_name_handler (expanded_name, Qfile_truename); 1395 handler = Ffind_file_name_handler (expanded_name, Qfile_truename);
1401 UNGCPRO; 1396 UNGCPRO;
1402 1397
1403 if (!NILP (handler)) 1398 if (!NILP (handler))
1404 return (call2_check_string (handler, Qfile_truename, 1399 return call2_check_string (handler, Qfile_truename, expanded_name);
1405 expanded_name));
1406 1400
1407 #ifdef VMS 1401 #ifdef VMS
1408 return (expanded_name); 1402 return expanded_name;
1409 #else 1403 #else
1410 { 1404 {
1411 char resolved_path[MAXPATHLEN]; 1405 char resolved_path[MAXPATHLEN];
1412 char path[MAXPATHLEN]; 1406 char path[MAXPATHLEN];
1413 char *p = path; 1407 char *p = path;
1525 1519
1526 /* If the file name has special constructs in it, 1520 /* If the file name has special constructs in it,
1527 call the corresponding file handler. */ 1521 call the corresponding file handler. */
1528 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name); 1522 handler = Ffind_file_name_handler (string, Qsubstitute_in_file_name);
1529 if (!NILP (handler)) 1523 if (!NILP (handler))
1530 return (call2_check_string_or_nil (handler, Qsubstitute_in_file_name, 1524 return call2_check_string_or_nil (handler, Qsubstitute_in_file_name,
1531 string)); 1525 string);
1532 1526
1533 nm = XSTRING_DATA (string); 1527 nm = XSTRING_DATA (string);
1534 #ifdef MSDOS 1528 #ifdef MSDOS
1535 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm)); 1529 dostounix_filename (nm = strcpy (alloca (strlen (nm) + 1), nm));
1536 substituted = !strcmp (nm, XSTRING_DATA (string)); 1530 substituted = !strcmp (nm, XSTRING_DATA (string));
1976 } 1970 }
1977 1971
1978 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /* 1972 DEFUN ("make-directory-internal", Fmake_directory_internal, 1, 1, 0, /*
1979 Create a directory. One argument, a file name string. 1973 Create a directory. One argument, a file name string.
1980 */ 1974 */
1981 (dirname)) 1975 (dirname_))
1982 { 1976 {
1983 /* This function can GC. GC checked 1997.04.06. */ 1977 /* This function can GC. GC checked 1997.04.06. */
1984 char dir [MAXPATHLEN]; 1978 char dir [MAXPATHLEN];
1985 Lisp_Object handler; 1979 Lisp_Object handler;
1986 struct gcpro gcpro1; 1980 struct gcpro gcpro1;
1987 1981
1988 CHECK_STRING (dirname); 1982 CHECK_STRING (dirname_);
1989 dirname = Fexpand_file_name (dirname, Qnil); 1983 dirname_ = Fexpand_file_name (dirname_, Qnil);
1990 1984
1991 GCPRO1 (dirname); 1985 GCPRO1 (dirname_);
1992 handler = Ffind_file_name_handler (dirname, Qmake_directory_internal); 1986 handler = Ffind_file_name_handler (dirname_, Qmake_directory_internal);
1993 UNGCPRO; 1987 UNGCPRO;
1994 if (!NILP (handler)) 1988 if (!NILP (handler))
1995 return (call2 (handler, Qmake_directory_internal, dirname)); 1989 return (call2 (handler, Qmake_directory_internal, dirname_));
1996 1990
1997 if (XSTRING_LENGTH (dirname) > (sizeof (dir) - 1)) 1991 if (XSTRING_LENGTH (dirname_) > (sizeof (dir) - 1))
1998 { 1992 {
1999 return Fsignal (Qfile_error, 1993 return Fsignal (Qfile_error,
2000 list3 (build_translated_string ("Creating directory"), 1994 list3 (build_translated_string ("Creating directory"),
2001 build_translated_string ("pathame too long"), 1995 build_translated_string ("pathame too long"),
2002 dirname)); 1996 dirname_));
2003 } 1997 }
2004 strncpy (dir, (char *) XSTRING_DATA (dirname), 1998 strncpy (dir, (char *) XSTRING_DATA (dirname_),
2005 XSTRING_LENGTH (dirname) + 1); 1999 XSTRING_LENGTH (dirname_) + 1);
2006 2000
2007 #ifndef VMS 2001 #ifndef VMS
2008 if (dir [XSTRING_LENGTH (dirname) - 1] == '/') 2002 if (dir [XSTRING_LENGTH (dirname_) - 1] == '/')
2009 dir [XSTRING_LENGTH (dirname) - 1] = 0; 2003 dir [XSTRING_LENGTH (dirname_) - 1] = 0;
2010 #endif 2004 #endif
2011 2005
2012 #ifdef WINDOWSNT 2006 #ifdef WINDOWSNT
2013 if (mkdir (dir) != 0) 2007 if (mkdir (dir) != 0)
2014 #else 2008 #else
2015 if (mkdir (dir, 0777) != 0) 2009 if (mkdir (dir, 0777) != 0)
2016 #endif 2010 #endif
2017 report_file_error ("Creating directory", list1 (dirname)); 2011 report_file_error ("Creating directory", list1 (dirname_));
2018 2012
2019 return Qnil; 2013 return Qnil;
2020 } 2014 }
2021 2015
2022 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /* 2016 DEFUN ("delete-directory", Fdelete_directory, 1, 1, "FDelete directory: ", /*
2023 Delete a directory. One argument, a file name or directory name string. 2017 Delete a directory. One argument, a file name or directory name string.
2024 */ 2018 */
2025 (dirname)) 2019 (dirname_))
2026 { 2020 {
2027 /* This function can GC. GC checked 1997.04.06. */ 2021 /* This function can GC. GC checked 1997.04.06. */
2028 Lisp_Object handler; 2022 Lisp_Object handler;
2029 struct gcpro gcpro1; 2023 struct gcpro gcpro1;
2030 2024
2031 CHECK_STRING (dirname); 2025 CHECK_STRING (dirname_);
2032 2026
2033 GCPRO1 (dirname); 2027 GCPRO1 (dirname_);
2034 dirname = Fexpand_file_name (dirname, Qnil); 2028 dirname_ = Fexpand_file_name (dirname_, Qnil);
2035 dirname = Fdirectory_file_name (dirname); 2029 dirname_ = Fdirectory_file_name (dirname_);
2036 2030
2037 handler = Ffind_file_name_handler (dirname, Qdelete_directory); 2031 handler = Ffind_file_name_handler (dirname_, Qdelete_directory);
2038 UNGCPRO; 2032 UNGCPRO;
2039 if (!NILP (handler)) 2033 if (!NILP (handler))
2040 return (call2 (handler, Qdelete_directory, dirname)); 2034 return (call2 (handler, Qdelete_directory, dirname_));
2041 2035
2042 if (rmdir ((char *) XSTRING_DATA (dirname)) != 0) 2036 if (rmdir ((char *) XSTRING_DATA (dirname_)) != 0)
2043 report_file_error ("Removing directory", list1 (dirname)); 2037 report_file_error ("Removing directory", list1 (dirname_));
2044 2038
2045 return Qnil; 2039 return Qnil;
2046 } 2040 }
2047 2041
2048 DEFUN ("delete-file", Fdelete_file, 1, 1, "fDelete file: ", /* 2042 DEFUN ("delete-file", Fdelete_file, 1, 1, "fDelete file: ", /*
2937 #endif 2931 #endif
2938 2932
2939 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) ) 2933 if ( (!NILP (beg) || !NILP (end)) && !NILP (visit) )
2940 error ("Attempt to visit less than an entire file"); 2934 error ("Attempt to visit less than an entire file");
2941 2935
2942 if (!NILP (beg))
2943 CHECK_INT (beg);
2944 else
2945 beg = Qzero;
2946
2947 if (!NILP (end))
2948 CHECK_INT (end);
2949
2950 fd = -1; 2936 fd = -1;
2951 2937
2952 #ifndef APOLLO 2938 #ifndef APOLLO
2953 if (stat ((char *) XSTRING_DATA (filename), &st) < 0) 2939 if (stat ((char *) XSTRING_DATA (filename), &st) < 0)
2954 #else /* APOLLO */ 2940 #else /* APOLLO */
2969 /* This code will need to be changed in order to work on named 2955 /* This code will need to be changed in order to work on named
2970 pipes, and it's probably just not worth it. So we should at 2956 pipes, and it's probably just not worth it. So we should at
2971 least signal an error. */ 2957 least signal an error. */
2972 if (!S_ISREG (st.st_mode)) 2958 if (!S_ISREG (st.st_mode))
2973 { 2959 {
2974 if (NILP (visit)) 2960 not_regular = 1;
2961
2962 if (!NILP (visit))
2963 goto notfound;
2964
2965 if (!NILP (replace) || !NILP (beg) || !NILP (end))
2975 { 2966 {
2976 end_multiple_change (buf, mc_count); 2967 end_multiple_change (buf, mc_count);
2977 2968
2978 return Fsignal (Qfile_error, 2969 return Fsignal (Qfile_error,
2979 list2 (build_translated_string("not a regular file"), 2970 list2 (build_translated_string("not a regular file"),
2980 filename)); 2971 filename));
2981 } 2972 }
2982 else
2983 {
2984 not_regular = 1;
2985 goto notfound;
2986 }
2987 } 2973 }
2988 #endif 2974 #endif
2975
2976 if (!NILP (beg))
2977 CHECK_INT (beg);
2978 else
2979 beg = Qzero;
2980
2981 if (!NILP (end))
2982 CHECK_INT (end);
2989 2983
2990 if (fd < 0) 2984 if (fd < 0)
2991 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0) 2985 if ((fd = open ((char *) XSTRING_DATA (filename), O_RDONLY, 0)) < 0)
2992 goto badopen; 2986 goto badopen;
2993 2987
3001 if (st.st_size < 0) 2995 if (st.st_size < 0)
3002 error ("File size is negative"); 2996 error ("File size is negative");
3003 2997
3004 if (NILP (end)) 2998 if (NILP (end))
3005 { 2999 {
3006 end = make_int (st.st_size); 3000 if (!not_regular)
3007 if (XINT (end) != st.st_size) 3001 {
3008 error ("maximum buffer size exceeded"); 3002 end = make_int (st.st_size);
3003 if (XINT (end) != st.st_size)
3004 error ("Maximum buffer size exceeded");
3005 }
3009 } 3006 }
3010 3007
3011 /* If requested, replace the accessible part of the buffer 3008 /* If requested, replace the accessible part of the buffer
3012 with the file contents. Avoid replacing text at the 3009 with the file contents. Avoid replacing text at the
3013 beginning or end of the buffer that matches the file contents; 3010 beginning or end of the buffer that matches the file contents;
3129 /* Insert from the file at the proper position. */ 3126 /* Insert from the file at the proper position. */
3130 BUF_SET_PT (buf, same_at_start); 3127 BUF_SET_PT (buf, same_at_start);
3131 } 3128 }
3132 #endif /* FSFMACS_SPEEDY_INSERT */ 3129 #endif /* FSFMACS_SPEEDY_INSERT */
3133 3130
3134 total = XINT (end) - XINT (beg); 3131 if (!not_regular)
3132 {
3133 Lisp_Object temp;
3134
3135 total = XINT (end) - XINT (beg);
3136
3137 /* Make sure point-max won't overflow after this insertion. */
3138 XSETINT (temp, total);
3139 if (total != XINT (temp))
3140 error ("Maximum buffer size exceeded");
3141 }
3142 else
3143 /* For a special file, all we can do is guess. */
3144 total = READ_BUF_SIZE;
3135 3145
3136 if (XINT (beg) != 0 3146 if (XINT (beg) != 0
3137 #ifdef FSFMACS_SPEEDY_INSERT 3147 #ifdef FSFMACS_SPEEDY_INSERT
3138 /* why was this here? asked jwz. The reason is that the replace-mode 3148 /* why was this here? asked jwz. The reason is that the replace-mode
3139 connivings above will normally put the file pointer other than 3149 connivings above will normally put the file pointer other than