X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Feditfns.c;h=8ad18f53e0210628136c3f3fb8357a2538a4776b;hb=3f711eea68ce5fd586297b43c8d9936cd2ba916f;hp=bc3d29b09e766bfb96f06c4b2aa086194ff74a93;hpb=21db8709c0c2dcedbd278c7fe571290d5ce80a71;p=chise%2Fxemacs-chise.git.1 diff --git a/src/editfns.c b/src/editfns.c index bc3d29b..8ad18f5 100644 --- a/src/editfns.c +++ b/src/editfns.c @@ -644,14 +644,17 @@ On Unix it is obtained from TMPDIR, with /tmp as the default. } else { - strcpy(path, getenv("HOME")); strncat(path, "/tmp/", _POSIX_PATH_MAX); + path[5 + _POSIX_PATH_MAX] = '\0'; + strncpy(path, getenv("HOME"), 5 + _POSIX_PATH_MAX); + strncat(path, "/tmp/", 5 + _POSIX_PATH_MAX); if (stat(path, &st) < 0 && errno == ENOENT) { int fd; - char warnpath[1+_POSIX_PATH_MAX]; + char warnpath[6+_POSIX_PATH_MAX]; mkdir(path, 0700); /* ignore retvals */ - strcpy(warnpath, path); - strncat(warnpath, ".created_by_xemacs", _POSIX_PATH_MAX); + warnpath[_POSIX_PATH_MAX] = '\0'; + strncpy(warnpath, path, 5 + _POSIX_PATH_MAX); + strncat(warnpath, ".created_by_xemacs", 5 + _POSIX_PATH_MAX); if ((fd = open(warnpath, O_WRONLY|O_CREAT, 0644)) > 0) { write(fd, "XEmacs created this directory because /tmp/ was unavailable -- \nPlease check !\n", 89); @@ -1107,10 +1110,11 @@ characters appearing in the day and month names may be incorrect. { time_t value; size_t size; + struct tm * tm; CHECK_STRING (format_string); - if (! lisp_to_time (time_, &value)) + if (! lisp_to_time (time_, &value) || ! (tm = localtime (&value))) error ("Invalid time specification"); /* This is probably enough. */ @@ -1122,7 +1126,7 @@ characters appearing in the day and month names may be incorrect. *buf = 1; if (emacs_strftime (buf, size, (const char *) XSTRING_DATA (format_string), - localtime (&value)) + tm) || !*buf) return build_ext_string (buf, Qbinary); /* If buffer was too small, make it bigger. */ @@ -1151,10 +1155,10 @@ ZONE is an integer indicating the number of seconds east of Greenwich. struct tm *decoded_time; Lisp_Object list_args[9]; - if (! lisp_to_time (specified_time, &time_spec)) + if (! lisp_to_time (specified_time, &time_spec) + || ! (decoded_time = localtime (&time_spec))) error ("Invalid time specification"); - decoded_time = localtime (&time_spec); list_args[0] = make_int (decoded_time->tm_sec); list_args[1] = make_int (decoded_time->tm_min); list_args[2] = make_int (decoded_time->tm_hour); @@ -1176,6 +1180,15 @@ ZONE is an integer indicating the number of seconds east of Greenwich. static void set_time_zone_rule (char *tzstring); +/* from GNU Emacs 21, per Simon Josefsson, modified by stephen + The slight inefficiency is justified since negative times are weird. */ +Lisp_Object +make_time (time_t tval) +{ + return list2 (make_int (tval < 0 ? tval / 0x10000 : tval >> 16), + make_int (tval & 0xFFFF)); +} + DEFUN ("encode-time", Fencode_time, 6, MANY, 0, /* Convert SECOND, MINUTE, HOUR, DAY, MONTH, YEAR and ZONE to internal time. This is the reverse operation of `decode-time', which see. @@ -1249,7 +1262,7 @@ If you want them to stand for years in this century, you must do that yourself. if (the_time == (time_t) -1) error ("Specified time is not representable"); - return wasteful_word_to_lisp (the_time); + return make_time (the_time); } DEFUN ("current-time-string", Fcurrent_time_string, 0, 1, 0, /*