Back to index

glibc  2.9
time.h
Go to the documentation of this file.
00001 /* Copyright (C) 1991-1999,2000,2001,2002,2003,2006
00002        Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 /*
00021  *     ISO C99 Standard: 7.23 Date and time      <time.h>
00022  */
00023 
00024 #ifndef       _TIME_H
00025 
00026 #if (! defined __need_time_t && !defined __need_clock_t && \
00027      ! defined __need_timespec)
00028 # define _TIME_H     1
00029 # include <features.h>
00030 
00031 __BEGIN_DECLS
00032 
00033 #endif
00034 
00035 #ifdef _TIME_H
00036 /* Get size_t and NULL from <stddef.h>.  */
00037 # define __need_size_t
00038 # define __need_NULL
00039 # include <stddef.h>
00040 
00041 /* This defines CLOCKS_PER_SEC, which is the number of processor clock
00042    ticks per second.  */
00043 # include <bits/time.h>
00044 
00045 /* This is the obsolete POSIX.1-1988 name for the same constant.  */
00046 # if !defined __STRICT_ANSI__ && !defined __USE_XOPEN2K
00047 #  ifndef CLK_TCK
00048 #   define CLK_TCK   CLOCKS_PER_SEC
00049 #  endif
00050 # endif
00051 
00052 #endif /* <time.h> included.  */
00053 
00054 #if !defined __clock_t_defined && (defined _TIME_H || defined __need_clock_t)
00055 # define __clock_t_defined  1
00056 
00057 # include <bits/types.h>
00058 
00059 __BEGIN_NAMESPACE_STD
00060 /* Returned by `clock'.  */
00061 typedef __clock_t clock_t;
00062 __END_NAMESPACE_STD
00063 #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
00064 __USING_NAMESPACE_STD(clock_t)
00065 #endif
00066 
00067 #endif /* clock_t not defined and <time.h> or need clock_t.  */
00068 #undef __need_clock_t
00069 
00070 #if !defined __time_t_defined && (defined _TIME_H || defined __need_time_t)
00071 # define __time_t_defined   1
00072 
00073 # include <bits/types.h>
00074 
00075 __BEGIN_NAMESPACE_STD
00076 /* Returned by `time'.  */
00077 typedef __time_t time_t;
00078 __END_NAMESPACE_STD
00079 #if defined __USE_POSIX || defined __USE_MISC || defined __USE_SVID
00080 __USING_NAMESPACE_STD(time_t)
00081 #endif
00082 
00083 #endif /* time_t not defined and <time.h> or need time_t.  */
00084 #undef __need_time_t
00085 
00086 #if !defined __clockid_t_defined && \
00087    ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_clockid_t)
00088 # define __clockid_t_defined       1
00089 
00090 # include <bits/types.h>
00091 
00092 /* Clock ID used in clock and timer functions.  */
00093 typedef __clockid_t clockid_t;
00094 
00095 #endif /* clockid_t not defined and <time.h> or need clockid_t.  */
00096 #undef __clockid_time_t
00097 
00098 #if !defined __timer_t_defined && \
00099     ((defined _TIME_H && defined __USE_POSIX199309) || defined __need_timer_t)
00100 # define __timer_t_defined  1
00101 
00102 # include <bits/types.h>
00103 
00104 /* Timer ID returned by `timer_create'.  */
00105 typedef __timer_t timer_t;
00106 
00107 #endif /* timer_t not defined and <time.h> or need timer_t.  */
00108 #undef __need_timer_t
00109 
00110 
00111 #if !defined __timespec_defined &&                      \
00112     ((defined _TIME_H &&                                \
00113       (defined __USE_POSIX199309 || defined __USE_MISC)) ||    \
00114       defined __need_timespec)
00115 # define __timespec_defined 1
00116 
00117 # include <bits/types.h>    /* This defines __time_t for us.  */
00118 
00119 /* POSIX.1b structure for a time value.  This is like a `struct timeval' but
00120    has nanoseconds instead of microseconds.  */
00121 struct timespec
00122   {
00123     __time_t tv_sec;        /* Seconds.  */
00124     long int tv_nsec;              /* Nanoseconds.  */
00125   };
00126 
00127 #endif /* timespec not defined and <time.h> or need timespec.  */
00128 #undef __need_timespec
00129 
00130 
00131 #ifdef _TIME_H
00132 __BEGIN_NAMESPACE_STD
00133 /* Used by other time functions.  */
00134 struct tm
00135 {
00136   int tm_sec;               /* Seconds.   [0-60] (1 leap second) */
00137   int tm_min;               /* Minutes.   [0-59] */
00138   int tm_hour;                     /* Hours.     [0-23] */
00139   int tm_mday;                     /* Day.              [1-31] */
00140   int tm_mon;               /* Month.     [0-11] */
00141   int tm_year;                     /* Year       - 1900.  */
00142   int tm_wday;                     /* Day of week.      [0-6] */
00143   int tm_yday;                     /* Days in year.[0-365]     */
00144   int tm_isdst;                    /* DST.              [-1/0/1]*/
00145 
00146 #ifdef __USE_BSD
00147   long int tm_gmtoff;              /* Seconds east of UTC.  */
00148   __const char *tm_zone;    /* Timezone abbreviation.  */
00149 #else
00150   long int __tm_gmtoff;            /* Seconds east of UTC.  */
00151   __const char *__tm_zone;  /* Timezone abbreviation.  */
00152 #endif
00153 };
00154 __END_NAMESPACE_STD
00155 #if defined __USE_XOPEN || defined __USE_POSIX || defined __USE_MISC
00156 __USING_NAMESPACE_STD(tm)
00157 #endif
00158 
00159 
00160 #ifdef __USE_POSIX199309
00161 /* POSIX.1b structure for timer start values and intervals.  */
00162 struct itimerspec
00163   {
00164     struct timespec it_interval;
00165     struct timespec it_value;
00166   };
00167 
00168 /* We can use a simple forward declaration.  */
00169 struct sigevent;
00170 
00171 #endif /* POSIX.1b */
00172 
00173 #ifdef __USE_XOPEN2K
00174 # ifndef __pid_t_defined
00175 typedef __pid_t pid_t;
00176 #  define __pid_t_defined
00177 # endif
00178 #endif
00179 
00180 
00181 __BEGIN_NAMESPACE_STD
00182 /* Time used by the program so far (user time + system time).
00183    The result / CLOCKS_PER_SECOND is program time in seconds.  */
00184 extern clock_t clock (void) __THROW;
00185 
00186 /* Return the current time and put it in *TIMER if TIMER is not NULL.  */
00187 extern time_t time (time_t *__timer) __THROW;
00188 
00189 /* Return the difference between TIME1 and TIME0.  */
00190 extern double difftime (time_t __time1, time_t __time0)
00191      __THROW __attribute__ ((__const__));
00192 
00193 /* Return the `time_t' representation of TP and normalize TP.  */
00194 extern time_t mktime (struct tm *__tp) __THROW;
00195 
00196 
00197 /* Format TP into S according to FORMAT.
00198    Write no more than MAXSIZE characters and return the number
00199    of characters written, or 0 if it would exceed MAXSIZE.  */
00200 extern size_t strftime (char *__restrict __s, size_t __maxsize,
00201                      __const char *__restrict __format,
00202                      __const struct tm *__restrict __tp) __THROW;
00203 __END_NAMESPACE_STD
00204 
00205 # ifdef __USE_XOPEN
00206 /* Parse S according to FORMAT and store binary time information in TP.
00207    The return value is a pointer to the first unparsed character in S.  */
00208 extern char *strptime (__const char *__restrict __s,
00209                      __const char *__restrict __fmt, struct tm *__tp)
00210      __THROW;
00211 # endif
00212 
00213 # ifdef __USE_GNU
00214 /* Similar to the two functions above but take the information from
00215    the provided locale and not the global locale.  */
00216 # include <xlocale.h>
00217 
00218 extern size_t strftime_l (char *__restrict __s, size_t __maxsize,
00219                        __const char *__restrict __format,
00220                        __const struct tm *__restrict __tp,
00221                        __locale_t __loc) __THROW;
00222 
00223 extern char *strptime_l (__const char *__restrict __s,
00224                       __const char *__restrict __fmt, struct tm *__tp,
00225                       __locale_t __loc) __THROW;
00226 # endif
00227 
00228 
00229 __BEGIN_NAMESPACE_STD
00230 /* Return the `struct tm' representation of *TIMER
00231    in Universal Coordinated Time (aka Greenwich Mean Time).  */
00232 extern struct tm *gmtime (__const time_t *__timer) __THROW;
00233 
00234 /* Return the `struct tm' representation
00235    of *TIMER in the local timezone.  */
00236 extern struct tm *localtime (__const time_t *__timer) __THROW;
00237 __END_NAMESPACE_STD
00238 
00239 # if defined __USE_POSIX || defined __USE_MISC
00240 /* Return the `struct tm' representation of *TIMER in UTC,
00241    using *TP to store the result.  */
00242 extern struct tm *gmtime_r (__const time_t *__restrict __timer,
00243                          struct tm *__restrict __tp) __THROW;
00244 
00245 /* Return the `struct tm' representation of *TIMER in local time,
00246    using *TP to store the result.  */
00247 extern struct tm *localtime_r (__const time_t *__restrict __timer,
00248                             struct tm *__restrict __tp) __THROW;
00249 # endif       /* POSIX or misc */
00250 
00251 __BEGIN_NAMESPACE_STD
00252 /* Return a string of the form "Day Mon dd hh:mm:ss yyyy\n"
00253    that is the representation of TP in this format.  */
00254 extern char *asctime (__const struct tm *__tp) __THROW;
00255 
00256 /* Equivalent to `asctime (localtime (timer))'.  */
00257 extern char *ctime (__const time_t *__timer) __THROW;
00258 __END_NAMESPACE_STD
00259 
00260 # if defined __USE_POSIX || defined __USE_MISC
00261 /* Reentrant versions of the above functions.  */
00262 
00263 /* Return in BUF a string of the form "Day Mon dd hh:mm:ss yyyy\n"
00264    that is the representation of TP in this format.  */
00265 extern char *asctime_r (__const struct tm *__restrict __tp,
00266                      char *__restrict __buf) __THROW;
00267 
00268 /* Equivalent to `asctime_r (localtime_r (timer, *TMP*), buf)'.  */
00269 extern char *ctime_r (__const time_t *__restrict __timer,
00270                     char *__restrict __buf) __THROW;
00271 # endif       /* POSIX or misc */
00272 
00273 
00274 /* Defined in localtime.c.  */
00275 extern char *__tzname[2];   /* Current timezone names.  */
00276 extern int __daylight;             /* If daylight-saving time is ever in use.  */
00277 extern long int __timezone; /* Seconds west of UTC.  */
00278 
00279 
00280 # ifdef       __USE_POSIX
00281 /* Same as above.  */
00282 extern char *tzname[2];
00283 
00284 /* Set time conversion information from the TZ environment variable.
00285    If TZ is not defined, a locale-dependent default is used.  */
00286 extern void tzset (void) __THROW;
00287 # endif
00288 
00289 # if defined __USE_SVID || defined __USE_XOPEN
00290 extern int daylight;
00291 extern long int timezone;
00292 # endif
00293 
00294 # ifdef __USE_SVID
00295 /* Set the system time to *WHEN.
00296    This call is restricted to the superuser.  */
00297 extern int stime (__const time_t *__when) __THROW;
00298 # endif
00299 
00300 
00301 /* Nonzero if YEAR is a leap year (every 4 years,
00302    except every 100th isn't, and every 400th is).  */
00303 # define __isleap(year)     \
00304   ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
00305 
00306 
00307 # ifdef __USE_MISC
00308 /* Miscellaneous functions many Unices inherited from the public domain
00309    localtime package.  These are included only for compatibility.  */
00310 
00311 /* Like `mktime', but for TP represents Universal Time, not local time.  */
00312 extern time_t timegm (struct tm *__tp) __THROW;
00313 
00314 /* Another name for `mktime'.  */
00315 extern time_t timelocal (struct tm *__tp) __THROW;
00316 
00317 /* Return the number of days in YEAR.  */
00318 extern int dysize (int __year) __THROW  __attribute__ ((__const__));
00319 # endif
00320 
00321 
00322 # ifdef __USE_POSIX199309
00323 /* Pause execution for a number of nanoseconds.
00324 
00325    This function is a cancellation point and therefore not marked with
00326    __THROW.  */
00327 extern int nanosleep (__const struct timespec *__requested_time,
00328                     struct timespec *__remaining);
00329 
00330 
00331 /* Get resolution of clock CLOCK_ID.  */
00332 extern int clock_getres (clockid_t __clock_id, struct timespec *__res) __THROW;
00333 
00334 /* Get current value of clock CLOCK_ID and store it in TP.  */
00335 extern int clock_gettime (clockid_t __clock_id, struct timespec *__tp) __THROW;
00336 
00337 /* Set clock CLOCK_ID to value TP.  */
00338 extern int clock_settime (clockid_t __clock_id, __const struct timespec *__tp)
00339      __THROW;
00340 
00341 #  ifdef __USE_XOPEN2K
00342 /* High-resolution sleep with the specified clock.
00343 
00344    This function is a cancellation point and therefore not marked with
00345    __THROW.  */
00346 extern int clock_nanosleep (clockid_t __clock_id, int __flags,
00347                          __const struct timespec *__req,
00348                          struct timespec *__rem);
00349 
00350 /* Return clock ID for CPU-time clock.  */
00351 extern int clock_getcpuclockid (pid_t __pid, clockid_t *__clock_id) __THROW;
00352 #  endif
00353 
00354 
00355 /* Create new per-process timer using CLOCK_ID.  */
00356 extern int timer_create (clockid_t __clock_id,
00357                       struct sigevent *__restrict __evp,
00358                       timer_t *__restrict __timerid) __THROW;
00359 
00360 /* Delete timer TIMERID.  */
00361 extern int timer_delete (timer_t __timerid) __THROW;
00362 
00363 /* Set timer TIMERID to VALUE, returning old value in OVLAUE.  */
00364 extern int timer_settime (timer_t __timerid, int __flags,
00365                        __const struct itimerspec *__restrict __value,
00366                        struct itimerspec *__restrict __ovalue) __THROW;
00367 
00368 /* Get current value of timer TIMERID and store it in VLAUE.  */
00369 extern int timer_gettime (timer_t __timerid, struct itimerspec *__value)
00370      __THROW;
00371 
00372 /* Get expiration overrun for timer TIMERID.  */
00373 extern int timer_getoverrun (timer_t __timerid) __THROW;
00374 # endif
00375 
00376 
00377 # ifdef __USE_XOPEN_EXTENDED
00378 /* Set to one of the following values to indicate an error.
00379      1  the DATEMSK environment variable is null or undefined,
00380      2  the template file cannot be opened for reading,
00381      3  failed to get file status information,
00382      4  the template file is not a regular file,
00383      5  an error is encountered while reading the template file,
00384      6  memory allication failed (not enough memory available),
00385      7  there is no line in the template that matches the input,
00386      8  invalid input specification Example: February 31 or a time is
00387         specified that can not be represented in a time_t (representing
00388        the time in seconds since 00:00:00 UTC, January 1, 1970) */
00389 extern int getdate_err;
00390 
00391 /* Parse the given string as a date specification and return a value
00392    representing the value.  The templates from the file identified by
00393    the environment variable DATEMSK are used.  In case of an error
00394    `getdate_err' is set.
00395 
00396    This function is a possible cancellation points and therefore not
00397    marked with __THROW.  */
00398 extern struct tm *getdate (__const char *__string);
00399 # endif
00400 
00401 # ifdef __USE_GNU
00402 /* Since `getdate' is not reentrant because of the use of `getdate_err'
00403    and the static buffer to return the result in, we provide a thread-safe
00404    variant.  The functionality is the same.  The result is returned in
00405    the buffer pointed to by RESBUFP and in case of an error the return
00406    value is != 0 with the same values as given above for `getdate_err'.
00407 
00408    This function is not part of POSIX and therefore no official
00409    cancellation point.  But due to similarity with an POSIX interface
00410    or due to the implementation it is a cancellation point and
00411    therefore not marked with __THROW.  */
00412 extern int getdate_r (__const char *__restrict __string,
00413                     struct tm *__restrict __resbufp);
00414 # endif
00415 
00416 __END_DECLS
00417 
00418 #endif /* <time.h> included.  */
00419 
00420 #endif /* <time.h> not already included.  */