#include <stdio.h>
#include <stdint.h>
#include "attributes.h"
Go to the source code of this file.
|
| char * | cog_load_whole_file_fp (FILE *fp, size_t *len) |
| | Load file contents into a string. More...
|
| |
| char * | cog_load_whole_file (const char filename[], size_t *len) |
| | Load file contents into a string. More...
|
| |
| long | cog_timezone (void) |
| | Get the difference between UTC and the latest local standard time, in seconds. More...
|
| |
| int | cog_iso8601_to_unix_ms (const char str[], size_t len, uint64_t *p_value) |
| | Convert a iso8601 string to a unix timestamp (milliseconds) More...
|
| |
| int | cog_unix_ms_to_iso8601 (char str[], size_t len, const uint64_t value) |
| | Convert a unix timestamp (milliseconds) to a iso8601 string. More...
|
| |
| int | cog_strtou64 (char *str, size_t len, uint64_t *p_value) |
| | Convert a numerical string to uint64_t More...
|
| |
| int | cog_u64tostr (char *str, size_t len, uint64_t *p_value) |
| | Convert uint64_t to a numerical string. More...
|
| |
| size_t | cog_strndup (const char src[], size_t len, char **p_dest) |
| | Copies at most len bytes of src to *p_dest. More...
|
| |
| size_t | cog_asprintf (char **strp, const char fmt[],...) |
| | Copies at most len bytes of src to *p_dest. More...
|
| |
| int | cog_sleep_ms (const long tms) |
| | Sleep for amount of milliseconds. More...
|
| |
| int | cog_sleep_us (const long tms) |
| | Sleep for amount of microseconds. More...
|
| |
| uint64_t | cog_timestamp_ms (void) |
| | Get the current timestamp in milliseconds. More...
|
| |
| uint64_t | cog_timestamp_us (void) |
| | Get the current timestamp in microseconds. More...
|
| |
◆ cog_load_whole_file_fp()
| char * cog_load_whole_file_fp |
( |
FILE * |
fp, |
|
|
size_t * |
len |
|
) |
| |
Load file contents into a string.
- Parameters
-
| fp | the file to be read |
| len | optional pointer to store the amount of bytes read |
- Returns
- the file contents
◆ cog_load_whole_file()
| char * cog_load_whole_file |
( |
const char |
filename[], |
|
|
size_t * |
len |
|
) |
| |
Load file contents into a string.
Wrapper over cog_load_whole_file_fp(), get the file by its relative-path.
- Parameters
-
| filename | the name of the file to be read |
| len | optional pointer to store the amount of bytes read |
- Returns
- the file contents
◆ cog_timezone()
| long cog_timezone |
( |
void |
| ) |
|
Get the difference between UTC and the latest local standard time, in seconds.
- Returns
- difference between UTC and local time in seconds
◆ cog_iso8601_to_unix_ms()
| int cog_iso8601_to_unix_ms |
( |
const char |
str[], |
|
|
size_t |
len, |
|
|
uint64_t * |
p_value |
|
) |
| |
Convert a iso8601 string to a unix timestamp (milliseconds)
Can be matched to the json_extract() and json_inject() F specifier
- Parameters
-
| str | the iso8601 string timestamp |
| len | the string length |
| p_value | pointer to the uint64_t variable to receive the converted timestamp |
- Returns
- 1 on success, 0 on failure
◆ cog_unix_ms_to_iso8601()
| int cog_unix_ms_to_iso8601 |
( |
char |
str[], |
|
|
size_t |
len, |
|
|
const uint64_t |
value |
|
) |
| |
Convert a unix timestamp (milliseconds) to a iso8601 string.
- Parameters
-
| timestamp | the buffer to receive the converted timestamp |
| len | the size of the buffer |
| value | the unix timestamp to be converted to iso8601 |
- Returns
- the amount of characters (in bytes) written to the buffer
◆ cog_strtou64()
| int cog_strtou64 |
( |
char * |
str, |
|
|
size_t |
len, |
|
|
uint64_t * |
p_value |
|
) |
| |
Convert a numerical string to uint64_t
- Parameters
-
| str | the numerical string |
| len | the string length |
| p_value | pointer to the uint64_t variable to receive the converted value |
- Returns
- 1 on success, 0 on failure
◆ cog_u64tostr()
| int cog_u64tostr |
( |
char * |
str, |
|
|
size_t |
len, |
|
|
uint64_t * |
p_value |
|
) |
| |
Convert uint64_t to a numerical string.
- Parameters
-
| str | the buffer to store the numerical string |
| len | the size of the buffer |
| p_value | the unsigned long long value |
- Returns
- the amount of characters (in bytes) written to the buffer
◆ cog_strndup()
| size_t cog_strndup |
( |
const char |
src[], |
|
|
size_t |
len, |
|
|
char ** |
p_dest |
|
) |
| |
Copies at most len bytes of src to *p_dest.
Analogous to strndup()
- Parameters
-
| src | the buffer to be copied |
| len | the maximum amount of characters to be copied |
| p_dest | a pointer to the new src copy |
- Returns
- length of copied string on success, 0 on failure
◆ cog_asprintf()
| size_t cog_asprintf |
( |
char ** |
strp, |
|
|
const char |
fmt[], |
|
|
|
... |
|
) |
| |
Copies at most len bytes of src to *p_dest.
Analogous to asprintf()
- Parameters
-
| strp | source to write resulting string to |
| fmt | printf format string |
| ... | variadic arguments to be matched to fmt specifiers |
- Returns
- length of copied string on success, -1 on failure
◆ cog_sleep_ms()
| int cog_sleep_ms |
( |
const long |
tms | ) |
|
Sleep for amount of milliseconds.
- Parameters
-
| tms | amount of milliseconds to sleep for |
- Returns
- 0 on success, -1 on error with an
errno set to indicate the error
◆ cog_sleep_us()
| int cog_sleep_us |
( |
const long |
tms | ) |
|
Sleep for amount of microseconds.
- Parameters
-
| tms | amount of microseconds to sleep for |
- Returns
- 0 on success, -1 on error with an
errno set to indicate the error
◆ cog_timestamp_ms()
| uint64_t cog_timestamp_ms |
( |
void |
| ) |
|
Get the current timestamp in milliseconds.
- Returns
- the timestamp on success, 0 on failure
◆ cog_timestamp_us()
| uint64_t cog_timestamp_us |
( |
void |
| ) |
|
Get the current timestamp in microseconds.
- Returns
- the timestamp on success, 0 on failure