aboutsummaryrefslogtreecommitdiff
path: root/src/time (follow)
Commit message (Expand)AuthorAgeFilesLines
* fix handling of negative offsets in timezone spec strings•••previously, the hours were considered as a signed quantity while minutes and seconds were always treated as positive offsets. however, semantically the '-' sign should negate the whole hh:mm:ss offset. this bug only affected timezones east of GMT with non-whole-hours offsets, such as those used in India and Nepal. Rich Felker2014-10-091-10/+7
* add C11 timespec_get function, with associated time.h changes for C11•••based on patch by Jens Gustedt for inclusion with C11 threads implementation, but committed separately since it's independent of threads. Rich Felker2014-09-061-0/+12
* properly pass current locale to *_l functions when used internally•••this change is presently non-functional since the callees do not yet use their locale argument for anything. Rich Felker2014-07-022-2/+4
* use default timezone from /etc/localtime if $TZ is unset/blank•••the way this is implemented, it also allows explicit setting of TZ=/etc/localtime even for suid programs. this is not a problem because /etc/localtime is a trusted path, much like the trusted zoneinfo search path. Rich Felker2014-06-061-2/+3
* implement %y and %C specifiers in strptimeTimo Teräs2014-06-061-4/+10
* support linux kernel apis (new archs) with old syscalls removed•••such archs are expected to omit definitions of the SYS_* macros for syscalls their kernels lack from arch/$ARCH/bits/syscall.h. the preprocessor is then able to select the an appropriate implementation for affected functions. two basic strategies are used on a case-by-case basis: where the old syscalls correspond to deprecated library-level functions, the deprecated functions have been converted to wrappers for the modern function, and the modern function has fallback code (omitted at the preprocessor level on new archs) to make use of the old syscalls if the new syscall fails with ENOSYS. this also improves functionality on older kernels and eliminates the incentive to program with deprecated library-level functions for the sake of compatibility with older kernels. in other situations where the old syscalls correspond to library-level functions which are not deprecated but merely lack some new features, such as the *at functions, the old syscalls are still used on archs which support them. this may change at some point in the future if or when fallback code is added to the new functions to make them usable (possibly with reduced functionality) on old kernels. Rich Felker2014-05-291-9/+6
* support kernels with no SYS_open syscall, only SYS_openat•••open is handled specially because it is used from so many places, in so many variants (2 or 3 arguments, setting errno or not, and cancellable or not). trying to do it as a function would not only increase bloat, but would also risk subtle breakage. this is the first step towards supporting "new" archs where linux lacks "old" syscalls. Rich Felker2014-05-241-2/+1
* fix unhandled cases in strptime•••%C, %U, %W, and %y handling were completely missing; %C wrongly fell-through to unrelated cases, and the rest returned failure. for now, they all parse numbers in the proper forms and range-check the values, but they do not store the value anywhere. it's not clear to me whether, as "derived" fields, %U and %W should produce any result. they certainly cannot produce a result unless the year and weekday are also converted, but in this case it might be desirable for them to do so. clarification is needed on the intended behavior of strptime in cases like this. %C and %y have well-defined behavior as long as they are used together (and %y is defined by itself but may change in the future). implementing them (including their correct interaction) is left as a later change to be made. finally, strptime now rejects unknown/invalid format characters instead of ignoring them. Rich Felker2014-05-191-5/+16
* fix strftime %s not to zero pad with default width=2Szabolcs Nagy2014-05-081-0/+1
* perform minimal sanity checks on zoneinfo files loaded via TZ variable•••previously, setting TZ to the pathname of a file which was not a valid zoneinfo file would usually cause programs using local time zone based operations to crash. the new code checks the file size and magic at the beginning of the file, which seems sufficient to prevent accidental misconfiguration from causing crashes. attempting to make fully-robust validation would be futile unless we wanted to drop use of mmap (shared zoneinfo) and instead read it into a local buffer, since such validation would be subject to race conditions with modification of the file. Rich Felker2014-04-221-0/+5
* do not try to interpret implementation specific strings as tz definitionTimo Teräs2014-04-221-0/+1
* allow zoneinfo-path-relative filenames with no slashes in TZ variable•••since the form TZ=name is reserved for POSIX-form time zone strings, TZ=:name needs to be used when the zoneinfo filename is in the top-level zoneinfo directory and therefore does not contain a slash. previously the leading colon was merely dropped, making it impossible to access such zones without a full absolute pathname. changes based on patch by Timo Teräs. Rich Felker2014-04-211-12/+8
* add working vdso clock_gettime support, including static linking•••the vdso symbol lookup code is based on the original 2011 patch by Nicholas J. Kain, with some streamlining, pointer arithmetic fixes, and one symbol version matching fix. on the consumer side (clock_gettime), per-arch macros for the particular symbol name and version to lookup are added in syscall_arch.h, and no vdso code is pulled in on archs which do not define these macros. at this time, vdso is enabled only on x86_64. the vdso support at the dynamic linker level is no longer useful to libc, but is left in place for the sake of debuggers (which may need the vdso in the link map to find its functions) and possibly use with dlsym. Rich Felker2014-04-161-5/+13
* fix fallback code for old kernels in clock_gettimeRich Felker2014-04-141-1/+1
* eliminate explicit (long) casts when making syscalls•••this practice came from very early, before internal/syscall.h defined macros that could accept pointer arguments directly and handle them correctly. aside from being ugly and unnecessary, it looks like it will be problematic when we add support for 32-bit ABIs on archs where registers (and syscall arguments) are 64-bit, e.g. x32 and mips n32. Rich Felker2014-01-064-4/+4
* fix hangs in localtime for near-overflowing time_t values on 64-bit archsRich Felker2013-12-191-0/+6
* include cleanups: remove unused headers and add feature test macrosSzabolcs Nagy2013-12-125-6/+0
* fix off-by-one length failure in strftime/wcsftime and improve error behavior•••these functions were spuriously failing in the case where the buffer size was exactly the number of bytes/characters to be written, including null termination. since these functions do not have defined error conditions other than buffer size, a reasonable application may fail to check the return value when the format string and buffer size are known to be valid; such an application could then attempt to use a non-terminated buffer. in addition to fixing the bug, I have changed the error handling behavior so that these functions always null-terminate the output except in the case where the buffer size is zero, and so that they always write as many characters as possible before failing, rather than dropping whole fields that do not fit. this actually simplifies the logic somewhat anyway. Rich Felker2013-11-262-12/+16
* remove O_NOFOLLOW from __map_file used for time zone file loading•••it's not clear why I originally wrote O_NOFOLLOW into this; I suspect the reason was with an aim of making the function more general for mapping partially or fully untrusted files provided by the user. however, the timezone code already precludes use of absolute or relative pathnames in suid/sgid programs, and disallows .. in pathnames which are relative to one of the system timezone locations, so there is no threat of opening a symlink which is not trusted by appropriate user. since some users may wish to put symbolic links in the zoneinfo directories to alias timezones, it seems preferable to allow this. Rich Felker2013-11-081-1/+1
* fix handling of overly-long TZ environment variable values•••the rest of the code is not prepared to handle an empty TZ string, so falling back to __gmt ("GMT"), just as if TZ had been blank or unset, is the preferable action. Rich Felker2013-11-081-1/+1
* timezone parser: fix iteration over search dir paths•••try+l points to \0, so only one iteration was ever tried. rofl0r2013-11-041-1/+1
* timezone parser: fix offset to transition table in 64bit code path•••we need to skip to the second TZif header, which starts at skip+44, and then skip another header (20 bytes) plus the following 6 32bit values. rofl0r2013-11-041-1/+1
* fix timezone parser code crashing on 64bit sys•••if sizeof(time_t) == 8, this code path was missing the correct offset into the zoneinfo file, using the header magic to do offset calculations. the 6 32bit fields to be read start at offset 20. rofl0r2013-11-041-1/+1
* add legacy ftime function and sys/timeb.h•••despite being marked legacy, this was specified by SUSv3 as part of the XSI option; only the most recent version of the standard dropped it. reportedly there's actual code using it. Rich Felker2013-10-251-0/+12
* add the %s (seconds since the epoch) format to strftime•••this is a nonstandard extension but will be required in the next version of POSIX, and it's widely used/useful in shell scripts utilizing the date utility. Rich Felker2013-08-251-0/+4
* fix strftime regression in %e format•••%e pads with spaces instead of zeros. Rich Felker2013-08-241-2/+2
* properly fill in tzname[] for old (pre-64-bit-format) zoneinfo files•••in this case, the first standard-time and first daylight-time rules should be taken as the "default" ones to expose. Rich Felker2013-08-241-1/+22
* minor fix to tz name checking•••if a zoneinfo file is not (or is no longer) in use, don't check the abbrevs pointers, which may be invalid. Rich Felker2013-08-241-2/+2
* fix strftime handling of time zone data•••this may need further revision in the future, since POSIX is rather unclear on the requirements, and is designed around the assumption of POSIX TZ specifiers which are not sufficiently powerful to represent real-world timezones (this is why zoneinfo support was added). the basic issue is that strftime gets the string and numeric offset for the timezone from the extra fields in struct tm, which are initialized when calling localtime/gmtime/etc. however, a conforming application might have created its own struct tm without initializing these fields, in which case using __tm_zone (a pointer) could crash. other zoneinfo-based implementations simply check for a null pointer, but otherwise can still crash of the field contains junk. simply ignoring __tm_zone and using tzname[] would "work" but would give incorrect results in time zones with more complex rules. I feel like this would lower the quality of implementation. instead, simply validate __tm_zone: unless it points to one of the zone name strings managed by the timezone system, assume it's invalid. this commit also fixes several other minor bugs with formatting: tm_isdst being negative is required to suppress printing of the zone formats, and %z was using the wrong format specifiers since the type of val was changed, resulting in bogus output. Rich Felker2013-08-244-8/+36
* fix mishandling of empty or blank TZ environment variable•••the empty TZ string was matching equal to the initial value of the cached TZ name, thus causing do_tzset never to run and never to initialize the time zone data. Rich Felker2013-08-231-1/+1
* fix missing string.h in strftime.c (needed by new strftime code)•••this bug was masked by local experimental CFLAGS in my config.mak. Rich Felker2013-08-231-0/+1
* add strftime and wcsftime field widths•••at present, since POSIX requires %F to behave as %+4Y-%m-%d and ISO C requires %F to behave as %Y-%m-%d, the default behavior for %Y has been changed to match %+4Y. this seems to be the only way to conform to the requirements of both standards, and it does not affect years prior to the year 10000. depending on the outcome of interpretations from the standards bodies, this may be adjusted at some point. Rich Felker2013-08-222-24/+81
* simplify strftime and fix integer overflows•••use a long long value so that even with offsets, values cannot overflow. instead of using different format strings for different numeric formats, simply use a per-format width and %0*lld for all of them. this width specifier is not for use with strftime field widths; that will be a separate step in the caller. Rich Felker2013-08-221-28/+12
* strftime cleanup: avoid recomputing strlen when it's knownRich Felker2013-08-221-10/+16
* more strftime refactoring•••make __strftime_fmt_1 return a string (possibly in the caller-provided temp buffer) rather than writing into the output buffer. this approach makes more sense when padding to a minimum field width might be required, and it's also closer to what wcsftime wants. Rich Felker2013-08-221-23/+25
* begin refactoring strftime to make adding field widths easierRich Felker2013-08-221-151/+161
* have new timer threads unblock their own SIGTIMER•••unblocking it in the pthread_once init function is not sufficient, since multiple threads, some of them with the signal blocked, could already exist before this is called; timers started from such threads would be non-functional. Rich Felker2013-08-031-2/+2
* add system for resetting TLS to initial values•••this is needed for reused threads in the SIGEV_THREAD timer notification system, and could be reused elsewhere in the future if needed, though it should be refactored for such use. for static linking, __init_tls.c is simply modified to export the TLS info in a structure with external linkage, rather than using statics. this perhaps makes the code more clear, since the statics were poorly named for statics. the new __reset_tls.c is only linked if it is used. for dynamic linking, the code is in dynlink.c. sharing code with __copy_tls is not practical since __reset_tls must also re-zero thread-local bss. Rich Felker2013-08-031-0/+3
* fix multiple bugs in SIGEV_THREAD timers•••1. the thread result field was reused for storing a kernel timer id, but would be overwritten if the application code exited or cancelled the thread. 2. low pointer values were used as the indicator that the timer id is a kernel timer id rather than a thread id. this is not portable, as mmap may return low pointers on some conditions. instead, use the fact that pointers must be aligned and kernel timer ids must be non-negative to map pointers into the negative integer space. 3. signals were not blocked until after the timer thread started, so a race condition could allow a signal handler to run in the timer thread when it's not supposed to exist. this is mainly problematic if the calling thread was the only thread where the signal was unblocked and the signal handler assumes it runs in that thread. Rich Felker2013-08-035-21/+35
* add wcsftime_t alias•••this is a nonstandard extension. Rich Felker2013-08-021-0/+3
* fix semantically incorrect use of LC_GLOBAL_LOCALE•••LC_GLOBAL_LOCALE refers to the global locale, controlled by setlocale, not the thread-local locale in effect which these functions should be using. neither LC_GLOBAL_LOCALE nor 0 has an argument to the *_l functions has behavior defined by the standard, but 0 is a more logical choice for requesting the callee to lookup the current locale. in the future I may move the current locale lookup the the caller (the non-_l-suffixed wrapper). at this point, all of the locale logic is dummied out, so no harm was done, but it should at least avoid misleading usage. Rich Felker2013-07-282-2/+2
* reorder strftime to eliminate the incorrect indention level•••this change is in preparation for possibly adding support for the field width and padding specifiers added in POSIX 2008. Rich Felker2013-07-271-5/+5
* rework langinfo code for ABI compat and for use by time codeRich Felker2013-07-242-8/+9
* add __wcsftime_l symbol•••unlike the strftime commit, this one is purely an ABI compatibility issue. the previous version of the code would have worked just as well with LC_TIME once LC_TIME support is added. Rich Felker2013-07-241-3/+9
* move strftime_l into strftime.c and add __-prefixed version•••the latter is both for ABI purposes, and to facilitate eventually adding LC_TIME support. it's also nice to eliminate an extra source file. Rich Felker2013-07-241-1/+10
* fix error code on time conversion overflows•••POSIX mandates EOVERFLOW for this condition. Rich Felker2013-07-174-4/+4
* fix fd leak in file mapping code used in new zoneinfo supportRich Felker2013-07-171-1/+1
* the big time handling overhaul•••this commit has two major user-visible parts: zoneinfo-format time zones are now supported, and overflow handling is intended to be complete in the sense that all functions return a correct result if and only if the result fits in the destination type, and otherwise return an error. also, some noticable bugs in the way DST detection and normalization worked have been fixed, and performance may be better than before, but it has not been tested. Rich Felker2013-07-1718-348/+649
* implement week-based-year year numbers in strftime•••in the process, I refactored the week-number code so it can be used by the week-based-year formats to determine year adjustments at the boundary values. this also improves indention/code readability. Rich Felker2013-06-281-27/+34
* fix breakage in last commit to strftime due to missing INT_MAX•••that's what I get for changing a hard-coded threshold to a proper non-magic-number without testing. Rich Felker2013-06-281-0/+1