Serenity Operating System
at hosted 88 lines 3.1 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include <sys/cdefs.h> 30#include <sys/types.h> 31 32__BEGIN_DECLS 33 34struct tm { 35 int tm_sec; /* Seconds (0-60) */ 36 int tm_min; /* Minutes (0-59) */ 37 int tm_hour; /* Hours (0-23) */ 38 int tm_mday; /* Day of the month (1-31) */ 39 int tm_mon; /* Month (0-11) */ 40 int tm_year; /* Year - 1900 */ 41 int tm_wday; /* Day of the week (0-6, Sunday = 0) */ 42 int tm_yday; /* Day in the year (0-365, 1 Jan = 0) */ 43 int tm_isdst; /* Daylight saving time */ 44}; 45 46extern long timezone; /* The difference in seconds between UTC and local time */ 47extern long altzone; 48extern char* tzname[2]; 49extern int daylight; 50 51typedef uint32_t clock_t; 52typedef int64_t time_t; 53 54struct tm* localtime(const time_t*); 55struct tm* gmtime(const time_t*); 56time_t mktime(struct tm*); 57time_t time(time_t*); 58char* ctime(const time_t*); 59void tzset(); 60char* asctime(const struct tm*); 61 62#define CLOCKS_PER_SEC 1000 63clock_t clock(); 64 65struct timespec { 66 time_t tv_sec; 67 long tv_nsec; 68}; 69 70typedef int clockid_t; 71 72#define CLOCK_REALTIME 0 73#define CLOCK_MONOTONIC 1 74#define TIMER_ABSTIME 99 75 76int clock_gettime(clockid_t, struct timespec*); 77int clock_settime(clockid_t, struct timespec*); 78int clock_nanosleep(clockid_t, int flags, const struct timespec* requested_sleep, struct timespec* remaining_sleep); 79int clock_getres(clockid_t, struct timespec* result); 80struct tm* gmtime_r(const time_t* timep, struct tm* result); 81struct tm* localtime_r(const time_t* timep, struct tm* result); 82 83double difftime(time_t, time_t); 84size_t strftime(char* s, size_t max, const char* format, const struct tm*); 85 86#define difftime(t1, t0) (double)(t1 - t0) 87 88__END_DECLS