crabc 0.7.8

A Rust musl-compatible libc with a dynamic linker
/* Copyright (c) 2026 Meng Zhuo */
/* SPDX-License-Identifier: BSD-3-Clause */

#ifndef _SYS_TIME_H
#define _SYS_TIME_H

#include <time.h>
#include <sys/types.h>
#include <sys/select.h>

#ifdef __cplusplus
extern "C" {
#endif

int gettimeofday(struct timeval *, void *);
int settimeofday(const struct timeval *, const void *);
int utimes(const char *, const struct timeval [2]);
int futimes(int, const struct timeval [2]);
int futimesat(int, const char *, const struct timeval [2]);
int lutimes(const char *, const struct timeval [2]);
int adjtime(const struct timeval *, struct timeval *);

#define ITIMER_REAL    0
#define ITIMER_VIRTUAL 1
#define ITIMER_PROF    2

struct itimerval {
    struct timeval it_interval;
    struct timeval it_value;
};

int getitimer(int, struct itimerval *);
int setitimer(int, const struct itimerval *, struct itimerval *);

struct timezone {
    int tz_minuteswest;
    int tz_dsttime;
};

#define timerisset(t) ((t)->tv_sec || (t)->tv_usec)
#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0)
#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \
    (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec)
#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \
    ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \
    ((a)->tv_usec -= 1000000, (a)->tv_sec++) )
#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \
    ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \
    ((a)->tv_usec += 1000000, (a)->tv_sec--) )
#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \
    (ts)->tv_sec = (tv)->tv_sec, \
    (ts)->tv_nsec = (tv)->tv_usec * 1000, \
    (void)0 )
#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \
    (tv)->tv_sec = (ts)->tv_sec, \
    (tv)->tv_usec = (ts)->tv_nsec / 1000, \
    (void)0 )

#ifdef __cplusplus
}
#endif

#endif