/*
 * $Id: time.h,v 1.9 2000/10/27 04:05:31 k-abe Exp $
 *
 * This file is part of PTL, Portable Thread Library.
 *
 * Copyright (C) 1997-2000 Kota Abe
 *
 */

#ifndef __PTHREAD_TIME_H__
#define __PTHREAD_TIME_H__

#include <sys/pthread-init.h>

/* ---------------------------------------------------------------- */
#ifdef __PTL_RENAMED__
#define __PTL_ALREADY_RENAMED_TIME_H
#else
#include <sys/pthread-before.h>
#endif

#ifdef linux
# define __need_timespec
#endif

#ifdef __GNUC__
#include <00root-gcc/time.h>
#else
#include <00root-system/time.h>
#endif

#include <sys/pthread-after.h>
/* ---------------------------------------------------------------- */

#include <sys/pthread-cdecl.h>

/* FreeBSD2.2 declares struct timespec in <sys/time.h> */
#include <sys/time.h>

/* clockid_t */
#include <sys/types.h>

#if !defined(HAVE_TIMESPEC) && !defined(_PTL_TIMESPEC)
#define _PTL_TIMESPEC
struct timespec {
    time_t      tv_sec;			/* Seconds */
    long        tv_nsec;		/* Nanoseconds */
};
#endif

#if !defined(HAVE_CLOCKID_T) && !defined(_PTL_CLOCKID_T)
#define _PTL_CLOCKID_T
/* Used for clock ID type in the clock and timer functions */
typedef int	clockid_t;
#endif

/****************************************************************
 *
 *	14.1.3  Manifest Constants
 *
 ****************************************************************/

#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME	0
#endif

/****************************************************************
 *
 *	14.2.1  Clocks
 *
 ****************************************************************/

__PTL_BEGIN_DECLS

extern int clock_gettime __PTL_P((clockid_t, struct timespec*));

/****************************************************************
 *
 *	14.2.5  High Resolution Sleep
 *
 ****************************************************************/

extern int _pthread_nanosleep __PTL_P((const struct timespec*,
				       struct timespec*,
				       const char*, const char*, int));
extern int (nanosleep) __PTL_P((const struct timespec*, struct timespec*));

/* Reentrant functions */
#ifndef HAVE_LOCALTIME_R
extern struct tm *localtime_r __PTL_P((const time_t*, struct tm*));
#endif
#ifndef HAVE_GMTIME_R
extern struct tm *gmtime_r __PTL_P((const time_t*, struct tm*));
#endif
#ifndef HAVE_ASCTIME_R
extern char	*asctime_r __PTL_P((const struct tm*, char*));
#endif
#ifndef HAVE_CTIME_R
extern char	*ctime_r __PTL_P((const time_t*, char*));
#endif

__PTL_END_DECLS

/* ---------------------------------------------------------------- */
#ifdef __PTL_ALREADY_RENAMED_TIME_H
#include <sys/pthread-before.h>
#undef __PTL_ALREADY_RENAMED_TIME_H
#else
#include <sys/pthread-after.h>
#endif
/* ---------------------------------------------------------------- */

#endif /* __PTHREAD_TIME_H__ */
