|
Packit |
6c4009 |
/* Copyright (C) 1991-2018 Free Software Foundation, Inc.
|
|
Packit |
6c4009 |
This file is part of the GNU C Library.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is free software; you can redistribute it and/or
|
|
Packit |
6c4009 |
modify it under the terms of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License as published by the Free Software Foundation; either
|
|
Packit |
6c4009 |
version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
The GNU C Library is distributed in the hope that it will be useful,
|
|
Packit |
6c4009 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
6c4009 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
6c4009 |
Lesser General Public License for more details.
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
You should have received a copy of the GNU Lesser General Public
|
|
Packit |
6c4009 |
License along with the GNU C Library; if not, see
|
|
Packit |
6c4009 |
<http://www.gnu.org/licenses/>. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef _SYS_TIME_H
|
|
Packit |
6c4009 |
#define _SYS_TIME_H 1
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <features.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <bits/types.h>
|
|
Packit |
6c4009 |
#include <bits/types/time_t.h>
|
|
Packit |
6c4009 |
#include <bits/types/struct_timeval.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifndef __suseconds_t_defined
|
|
Packit |
6c4009 |
typedef __suseconds_t suseconds_t;
|
|
Packit |
6c4009 |
# define __suseconds_t_defined
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#include <sys/select.h>
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__BEGIN_DECLS
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_GNU
|
|
Packit |
6c4009 |
/* Macros for converting between `struct timeval' and `struct timespec'. */
|
|
Packit |
6c4009 |
# define TIMEVAL_TO_TIMESPEC(tv, ts) { \
|
|
Packit |
6c4009 |
(ts)->tv_sec = (tv)->tv_sec; \
|
|
Packit |
6c4009 |
(ts)->tv_nsec = (tv)->tv_usec * 1000; \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
# define TIMESPEC_TO_TIMEVAL(tv, ts) { \
|
|
Packit |
6c4009 |
(tv)->tv_sec = (ts)->tv_sec; \
|
|
Packit |
6c4009 |
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
|
|
Packit |
6c4009 |
}
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_MISC
|
|
Packit |
6c4009 |
/* Structure crudely representing a timezone.
|
|
Packit |
6c4009 |
This is obsolete and should never be used. */
|
|
Packit |
6c4009 |
struct timezone
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
int tz_minuteswest; /* Minutes west of GMT. */
|
|
Packit |
6c4009 |
int tz_dsttime; /* Nonzero if DST is ever in effect. */
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
typedef struct timezone *__restrict __timezone_ptr_t;
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
typedef void *__restrict __timezone_ptr_t;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Get the current time of day and timezone information,
|
|
Packit |
6c4009 |
putting it into *TV and *TZ. If TZ is NULL, *TZ is not filled.
|
|
Packit |
6c4009 |
Returns 0 on success, -1 on errors.
|
|
Packit |
6c4009 |
NOTE: This form of timezone information is obsolete.
|
|
Packit |
6c4009 |
Use the functions and variables declared in <time.h> instead. */
|
|
Packit |
6c4009 |
extern int gettimeofday (struct timeval *__restrict __tv,
|
|
Packit |
6c4009 |
__timezone_ptr_t __tz) __THROW __nonnull ((1));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_MISC
|
|
Packit |
6c4009 |
/* Set the current time of day and timezone information.
|
|
Packit |
6c4009 |
This call is restricted to the super-user. */
|
|
Packit |
6c4009 |
extern int settimeofday (const struct timeval *__tv,
|
|
Packit |
6c4009 |
const struct timezone *__tz)
|
|
Packit |
6c4009 |
__THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Adjust the current time of day by the amount in DELTA.
|
|
Packit |
6c4009 |
If OLDDELTA is not NULL, it is filled in with the amount
|
|
Packit |
6c4009 |
of time adjustment remaining to be done from the last `adjtime' call.
|
|
Packit |
6c4009 |
This call is restricted to the super-user. */
|
|
Packit |
6c4009 |
extern int adjtime (const struct timeval *__delta,
|
|
Packit |
6c4009 |
struct timeval *__olddelta) __THROW;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Values for the first argument to `getitimer' and `setitimer'. */
|
|
Packit |
6c4009 |
enum __itimer_which
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Timers run in real time. */
|
|
Packit |
6c4009 |
ITIMER_REAL = 0,
|
|
Packit |
6c4009 |
#define ITIMER_REAL ITIMER_REAL
|
|
Packit |
6c4009 |
/* Timers run only when the process is executing. */
|
|
Packit |
6c4009 |
ITIMER_VIRTUAL = 1,
|
|
Packit |
6c4009 |
#define ITIMER_VIRTUAL ITIMER_VIRTUAL
|
|
Packit |
6c4009 |
/* Timers run when the process is executing and when
|
|
Packit |
6c4009 |
the system is executing on behalf of the process. */
|
|
Packit |
6c4009 |
ITIMER_PROF = 2
|
|
Packit |
6c4009 |
#define ITIMER_PROF ITIMER_PROF
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Type of the second argument to `getitimer' and
|
|
Packit |
6c4009 |
the second and third arguments `setitimer'. */
|
|
Packit |
6c4009 |
struct itimerval
|
|
Packit |
6c4009 |
{
|
|
Packit |
6c4009 |
/* Value to put into `it_value' when the timer expires. */
|
|
Packit |
6c4009 |
struct timeval it_interval;
|
|
Packit |
6c4009 |
/* Time to the next timer expiration. */
|
|
Packit |
6c4009 |
struct timeval it_value;
|
|
Packit |
6c4009 |
};
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#if defined __USE_GNU && !defined __cplusplus
|
|
Packit |
6c4009 |
/* Use the nicer parameter type only in GNU mode and not for C++ since the
|
|
Packit |
6c4009 |
strict C++ rules prevent the automatic promotion. */
|
|
Packit |
6c4009 |
typedef enum __itimer_which __itimer_which_t;
|
|
Packit |
6c4009 |
#else
|
|
Packit |
6c4009 |
typedef int __itimer_which_t;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set *VALUE to the current setting of timer WHICH.
|
|
Packit |
6c4009 |
Return 0 on success, -1 on errors. */
|
|
Packit |
6c4009 |
extern int getitimer (__itimer_which_t __which,
|
|
Packit |
6c4009 |
struct itimerval *__value) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Set the timer WHICH to *NEW. If OLD is not NULL,
|
|
Packit |
6c4009 |
set *OLD to the old value of timer WHICH.
|
|
Packit |
6c4009 |
Returns 0 on success, -1 on errors. */
|
|
Packit |
6c4009 |
extern int setitimer (__itimer_which_t __which,
|
|
Packit |
6c4009 |
const struct itimerval *__restrict __new,
|
|
Packit |
6c4009 |
struct itimerval *__restrict __old) __THROW;
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Change the access time of FILE to TVP[0] and the modification time of
|
|
Packit |
6c4009 |
FILE to TVP[1]. If TVP is a null pointer, use the current time instead.
|
|
Packit |
6c4009 |
Returns 0 on success, -1 on errors. */
|
|
Packit |
6c4009 |
extern int utimes (const char *__file, const struct timeval __tvp[2])
|
|
Packit |
6c4009 |
__THROW __nonnull ((1));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_MISC
|
|
Packit |
6c4009 |
/* Same as `utimes', but does not follow symbolic links. */
|
|
Packit |
6c4009 |
extern int lutimes (const char *__file, const struct timeval __tvp[2])
|
|
Packit |
6c4009 |
__THROW __nonnull ((1));
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
/* Same as `utimes', but takes an open file descriptor instead of a name. */
|
|
Packit |
6c4009 |
extern int futimes (int __fd, const struct timeval __tvp[2]) __THROW;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_GNU
|
|
Packit |
6c4009 |
/* Change the access time of FILE relative to FD to TVP[0] and the
|
|
Packit |
6c4009 |
modification time of FILE to TVP[1]. If TVP is a null pointer, use
|
|
Packit |
6c4009 |
the current time instead. Returns 0 on success, -1 on errors. */
|
|
Packit |
6c4009 |
extern int futimesat (int __fd, const char *__file,
|
|
Packit |
6c4009 |
const struct timeval __tvp[2]) __THROW;
|
|
Packit |
6c4009 |
#endif
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#ifdef __USE_MISC
|
|
Packit |
6c4009 |
/* Convenience macros for operations on timevals.
|
|
Packit |
6c4009 |
NOTE: `timercmp' does not work for >= or <=. */
|
|
Packit |
6c4009 |
# define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
|
Packit |
6c4009 |
# define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
|
|
Packit |
6c4009 |
# define timercmp(a, b, CMP) \
|
|
Packit |
6c4009 |
(((a)->tv_sec == (b)->tv_sec) ? \
|
|
Packit |
6c4009 |
((a)->tv_usec CMP (b)->tv_usec) : \
|
|
Packit |
6c4009 |
((a)->tv_sec CMP (b)->tv_sec))
|
|
Packit |
6c4009 |
# define timeradd(a, b, result) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
(result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \
|
|
Packit |
6c4009 |
(result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \
|
|
Packit |
6c4009 |
if ((result)->tv_usec >= 1000000) \
|
|
Packit |
6c4009 |
{ \
|
|
Packit |
6c4009 |
++(result)->tv_sec; \
|
|
Packit |
6c4009 |
(result)->tv_usec -= 1000000; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
# define timersub(a, b, result) \
|
|
Packit |
6c4009 |
do { \
|
|
Packit |
6c4009 |
(result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \
|
|
Packit |
6c4009 |
(result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \
|
|
Packit |
6c4009 |
if ((result)->tv_usec < 0) { \
|
|
Packit |
6c4009 |
--(result)->tv_sec; \
|
|
Packit |
6c4009 |
(result)->tv_usec += 1000000; \
|
|
Packit |
6c4009 |
} \
|
|
Packit |
6c4009 |
} while (0)
|
|
Packit |
6c4009 |
#endif /* Misc. */
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
__END_DECLS
|
|
Packit |
6c4009 |
|
|
Packit |
6c4009 |
#endif /* sys/time.h */
|