/usr/include/time.h


    1 /*	Copyright (c) 1988 AT&T	*/
    2 /*	  All Rights Reserved  	*/
    3 
    4 /*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
    5 /*	The copyright notice above does not evidence any   	*/
    6 /*	actual or intended publication of such source code.	*/
    7 
    8 /*
    9  *	Copyright (c) 1993-1999 by Sun Microsystems, Inc.
   10  *	All rights reserved.
   11  */
   12 
   13 #ifndef _TIME_H
   14 #define	_TIME_H
   15 
   16 #pragma ident	"@(#)time.h	1.39	99/08/10 SMI"	/* SVr4.0 1.18 */
   17 
   18 #include <sys/feature_tests.h>
   19 #include <sys/types.h>
   20 #include <iso/time_iso.h>
   21 
   22 /*
   23  * Allow global visibility for symbols defined in
   24  * C++ "std" namespace in <iso/time_iso.h>.
   25  */
   26 #if __cplusplus >= 199711L
   27 using std::size_t;
   28 using std::clock_t;
   29 using std::time_t;
   30 using std::tm;
   31 using std::asctime;
   32 using std::clock;
   33 using std::ctime;
   34 using std::difftime;
   35 using std::gmtime;
   36 using std::localtime;
   37 using std::mktime;
   38 using std::time;
   39 using std::strftime;
   40 #endif
   41 
   42 #ifdef	__cplusplus
   43 extern "C" {
   44 #endif
   45 
   46 #ifndef _CLOCKID_T
   47 #define	_CLOCKID_T
   48 typedef int	clockid_t;
   49 #endif
   50 
   51 #ifndef _TIMER_T
   52 #define	_TIMER_T
   53 typedef int	timer_t;
   54 #endif
   55 
   56 #if defined(__STDC__)
   57 
   58 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
   59 	    (_POSIX_C_SOURCE - 0 >= 199506L)
   60 extern struct tm *gmtime_r(const time_t *, struct tm *);
   61 extern struct tm *localtime_r(const time_t *, struct tm *);
   62 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT) .. */
   63 
   64 #if (__STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
   65 	(defined(_XOPEN_SOURCE) && _XOPEN_VERSION - 0 >= 4) || \
   66 	defined(__EXTENSIONS__)
   67 extern char *strptime(const char *, const char *, struct tm *);
   68 
   69 #ifdef _STRPTIME_DONTZERO
   70 #ifdef __PRAGMA_REDEFINE_EXTNAME
   71 #pragma	redefine_extname strptime __strptime_dontzero
   72 #else	/* __PRAGMA_REDEFINE_EXTNAME */
   73 extern char *__strptime_dontzero(const char *, const char *, struct tm *);
   74 #define	strptime	__strptime_dontzero
   75 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
   76 #endif	/* _STRPTIME_DONTZERO */
   77 
   78 #endif /* (__STDC__ == 0 && !defined(_POSIX_C_SOURCE)... */
   79 
   80 #if defined(__EXTENSIONS__) || ((__STDC__ - 0 == 0) && \
   81 	!defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
   82 	(_POSIX_C_SOURCE > 2)
   83 #include <sys/time_impl.h>
   84 
   85 /*
   86  * Neither X/Open nor POSIX allow the inclusion of <signal.h> for the
   87  * definition of the sigevent structure.  Both require the inclusion
   88  * of <signal.h> and <time.h> when using the timer_create() function.
   89  * However, X/Open also specifies that the sigevent structure be defined
   90  * in <time.h> as described in the header <signal.h>.  This prevents
   91  * compiler warnings for applications that only include <time.h> and not
   92  * also <signal.h>.  The sigval union and the sigevent structure is
   93  * therefore defined both here and in <sys/siginfo.h> which gets included
   94  * via inclusion of <signal.h>.
   95  */
   96 #ifndef	_SIGVAL
   97 #define	_SIGVAL
   98 union sigval {
   99 	int	sival_int;	/* integer value */
  100 	void	*sival_ptr;	/* pointer value */
  101 };
  102 #endif	/* _SIGVAL */
  103 
  104 #ifndef	_SIGEVENT
  105 #define	_SIGEVENT
  106 struct sigevent {
  107 	int		sigev_notify;	/* notification mode */
  108 	int		sigev_signo;	/* signal number */
  109 	union sigval	sigev_value;	/* signal value */
  110 	void		(*sigev_notify_function)(union sigval);
  111 	pthread_attr_t	*sigev_notify_attributes;
  112 	int		__sigev_pad2;
  113 };
  114 #endif	/* _SIGEVENT */
  115 
  116 extern int clock_getres(clockid_t, struct timespec *);
  117 extern int clock_gettime(clockid_t, struct timespec *);
  118 extern int clock_settime(clockid_t, const struct timespec *);
  119 extern int timer_create(clockid_t, struct sigevent *, timer_t *);
  120 extern int timer_delete(timer_t);
  121 extern int timer_getoverrun(timer_t);
  122 extern int timer_gettime(timer_t, struct itimerspec *);
  123 extern int timer_settime(timer_t, int, const struct itimerspec *,
  124 		struct itimerspec *);
  125 extern int nanosleep(const struct timespec *, struct timespec *);
  126 #endif /* defined(__EXTENSIONS__) || ((__STDC__ - 0 == 0 && ... */
  127 
  128 #if defined(__EXTENSIONS__) || __STDC__ == 0 || \
  129 		defined(_POSIX_C_SOURCE) || defined(_XOPEN_SOURCE)
  130 extern void tzset(void);
  131 
  132 extern char *tzname[2];
  133 
  134 #ifndef CLK_TCK
  135 extern long _sysconf(int);	/* System Private interface to sysconf() */
  136 #define	CLK_TCK	((clock_t) _sysconf(3))	/* clock ticks per second */
  137 				/* 3 is _SC_CLK_TCK */
  138 #endif
  139 
  140 #if defined(__EXTENSIONS__) || (__STDC__ == 0 && \
  141 		!defined(_POSIX_C_SOURCE)) || defined(_XOPEN_SOURCE)
  142 extern long timezone;
  143 extern int daylight;
  144 #endif
  145 
  146 #endif
  147 
  148 #if __STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)
  149 extern int cftime(char *, char *, const time_t *);
  150 extern int ascftime(char *, const char *, const struct tm *);
  151 extern long altzone;
  152 #endif
  153 
  154 #if (__STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
  155 	defined(_XPG4_2) || defined(__EXTENSIONS__)
  156 extern struct tm *getdate(const char *);
  157 
  158 #ifdef	_REENTRANT
  159 #undef getdate_err
  160 #define	getdate_err *(int *)_getdate_err_addr()
  161 extern int *_getdate_err_addr(void);
  162 #else
  163 extern int getdate_err;
  164 #endif /* _REENTRANT */
  165 #endif /* __STDC__ == 0 && !defined(_POSIX_C_SOURCE) ... */
  166 
  167 #else /* __STDC__ */
  168 
  169 extern char *strptime();
  170 extern int cftime(), ascftime();
  171 extern void tzset();
  172 
  173 #ifdef _STRPTIME_DONTZERO
  174 #ifdef __PRAGMA_REDEFINE_EXTNAME
  175 #pragma	redefine_extname strptime	__strptime_dontzero
  176 #else	/* __PRAGMA_REDEFINE_EXTNAME */
  177 extern char *__strptime_dontzero();
  178 #define	strptime	__strptime_dontzero
  179 #endif	/* __PRAGMA_REDEFINE_EXTNAME */
  180 #endif	/* _STRPTIME_DONTZERO */
  181 
  182 
  183 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
  184 	    (_POSIX_C_SOURCE - 0 >= 199506L)
  185 extern struct tm *gmtime_r();
  186 extern struct tm *localtime_r();
  187 #endif	/* defined(__EXTENSIONS__) || defined(_REENTRANT) .. */
  188 
  189 extern long timezone, altzone;
  190 extern int daylight;
  191 extern char *tzname[2];
  192 
  193 #if (__STDC__ == 0 && !defined(_POSIX_C_SOURCE) && !defined(_XOPEN_SOURCE)) || \
  194 	defined(_XPG4_2) || defined(__EXTENSIONS__)
  195 extern struct tm *getdate();
  196 #ifdef	_REENTRANT
  197 #undef getdate_err
  198 #define	getdate_err *(int *)_getdate_err_addr()
  199 extern int *_getdate_err_addr();
  200 #else
  201 extern int getdate_err;
  202 #endif /* _REENTRANT */
  203 #endif /* __STDC__ == 0 && !defined(_POSIX_C_SOURCE) ... */
  204 
  205 
  206 #endif	/* __STDC__ */
  207 
  208 /*
  209  * ctime_r() & asctime_r() prototypes are defined here.
  210  */
  211 
  212 /*
  213  * Previous releases of Solaris, starting at 2.3, provided definitions of
  214  * various functions as specified in POSIX.1c, Draft 6.  For some of these
  215  * functions, the final POSIX 1003.1c standard had a different number of
  216  * arguments and return values.
  217  *
  218  * The following segment of this header provides support for the standard
  219  * interfaces while supporting applications written under earlier
  220  * releases.  The application defines appropriate values of the feature
  221  * test macros _POSIX_C_SOURCE and _POSIX_PTHREAD_SEMANTICS to indicate
  222  * whether it was written to expect the Draft 6 or standard versions of
  223  * these interfaces, before including this header.  This header then
  224  * provides a mapping from the source version of the interface to an
  225  * appropriate binary interface.  Such mappings permit an application
  226  * to be built from libraries and objects which have mixed expectations
  227  * of the definitions of these functions.
  228  *
  229  * For applications using the Draft 6 definitions, the binary symbol is
  230  * the same as the source symbol, and no explicit mapping is needed.  For
  231  * the standard interface, the function func() is mapped to the binary
  232  * symbol _posix_func().  The preferred mechanism for the remapping is a
  233  * compiler #pragma.  If the compiler does not provide such a #pragma, the
  234  * header file defines a static function func() which calls the
  235  * _posix_func() version; this is required if the application needs to
  236  * take the address of func().
  237  *
  238  * NOTE: Support for the Draft 6 definitions is provided for compatibility
  239  * only.  New applications/libraries should use the standard definitions.
  240  */
  241 
  242 #if	defined(__EXTENSIONS__) || defined(_REENTRANT) || \
  243 	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
  244 
  245 #if	defined(__STDC__)
  246 
  247 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
  248 
  249 #ifdef __PRAGMA_REDEFINE_EXTNAME
  250 extern char *asctime_r(const struct tm *, char *);
  251 extern char *ctime_r(const time_t *, char *);
  252 #pragma redefine_extname ctime_r __posix_ctime_r
  253 #pragma redefine_extname asctime_r __posix_asctime_r
  254 #else  /* __PRAGMA_REDEFINE_EXTNAME */
  255 
  256 static char *
  257 asctime_r(const struct tm *__tm, char *__buf)
  258 {
  259 	extern char *__posix_asctime_r(const struct tm *, char *);
  260 	return (__posix_asctime_r(__tm, __buf));
  261 }
  262 static char *
  263 ctime_r(const time_t *__time, char *__buf)
  264 {
  265 	extern char *__posix_ctime_r(const time_t *, char *);
  266 	return (__posix_ctime_r(__time, __buf));
  267 }
  268 #endif /* __PRAGMA_REDEFINE_EXTNAME */
  269 
  270 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
  271 
  272 extern char *asctime_r(const struct tm *, char *, int);
  273 extern char *ctime_r(const time_t *, char *, int);
  274 
  275 #endif  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
  276 
  277 #else  /* __STDC__ */
  278 
  279 #if	(_POSIX_C_SOURCE - 0 >= 199506L) || defined(_POSIX_PTHREAD_SEMANTICS)
  280 
  281 #ifdef __PRAGMA_REDEFINE_EXTNAME
  282 extern char *asctime_r();
  283 extern char *ctime_r();
  284 #pragma redefine_extname asctime_r __posix_asctime_r
  285 #pragma redefine_extname ctime_r __posix_ctime_r
  286 #else  /* __PRAGMA_REDEFINE_EXTNAME */
  287 
  288 static char *
  289 asctime_r(__tm, __buf)
  290 	struct tm *__tm;
  291 	char *__buf;
  292 {
  293 	extern char *__posix_asctime_r();
  294 	return (__posix_asctime_r(__tm, __buf));
  295 }
  296 static char *
  297 ctime_r(__time, __buf)
  298 	time_t *__time;
  299 	char *__buf;
  300 {
  301 	extern char *__posix_ctime_r();
  302 	return (__posix_ctime_r(__time, __buf));
  303 }
  304 #endif /* __PRAGMA_REDEFINE_EXTNAME */
  305 
  306 #else  /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
  307 
  308 extern char *asctime_r();
  309 extern char *ctime_r();
  310 
  311 #endif /* (_POSIX_C_SOURCE - 0 >= 199506L) || ... */
  312 
  313 #endif /* __STDC__ */
  314 
  315 #endif /* defined(__EXTENSIONS__) || (__STDC__ == 0 ... */
  316 
  317 #ifdef	__cplusplus
  318 }
  319 #endif
  320 
  321 #endif	/* _TIME_H */