diff options
| author | Miles Bader | 2006-04-09 00:38:22 +0000 |
|---|---|---|
| committer | Miles Bader | 2006-04-09 00:38:22 +0000 |
| commit | 49d395cd57e646162e7f646a8561a416abacac82 (patch) | |
| tree | d7fabed45dfc19d6bff30024f82613f372b97951 /src/editfns.c | |
| parent | b6828792a25d042ede1ed164389531e30cc3e202 (diff) | |
| parent | 1b155fbd766b0a0f78fca5de62dd16a3542883f1 (diff) | |
| download | emacs-49d395cd57e646162e7f646a8561a416abacac82.tar.gz emacs-49d395cd57e646162e7f646a8561a416abacac82.zip | |
Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-54
Merge from emacs--devo--0
Patches applied:
* emacs--devo--0 (patch 190-203)
- Update from CVS
- Undo incorrect merge of etc/images/README from Gnus 5.10
- Merge from gnus--rel--5.10
* gnus--rel--5.10 (patch 74-80)
- Update from CVS
- Update from CVS: README: Addition from 5.10.6 tar ball.
Diffstat (limited to 'src/editfns.c')
| -rw-r--r-- | src/editfns.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/editfns.c b/src/editfns.c index 59401fdfecd..b0e79057988 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -74,6 +74,13 @@ extern char **environ; | |||
| 74 | 74 | ||
| 75 | #define TM_YEAR_BASE 1900 | 75 | #define TM_YEAR_BASE 1900 |
| 76 | 76 | ||
| 77 | /* Nonzero if TM_YEAR is a struct tm's tm_year value that causes | ||
| 78 | asctime to have well-defined behavior. */ | ||
| 79 | #ifndef TM_YEAR_IN_ASCTIME_RANGE | ||
| 80 | # define TM_YEAR_IN_ASCTIME_RANGE(tm_year) \ | ||
| 81 | (1000 - TM_YEAR_BASE <= (tm_year) && (tm_year) <= 9999 - TM_YEAR_BASE) | ||
| 82 | #endif | ||
| 83 | |||
| 77 | extern size_t emacs_strftimeu P_ ((char *, size_t, const char *, | 84 | extern size_t emacs_strftimeu P_ ((char *, size_t, const char *, |
| 78 | const struct tm *, int)); | 85 | const struct tm *, int)); |
| 79 | static int tm_diff P_ ((struct tm *, struct tm *)); | 86 | static int tm_diff P_ ((struct tm *, struct tm *)); |
| @@ -1831,7 +1838,8 @@ usage: (encode-time SECOND MINUTE HOUR DAY MONTH YEAR &optional ZONE) */) | |||
| 1831 | DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0, | 1838 | DEFUN ("current-time-string", Fcurrent_time_string, Scurrent_time_string, 0, 1, 0, |
| 1832 | doc: /* Return the current time, as a human-readable string. | 1839 | doc: /* Return the current time, as a human-readable string. |
| 1833 | Programs can use this function to decode a time, | 1840 | Programs can use this function to decode a time, |
| 1834 | since the number of columns in each field is fixed. | 1841 | since the number of columns in each field is fixed |
| 1842 | if the year is in the range 1000-9999. | ||
| 1835 | The format is `Sun Sep 16 01:03:52 1973'. | 1843 | The format is `Sun Sep 16 01:03:52 1973'. |
| 1836 | However, see also the functions `decode-time' and `format-time-string' | 1844 | However, see also the functions `decode-time' and `format-time-string' |
| 1837 | which provide a much more powerful and general facility. | 1845 | which provide a much more powerful and general facility. |
| @@ -1845,31 +1853,23 @@ but this is considered obsolete. */) | |||
| 1845 | Lisp_Object specified_time; | 1853 | Lisp_Object specified_time; |
| 1846 | { | 1854 | { |
| 1847 | time_t value; | 1855 | time_t value; |
| 1848 | char buf[30]; | ||
| 1849 | struct tm *tm; | 1856 | struct tm *tm; |
| 1850 | register char *tem; | 1857 | register char *tem; |
| 1851 | 1858 | ||
| 1852 | if (! lisp_time_argument (specified_time, &value, NULL)) | 1859 | if (! lisp_time_argument (specified_time, &value, NULL)) |
| 1853 | error ("Invalid time specification"); | 1860 | error ("Invalid time specification"); |
| 1854 | /* Do not use ctime, since it has undefined behavior with | 1861 | |
| 1855 | out-of-range time stamps. This avoids a core dump triggered by | 1862 | /* Convert to a string, checking for out-of-range time stamps. |
| 1856 | (current-time-string '(2814749767106 0)) on 64-bit Solaris 8. See | 1863 | Don't use 'ctime', as that might dump core if VALUE is out of |
| 1857 | <http://www.opengroup.org/austin/mailarchives/ag/msg09294.html> | 1864 | range. */ |
| 1858 | for more details about this portability problem. */ | ||
| 1859 | tm = localtime (&value); | 1865 | tm = localtime (&value); |
| 1860 | /* Checking for out-of-range time stamps avoids buffer overruns that | 1866 | if (! (tm && TM_YEAR_IN_ASCTIME_RANGE (tm->tm_year) && (tem = asctime (tm)))) |
| 1861 | cause core dump on some systems (e.g., 64-bit Solaris), and also | ||
| 1862 | preserves the historic behavior of always returning a fixed-size | ||
| 1863 | 24-character string. */ | ||
| 1864 | if (! (tm && -999 - TM_YEAR_BASE <= tm->tm_year | ||
| 1865 | && tm->tm_year <= 9999 - TM_YEAR_BASE)) | ||
| 1866 | error ("Specified time is not representable"); | 1867 | error ("Specified time is not representable"); |
| 1867 | tem = asctime (tm); | ||
| 1868 | 1868 | ||
| 1869 | strncpy (buf, tem, 24); | 1869 | /* Remove the trailing newline. */ |
| 1870 | buf[24] = 0; | 1870 | tem[strlen (tem) - 1] = '\0'; |
| 1871 | 1871 | ||
| 1872 | return build_string (buf); | 1872 | return build_string (tem); |
| 1873 | } | 1873 | } |
| 1874 | 1874 | ||
| 1875 | /* Yield A - B, measured in seconds. | 1875 | /* Yield A - B, measured in seconds. |