Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
epidemian
GitHub Repository: epidemian/gravity
Path: blob/master/src/utils/gravity_utils.h
1214 views
1
//
2
// gravity_utils.h
3
// gravity
4
//
5
// Created by Marco Bambini on 29/08/14.
6
// Copyright (c) 2014 CreoLabs. All rights reserved.
7
//
8
9
#ifndef __GRAVITY_UTILS__
10
#define __GRAVITY_UTILS__
11
12
#include <stdint.h>
13
#include <stdbool.h>
14
15
#if defined(_WIN32)
16
typedef unsigned _int64 nanotime_t;
17
#define DIRREF HANDLE
18
#else
19
#include <dirent.h>
20
typedef uint64_t nanotime_t;
21
#define DIRREF DIR*
22
#endif
23
24
// TIMER
25
nanotime_t nanotime (void);
26
double microtime (nanotime_t tstart, nanotime_t tend);
27
double millitime (nanotime_t tstart, nanotime_t tend);
28
29
// FILE
30
uint64_t file_size (const char *path);
31
const char *file_read (const char *path, size_t *len);
32
bool file_exists (const char *path);
33
const char *file_buildpath (const char *filename, const char *dirpath);
34
bool file_write (const char *path, const char *buffer, size_t len);
35
36
// DIRECTORY
37
bool is_directory (const char *path);
38
DIRREF directory_init (const char *path);
39
const char *directory_read (DIRREF ref);
40
41
// STRING
42
int string_nocasencmp (const char *s1, const char *s2, size_t n);
43
int string_casencmp (const char *s1, const char *s2, size_t n);
44
int string_cmp (const char *s1, const char *s2);
45
const char *string_dup (const char *s1);
46
const char *string_ndup (const char *s1, size_t n);
47
char *string_unescape (const char *s1, uint32_t *s1len, char *buffer);
48
void string_reverse (char *p);
49
uint32_t string_size (const char *p);
50
51
// UTF-8
52
uint32_t utf8_charbytes (const char *s, uint32_t i);
53
uint32_t utf8_len (const char *s, uint32_t nbytes);
54
void utf8_reverse (char *p);
55
56
// MATH and NUMBERS
57
uint32_t power_of2_ceil (uint32_t n);
58
int64_t number_from_hex (const char *s, uint32_t len);
59
int64_t number_from_oct (const char *s, uint32_t len);
60
int64_t number_from_bin (const char *s, uint32_t len);
61
62
#endif
63
64