7 n__time_8h
gullradriel edited this page 2026-10-25 10:46:33 +01:00

include/nilorea/n_time.h

Timing utilities. More...

Structures

Name
struct N_TIME
Timing Structure.

Detailed Description

Timing utilities.

Author: Castagnier Mickael

Version: 1.0

Date: 24/03/05

Source code

/*
 * Nilorea Library
 * Copyright (C) 2005-2026 Castagnier Mickael
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * permissions and limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */


#ifndef __TIME_C_IMPLEMENTATION__
#define __TIME_C_IMPLEMENTATION__

#ifdef __cplusplus
extern "C" {
#endif

#include "n_common.h"

#include <time.h>
#include <limits.h>
#include "nilorea/n_windows.h"
#ifndef __windows__
#include <sys/time.h>
#endif


typedef struct N_TIME {
    time_t delta;
#ifdef __windows__
    LARGE_INTEGER freq;
    LARGE_INTEGER startTime;
    LARGE_INTEGER currentTime;
#else
    struct timeval startTime;
    struct timeval currentTime;
#endif
} N_TIME;

#if defined __windows__
void u_sleep(__int64 usec);
#else
void u_sleep(unsigned int usec);
#endif

void PAUSE(void);

int start_HiTimer(N_TIME* timer);

time_t get_usec(N_TIME* timer);

time_t get_msec(N_TIME* timer);

time_t get_sec(N_TIME* timer);

#define N_TIME_HTTP_DATE_LEN 30
#define N_TIME_RFC2822_LEN 32
#define N_TIME_RFC3339_LEN 26

int n_time_http_date(time_t t, char* out, size_t size);

int n_time_parse_http_date(const char* s, size_t len, time_t* t);

int n_time_rfc2822(time_t t, long offset, char* out, size_t size);

int n_time_rfc3339(time_t t, long offset, char* out, size_t size);

int n_time_parse_rfc3339(const char* s, size_t len, time_t* t);


#ifdef __cplusplus
}
#endif

#endif /* #ifndef __COMMON_FOR_C_IMPLEMENTATION__ */