Files
jsix/src/libraries/libc/time.h
Justin C. Miller 4545256b49 [build] Move headers out of target dirs
The great header shift: It didn't make sense to regenerate headers for
the same module for every target (boot/kernel/user) it appeared in. And
now that core headers are out of src/include, this was going to cause
problems for the new libc changes I've been working on. So I went back
to re-design how module headers work.

Pre-requisites:
- A module's public headers should all be available in one location, not
  tied to target.
- No accidental includes. Another module should not be able to include
  anything (creating an implicit dependency) from a module without
  declaring an explicit dependency.
- Exception to the previous: libc's headers should be available to all,
  at least for the freestanding headers.

New system:
- A new "public_headers" property of module declares all public headers
  that should be available to dependant modules
- All public headers (after possible processing) are installed relative
  to build/include/<module> with the same path as their source
- This also means no "include" dir in modules is necessary. If a header
  should be included as <j6/types.h> then its source should be
  src/libraries/j6/j6/types.h - this caused the most churn as all public
  header sources moved one directory up.
- The "includes" property of a module is local only to that module now,
  it does not create any implicit public interface

Other changes:
- The bonnibel concept of sources changed: instead of sources having
  actions, they themselves are an instance of a (sub)class of Source,
  which provides all the necessary information itself.
- Along with the above, rule names were standardized into <type>.<ext>,
  eg "compile.cpp" or "parse.cog"
- cog and cogflags variables moved from per-target scope to global scope
  in the build files.
- libc gained a more dynamic .module file
2022-02-06 10:18:51 -08:00

106 lines
3.3 KiB
C

#pragma once
/* Date and time <time.h>
This file is part of the Public Domain C Library (PDCLib).
Permission is granted to use, modify, and / or redistribute at will.
*/
#include "j6libc/cpp.h"
#include "j6libc/int.h"
#include "j6libc/null.h"
#include "j6libc/size_t.h"
CPP_CHECK_BEGIN
/* These are defined to be "real types capable of representing types", with
"range and precision of times representable in [them being] implementation-
defined".
As part of struct timespec (see below), time_t is further defined as "a
linear count of seconds", with potentially different semantics from a
"normal" time_t.
For sake of simplicity, we used just that (common) definition of "seconds
since epoch" as integer.
*/
typedef _PDCLIB_time_t time_t;
typedef _PDCLIB_clock_t clock_t;
#define CLOCKS_PER_SEC _PDCLIB_CLOCKS_PER_SEC
#define TIME_UTC _PDCLIB_TIME_UTC
struct timespec
{
time_t tv_sec;
long tv_nsec;
};
struct tm
{
int tm_sec; /* 0-60 */
int tm_min; /* 0-59 */
int tm_hour; /* 0-23 */
int tm_mday; /* 1-31 */
int tm_mon; /* 0-11 */
int tm_year; /* years since 1900 */
int tm_wday; /* 0-6 */
int tm_yday; /* 0-365 */
int tm_isdst; /* >0 DST, 0 no DST, <0 information unavailable */
};
/* Returns the number of "clocks" in processor time since the invocation
of the program. Divide by CLOCKS_PER_SEC to get the value in seconds.
Returns -1 if the value cannot be represented in the return type or is
not available.
*/
clock_t clock( void );
/* Returns the difference between two calendar times in seconds. */
double difftime( time_t time1, time_t time0 );
/* Normalizes the values in the broken-down time pointed to by timeptr.
Returns the calender time specified by the broken-down time.
*/
time_t mktime( struct tm * timeptr );
/* Returns the current calender time. If timer is not a NULL pointer, stores
the current calender time at that address as well.
*/
time_t time( time_t * timer );
/* Sets the interval pointed to by ts to the current calender time, based
on the specified base.
Returns base, if successful, otherwise zero.
*/
int timespec_get( struct timespec * ts, int base );
/* Converts the broken-down time pointed to by timeptr into a string in the
form "Sun Sep 16 01:03:52 1973\n\0".
*/
char * asctime( const struct tm * timeptr );
/* Equivalent to asctime( localtime( timer ) ). */
char * ctime( const time_t * timer );
/* Converts the calender time pointed to by timer into a broken-down time
expressed as UTC.
Returns a pointer to the broken-down time, or a NULL pointer if it
cannot be represented.
*/
struct tm * gmtime( const time_t * timer );
/* Converts the calender time pointed to by timer into a broken-down time
expressed as local time.
Returns a pointer to the broken-down time, or a NULL pointer if if
cannot be represented.
*/
struct tm * localtime( const time_t * timer );
/* Writes the broken-down time pointed to by timeptr into the character
array pointed to by s. The string pointed to by format controls the
exact output. No more than maxsize charactrs will be written.
Returns the number of characters written (excluding the terminating
null character), or zero on failure.
*/
size_t strftime( char * restrict s, size_t maxsize, const char * restrict format, const struct tm * restrict timeptr );
CPP_CHECK_END