aboutsummaryrefslogtreecommitdiffstats
path: root/src/fileio.c
diff options
context:
space:
mode:
authorPaul Eggert2013-08-27 11:47:55 -0700
committerPaul Eggert2013-08-27 11:47:55 -0700
commit43aac990c339c0fc3304aa476ebc8ea8467f107e (patch)
tree24f6477d7ec79c7f3529e08c421f309b1180c436 /src/fileio.c
parent278208b8e6917af1e7e2623a3869614fa70059ed (diff)
downloademacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.tar.gz
emacs-43aac990c339c0fc3304aa476ebc8ea8467f107e.zip
Simplify EMACS_TIME-related code.
This portability layer is no longer needed, since Emacs has been using struct timespec as a portability layer for some time. Merge from gnulib, incorporating: 2013-08-27 timespec: new convenience constants and function * src/atimer.h, src/buffer.h, src/dispextern.h, src/xgselect.h: Include <time.h> rather than "systime.h"; that's all that's needed now. * src/dispnew.c: Include <timespec.h> rather than "systime.h"; that's all that's needed now. * src/systime.h (EMACS_TIME): Remove. All uses changed to struct timespec. (EMACS_TIME_RESOLUTION): Remove. All uses changed to TIMESPEC_RESOLUTION. (LOG10_EMACS_TIME_RESOLUTION): Remove. All uses changed to LOG10_TIMESPEC_RESOLUTION. (EMACS_SECS, emacs_secs_addr): Remove. All uses changed to tv_sec. (EMACS_NSECS): Remove. All uses changed to tv_nsec. (make_emacs_time): Remove. All used changed to make_timespec. (invalid_timespec): Rename from invalid_emacs_time. All uses changed. (current_timespec): Rename from current_emacs_time. All uses changed. (add_emacs_time): Remove. All uses changed to timespec_add. (sub_emacs_time): Remove. All uses change dot timespec_sub. (EMACS_TIME_SIGN): Remove. All uses changed to timespec_sign. (timespec_valid_p): Rename from EMACS_TIME_VALID_P. All uses changed. (EMACS_TIME_FROM_DOUBLE): Remove. All uses changed to dtotimespec. (EMACS_TIME_TO_DOUBLE): Remove. All uses changed to timespectod. (current_timespec): Rename from current_emacs_time. All uses changed. (EMACS_TIME_EQ, EMACS_TIME_LT, EMACS_TIME_LE): Remove. All uses changed to timespec_cmp. * src/xgselect.c: Include <timespec.h>, since our .h files don't.
Diffstat (limited to 'src/fileio.c')
-rw-r--r--src/fileio.c58
1 files changed, 29 insertions, 29 deletions
diff --git a/src/fileio.c b/src/fileio.c
index 7cad8d29da2..a751a73ae50 100644
--- a/src/fileio.c
+++ b/src/fileio.c
@@ -2045,7 +2045,7 @@ entries (depending on how Emacs was built). */)
2045 /* CopyFile retains the timestamp by default. */ 2045 /* CopyFile retains the timestamp by default. */
2046 else if (NILP (keep_time)) 2046 else if (NILP (keep_time))
2047 { 2047 {
2048 EMACS_TIME now; 2048 struct timespec now;
2049 DWORD attributes; 2049 DWORD attributes;
2050 char * filename; 2050 char * filename;
2051 2051
@@ -2054,7 +2054,7 @@ entries (depending on how Emacs was built). */)
2054 /* Ensure file is writable while its modified time is set. */ 2054 /* Ensure file is writable while its modified time is set. */
2055 attributes = GetFileAttributes (filename); 2055 attributes = GetFileAttributes (filename);
2056 SetFileAttributes (filename, attributes & ~FILE_ATTRIBUTE_READONLY); 2056 SetFileAttributes (filename, attributes & ~FILE_ATTRIBUTE_READONLY);
2057 now = current_emacs_time (); 2057 now = current_timespec ();
2058 if (set_file_times (-1, filename, now, now)) 2058 if (set_file_times (-1, filename, now, now))
2059 { 2059 {
2060 /* Restore original attributes. */ 2060 /* Restore original attributes. */
@@ -2178,8 +2178,8 @@ entries (depending on how Emacs was built). */)
2178 2178
2179 if (!NILP (keep_time)) 2179 if (!NILP (keep_time))
2180 { 2180 {
2181 EMACS_TIME atime = get_stat_atime (&st); 2181 struct timespec atime = get_stat_atime (&st);
2182 EMACS_TIME mtime = get_stat_mtime (&st); 2182 struct timespec mtime = get_stat_mtime (&st);
2183 if (set_file_times (ofd, SSDATA (encoded_newname), atime, mtime)) 2183 if (set_file_times (ofd, SSDATA (encoded_newname), atime, mtime))
2184 xsignal2 (Qfile_date_error, 2184 xsignal2 (Qfile_date_error,
2185 build_string ("Cannot set file date"), newname); 2185 build_string ("Cannot set file date"), newname);
@@ -3286,7 +3286,7 @@ Use the current time if TIMESTAMP is nil. TIMESTAMP is in the format of
3286{ 3286{
3287 Lisp_Object absname, encoded_absname; 3287 Lisp_Object absname, encoded_absname;
3288 Lisp_Object handler; 3288 Lisp_Object handler;
3289 EMACS_TIME t = lisp_time_argument (timestamp); 3289 struct timespec t = lisp_time_argument (timestamp);
3290 3290
3291 absname = Fexpand_file_name (filename, BVAR (current_buffer, directory)); 3291 absname = Fexpand_file_name (filename, BVAR (current_buffer, directory));
3292 3292
@@ -3363,7 +3363,7 @@ otherwise, if FILE2 does not exist, the answer is t. */)
3363 if (stat (SSDATA (absname2), &st2) < 0) 3363 if (stat (SSDATA (absname2), &st2) < 0)
3364 return Qt; 3364 return Qt;
3365 3365
3366 return (EMACS_TIME_LT (get_stat_mtime (&st2), get_stat_mtime (&st1)) 3366 return (timespec_cmp (get_stat_mtime (&st2), get_stat_mtime (&st1)) < 0
3367 ? Qt : Qnil); 3367 ? Qt : Qnil);
3368} 3368}
3369 3369
@@ -3463,13 +3463,13 @@ file_offset (Lisp_Object val)
3463} 3463}
3464 3464
3465/* Return a special time value indicating the error number ERRNUM. */ 3465/* Return a special time value indicating the error number ERRNUM. */
3466static EMACS_TIME 3466static struct timespec
3467time_error_value (int errnum) 3467time_error_value (int errnum)
3468{ 3468{
3469 int ns = (errnum == ENOENT || errnum == EACCES || errnum == ENOTDIR 3469 int ns = (errnum == ENOENT || errnum == EACCES || errnum == ENOTDIR
3470 ? NONEXISTENT_MODTIME_NSECS 3470 ? NONEXISTENT_MODTIME_NSECS
3471 : UNKNOWN_MODTIME_NSECS); 3471 : UNKNOWN_MODTIME_NSECS);
3472 return make_emacs_time (0, ns); 3472 return make_timespec (0, ns);
3473} 3473}
3474 3474
3475DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents, 3475DEFUN ("insert-file-contents", Finsert_file_contents, Sinsert_file_contents,
@@ -3501,7 +3501,7 @@ by calling `format-decode', which see. */)
3501 (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, Lisp_Object replace) 3501 (Lisp_Object filename, Lisp_Object visit, Lisp_Object beg, Lisp_Object end, Lisp_Object replace)
3502{ 3502{
3503 struct stat st; 3503 struct stat st;
3504 EMACS_TIME mtime; 3504 struct timespec mtime;
3505 int fd; 3505 int fd;
3506 ptrdiff_t inserted = 0; 3506 ptrdiff_t inserted = 0;
3507 ptrdiff_t how_much; 3507 ptrdiff_t how_much;
@@ -4567,7 +4567,7 @@ by calling `format-decode', which see. */)
4567 } 4567 }
4568 4568
4569 if (!NILP (visit) 4569 if (!NILP (visit)
4570 && EMACS_NSECS (current_buffer->modtime) == NONEXISTENT_MODTIME_NSECS) 4570 && current_buffer->modtime.tv_nsec == NONEXISTENT_MODTIME_NSECS)
4571 { 4571 {
4572 /* If visiting nonexistent file, return nil. */ 4572 /* If visiting nonexistent file, return nil. */
4573 report_file_errno ("Opening input file", orig_filename, save_errno); 4573 report_file_errno ("Opening input file", orig_filename, save_errno);
@@ -4766,7 +4766,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
4766 int save_errno = 0; 4766 int save_errno = 0;
4767 const char *fn; 4767 const char *fn;
4768 struct stat st; 4768 struct stat st;
4769 EMACS_TIME modtime; 4769 struct timespec modtime;
4770 ptrdiff_t count = SPECPDL_INDEX (); 4770 ptrdiff_t count = SPECPDL_INDEX ();
4771 ptrdiff_t count1 IF_LINT (= 0); 4771 ptrdiff_t count1 IF_LINT (= 0);
4772 Lisp_Object handler; 4772 Lisp_Object handler;
@@ -4980,7 +4980,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
4980 } 4980 }
4981 } 4981 }
4982 4982
4983 modtime = invalid_emacs_time (); 4983 modtime = invalid_timespec ();
4984 if (visiting) 4984 if (visiting)
4985 { 4985 {
4986 if (fstat (desc, &st) == 0) 4986 if (fstat (desc, &st) == 0)
@@ -5014,7 +5014,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
5014 unlikely and a similar race between the last write and the fstat 5014 unlikely and a similar race between the last write and the fstat
5015 above cannot possibly be closed anyway. */ 5015 above cannot possibly be closed anyway. */
5016 5016
5017 if (EMACS_TIME_VALID_P (modtime) 5017 if (timespec_valid_p (modtime)
5018 && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system)) 5018 && ! (valid_timestamp_file_system && st.st_dev == timestamp_file_system))
5019 { 5019 {
5020 int desc1 = emacs_open (fn, O_WRONLY | O_BINARY, 0); 5020 int desc1 = emacs_open (fn, O_WRONLY | O_BINARY, 0);
@@ -5036,11 +5036,11 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
5036 bool use_heuristic 5036 bool use_heuristic
5037 = ((open_flags & (O_EXCL | O_TRUNC)) != 0 5037 = ((open_flags & (O_EXCL | O_TRUNC)) != 0
5038 && st.st_size != 0 5038 && st.st_size != 0
5039 && EMACS_NSECS (modtime) % 100 != 0); 5039 && modtime.tv_nsec % 100 != 0);
5040 5040
5041 EMACS_TIME modtime1 = get_stat_mtime (&st1); 5041 struct timespec modtime1 = get_stat_mtime (&st1);
5042 if (use_heuristic 5042 if (use_heuristic
5043 && EMACS_TIME_EQ (modtime, modtime1) 5043 && timespec_cmp (modtime, modtime1) == 0
5044 && st.st_size == st1.st_size) 5044 && st.st_size == st1.st_size)
5045 { 5045 {
5046 timestamp_file_system = st.st_dev; 5046 timestamp_file_system = st.st_dev;
@@ -5080,7 +5080,7 @@ write_region (Lisp_Object start, Lisp_Object end, Lisp_Object filename,
5080 /* Do this before reporting IO error 5080 /* Do this before reporting IO error
5081 to avoid a "file has changed on disk" warning on 5081 to avoid a "file has changed on disk" warning on
5082 next attempt to save. */ 5082 next attempt to save. */
5083 if (EMACS_TIME_VALID_P (modtime)) 5083 if (timespec_valid_p (modtime))
5084 { 5084 {
5085 current_buffer->modtime = modtime; 5085 current_buffer->modtime = modtime;
5086 current_buffer->modtime_size = st.st_size; 5086 current_buffer->modtime_size = st.st_size;
@@ -5355,7 +5355,7 @@ See Info node `(elisp)Modification Time' for more details. */)
5355 struct stat st; 5355 struct stat st;
5356 Lisp_Object handler; 5356 Lisp_Object handler;
5357 Lisp_Object filename; 5357 Lisp_Object filename;
5358 EMACS_TIME mtime; 5358 struct timespec mtime;
5359 5359
5360 if (NILP (buf)) 5360 if (NILP (buf))
5361 b = current_buffer; 5361 b = current_buffer;
@@ -5366,7 +5366,7 @@ See Info node `(elisp)Modification Time' for more details. */)
5366 } 5366 }
5367 5367
5368 if (!STRINGP (BVAR (b, filename))) return Qt; 5368 if (!STRINGP (BVAR (b, filename))) return Qt;
5369 if (EMACS_NSECS (b->modtime) == UNKNOWN_MODTIME_NSECS) return Qt; 5369 if (b->modtime.tv_nsec == UNKNOWN_MODTIME_NSECS) return Qt;
5370 5370
5371 /* If the file name has special constructs in it, 5371 /* If the file name has special constructs in it,
5372 call the corresponding file handler. */ 5372 call the corresponding file handler. */
@@ -5380,7 +5380,7 @@ See Info node `(elisp)Modification Time' for more details. */)
5380 mtime = (stat (SSDATA (filename), &st) == 0 5380 mtime = (stat (SSDATA (filename), &st) == 0
5381 ? get_stat_mtime (&st) 5381 ? get_stat_mtime (&st)
5382 : time_error_value (errno)); 5382 : time_error_value (errno));
5383 if (EMACS_TIME_EQ (mtime, b->modtime) 5383 if (timespec_cmp (mtime, b->modtime) == 0
5384 && (b->modtime_size < 0 5384 && (b->modtime_size < 0
5385 || st.st_size == b->modtime_size)) 5385 || st.st_size == b->modtime_size))
5386 return Qt; 5386 return Qt;
@@ -5397,7 +5397,7 @@ doesn't exist, return -1.
5397See Info node `(elisp)Modification Time' for more details. */) 5397See Info node `(elisp)Modification Time' for more details. */)
5398 (void) 5398 (void)
5399{ 5399{
5400 int ns = EMACS_NSECS (current_buffer->modtime); 5400 int ns = current_buffer->modtime.tv_nsec;
5401 if (ns < 0) 5401 if (ns < 0)
5402 return make_number (UNKNOWN_MODTIME_NSECS - ns); 5402 return make_number (UNKNOWN_MODTIME_NSECS - ns);
5403 return make_lisp_time (current_buffer->modtime); 5403 return make_lisp_time (current_buffer->modtime);
@@ -5416,11 +5416,11 @@ An argument specifies the modification time value to use
5416{ 5416{
5417 if (!NILP (time_flag)) 5417 if (!NILP (time_flag))
5418 { 5418 {
5419 EMACS_TIME mtime; 5419 struct timespec mtime;
5420 if (INTEGERP (time_flag)) 5420 if (INTEGERP (time_flag))
5421 { 5421 {
5422 CHECK_RANGED_INTEGER (time_flag, -1, 0); 5422 CHECK_RANGED_INTEGER (time_flag, -1, 0);
5423 mtime = make_emacs_time (0, UNKNOWN_MODTIME_NSECS - XINT (time_flag)); 5423 mtime = make_timespec (0, UNKNOWN_MODTIME_NSECS - XINT (time_flag));
5424 } 5424 }
5425 else 5425 else
5426 mtime = lisp_time_argument (time_flag); 5426 mtime = lisp_time_argument (time_flag);
@@ -5683,12 +5683,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5683 || NILP (Ffind_file_name_handler (BVAR (b, auto_save_file_name), 5683 || NILP (Ffind_file_name_handler (BVAR (b, auto_save_file_name),
5684 Qwrite_region)))) 5684 Qwrite_region))))
5685 { 5685 {
5686 EMACS_TIME before_time = current_emacs_time (); 5686 struct timespec before_time = current_timespec ();
5687 EMACS_TIME after_time; 5687 struct timespec after_time;
5688 5688
5689 /* If we had a failure, don't try again for 20 minutes. */ 5689 /* If we had a failure, don't try again for 20 minutes. */
5690 if (b->auto_save_failure_time > 0 5690 if (b->auto_save_failure_time > 0
5691 && EMACS_SECS (before_time) - b->auto_save_failure_time < 1200) 5691 && before_time.tv_sec - b->auto_save_failure_time < 1200)
5692 continue; 5692 continue;
5693 5693
5694 set_buffer_internal (b); 5694 set_buffer_internal (b);
@@ -5721,12 +5721,12 @@ A non-nil CURRENT-ONLY argument means save only current buffer. */)
5721 XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG); 5721 XSETFASTINT (BVAR (current_buffer, save_length), Z - BEG);
5722 set_buffer_internal (old); 5722 set_buffer_internal (old);
5723 5723
5724 after_time = current_emacs_time (); 5724 after_time = current_timespec ();
5725 5725
5726 /* If auto-save took more than 60 seconds, 5726 /* If auto-save took more than 60 seconds,
5727 assume it was an NFS failure that got a timeout. */ 5727 assume it was an NFS failure that got a timeout. */
5728 if (EMACS_SECS (after_time) - EMACS_SECS (before_time) > 60) 5728 if (after_time.tv_sec - before_time.tv_sec > 60)
5729 b->auto_save_failure_time = EMACS_SECS (after_time); 5729 b->auto_save_failure_time = after_time.tv_sec;
5730 } 5730 }
5731 } 5731 }
5732 5732