getdate, getdate_r — convert a string to struct tm
#define _XOPEN_SOURCE 500 #include <time.h>
struct tm *getdate( |
const char * | string) ; |
extern int getdate_err; #define _GNU_SOURCE #include <time.h>
int
getdate_r( |
const char * | string, |
struct tm * | res) ; |
The function getdate
()
converts a string pointed to by string
into the tm structure that it returns. This
tm structure may be found in
static storage, so that it will be overwritten by the next
call.
In contrast to strptime(3), (which has a
format
argument),
getdate
() uses the formats
found in the file of which the full pathname is given in the
environment variable DATEMSK
.
The first line in the file that matches the given input
string is used for the conversion.
The matching is done case insensitively. Superfluous whitespace, either in the pattern or in the string to be converted, is ignored.
The conversion specifications that a pattern can contain are those given for strptime(3). One more conversion specification is accepted:
Timezone name.
When %Z
is
given, the value to be returned is initialized to the
broken-down time corresponding to the current time in the
given time zone. Otherwise, it is initialized to the
broken-down time corresponding to the current local time.
When only the weekday is given, the day is taken to be the first such day on or after today.
When only the month is given (and no year), the month is taken to be the first such month equal to or after the current month. If no day is given, it is the first day of the month.
When no hour, minute and second are given, the current hour, minute and second are taken.
If no date is given, but we know the hour, then that hour is taken to be the first such hour equal to or after the current hour.
When successful, this function returns a pointer to a
struct tm. Otherwise,
it returns NULL and sets the global variable getdate_err
. Changes to errno
are unspecified. The following values
for getdate_err
are defined:
The DATEMSK
environment variable is null or undefined.
The template file cannot be opened for reading.
Failed to get file status information.
The template file is not a regular file.
An error is encountered while reading the template file.
Memory allocation failed (not enough memory available).
There is no line in the file that matches the input.
Invalid input specification.
Since getdate
() is not
reentrant because of the use of getdate_err
and the static buffer to return
the result in, glibc provides a thread-safe variant. The
functionality is the same. The result is returned in the
buffer pointed to by res
and in case of an error the
return value is nonzero with the same values as given above
for getdate_err
.
The POSIX.1-2001 specification for strptime(3) contains
conversion specifications using the %E
or %O
modifier, while such
specifications are not given for getdate
(). The glibc implementation
implements getdate
() using
strptime(3) so that
automatically precisely the same conversions are supported by
both.
The glibc implementation does not support the %Z
conversion
specification.
This page is part of release 2.79 of the Linux man-pages
project. A
description of the project, and information about reporting
bugs, can be found at
http://www.kernel.org/doc/man-pages/.
Copyright 2001 walter harms (walter.harmsinformatik.uni-oldenburg.de) Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Since the Linux kernel and libraries are constantly changing, this manual page may be incorrect or out-of-date. The author(s) assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. The author(s) may not have taken the same level of care in the production of this manual, which is licensed free of charge, as they might when working professionally. Formatted or processed versions of this manual, if unaccompanied by the source, must acknowledge the copyright and authors of this work. Modified, 2001-12-26, aeb |