luasandbox  1.4.0
Generic Lua sandbox for dynamic data analysis
util.h
Go to the documentation of this file.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 /** Shared types and structures @file */
8 
9 #ifndef luasandbox_util_util_h_
10 #define luasandbox_util_util_h_
11 
12 #include <stdbool.h>
13 #include <stddef.h>
14 #include <stdint.h>
15 
16 #include "../error.h"
17 
18 #ifdef _WIN32
19 #ifdef luasandboxutil_EXPORTS
20 #define LSB_UTIL_EXPORT __declspec(dllexport)
21 #else
22 #define LSB_UTIL_EXPORT __declspec(dllimport)
23 #endif
24 #else
25 #if __GNUC__ >= 4
26 #define LSB_UTIL_EXPORT __attribute__ ((visibility ("default")))
27 #else
28 #define LSB_UTIL_EXPORT
29 #endif
30 #endif
31 
32 #ifdef __cplusplus
33 extern "C"
34 {
35 #endif
36 
41 
42 /**
43  * Hacker's Delight - Henry S. Warren, Jr. page 48
44  *
45  * @param x
46  *
47  * @return size_t Least power of 2 greater than or equal to x
48  */
49 LSB_UTIL_EXPORT size_t lsb_lp2(unsigned long long x);
50 
51 /**
52  * Read a file into a string
53  *
54  * @param fn Filename to read
55  *
56  * @return char* NULL on failure otherwise a pointer to the file contents (must
57  * be freed by the caller).
58  */
59 LSB_UTIL_EXPORT char* lsb_read_file(const char *fn);
60 
61 /**
62  * Retrieves the highest resolution timer available converted to nanoseconds
63  *
64  * @return unsigned long long
65  */
66 LSB_UTIL_EXPORT unsigned long long lsb_get_time();
67 
68 /**
69  * Retrieves the highest resolution time since Jan 1, 1970 converted to
70  * nanoseconds
71  *
72  * @return unsigned long long (time_ns)
73  */
75 
76 /**
77  * Sets the timezone environment variable for the time conversion functions
78  *
79  * @param tz Timezone string (if NULL uses UTC)
80  *
81  * @return bool True if the environment variable is successfully set
82  */
83 LSB_UTIL_EXPORT bool lsb_set_tz(const char *tz);
84 
85 #ifdef __cplusplus
86 }
87 #endif
88 
89 #endif
LSB_UTIL_EXPORT lsb_err_id LSB_ERR_UTIL_NULL
const char lsb_err_id[]
Definition: error.h:14
LSB_UTIL_EXPORT lsb_err_id LSB_ERR_UTIL_OOM
LSB_UTIL_EXPORT size_t lsb_lp2(unsigned long long x)
Hacker&#39;s Delight - Henry S.
LSB_UTIL_EXPORT lsb_err_id LSB_ERR_UTIL_FULL
LSB_UTIL_EXPORT bool lsb_set_tz(const char *tz)
Sets the timezone environment variable for the time conversion functions.
LSB_UTIL_EXPORT long long lsb_get_timestamp()
Retrieves the highest resolution time since Jan 1, 1970 converted to nanoseconds. ...
#define LSB_UTIL_EXPORT
Definition: util.h:28
LSB_UTIL_EXPORT char * lsb_read_file(const char *fn)
Read a file into a string.
LSB_UTIL_EXPORT unsigned long long lsb_get_time()
Retrieves the highest resolution timer available converted to nanoseconds.
LSB_UTIL_EXPORT lsb_err_id LSB_ERR_UTIL_PRANGE