libreis 0.1.0
A simple header-based drop-in library
Loading...
Searching...
No Matches
reis.h File Reference

Shared typedefs and functions. More...

#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/prctl.h>
#include <signal.h>
#include <syslog.h>
#include <time.h>
#include <fcntl.h>
#include <stdatomic.h>

Go to the source code of this file.

Data Structures

struct  Pair
 
struct  Vec2
 
struct  Map
 
struct  List
 
struct  wcs_dynarr_t
 
struct  MultiMapNode
 
struct  MultiMap
 
struct  TrieNode
 
struct  string_t
 
union  string_t::string_content
 
struct  hashtable_entry_t
 
struct  hashtable_t
 
struct  hashtable_iterator_t
 
struct  filesystem_t
 

Macros

#define VERISION   "0.1.0"
 
#define REISLIB_INT_MAX   2147483647
 
#define CHARSET   "abcdefghijklmnopqrstuvwxyz"
 
#define CHARSET_LEN   26
 
#define MAX_CHARSET_SIZE   256
 
#define SUB   0x1A
 
#define MAX_DATASTRUCT_STRSIZ   100
 
#define MAP_MAX   100
 
#define MULTIMAP_DEFAULT_SIZE   16
 
#define MULTIMAP_RESIZE_FACTOR   2
 
#define REISLIB_HASHTABLE_INITIAL_CAPACITY   16
 
#define REISLIB_HASH_FNV_OFFSET   14695981039346656037UL
 
#define REISLIB_HASH_FNV_PRIME   1099511628211UL
 
#define BD_NO_CHDIR   01
 
#define BD_NO_CLOSE_FILES   02
 
#define BD_NO_REOPEN_STD_FDS   04
 
#define BD_NO_UMASK0   010
 
#define BD_MAX_CLOSE   8192
 
#define ANSI_RED   "\x1b[31m"
 
#define ANSI_GREEN   "\x1b[32m"
 
#define ANSI_YELLOW   "\x1b[33m"
 
#define ANSI_BLUE   "\x1b[34m"
 
#define ANSI_MAGENTA   "\x1b[35m"
 
#define ANSI_CYAN   "\x1b[36m"
 
#define ASNI_WHITE   "\x1b[37m"
 
#define ANSI_RESET   "\x1b[0m"
 
#define CHECK_PRINTF_FMT(...)
 
#define fnname(name)
 
#define reisHashTableGet(table, key)
 
#define reisHashTableSet(table, key, value)
 
#define MALLOC(size)
 
#define CALLOC(nitems, size)
 
#define REALLOC(ptr, size)
 
#define MGET(ptr)
 
#define FREE(ptr)
 
#define foreach   for
 

Typedefs

typedef uint8_t u8
 
typedef uint16_t u16
 
typedef uint32_t u32
 
typedef uint64_t u64
 
typedef int8_t s8
 
typedef int16_t s16
 
typedef int32_t s32
 
typedef int64_t s64
 
typedef float f32
 
typedef double f64
 
typedef long double f128
 
typedef struct Vec2 Vec2
 
typedef struct Map Map
 
typedef struct wcs_dynarr_t wcs_dynarr_t
 
typedef struct MultiMapNode MultiMapNode
 
typedef struct TrieNode TrieNode
 

Functions

enum __attribute__ ((__packed__))
 
PairreisPairCreate (wchar_t *first, wchar_t *second)
 
void reisPairFree (Pair *p)
 
Vec2reisNewVec2 (int x, int y)
 Create a new Vec2 datatype instance.
 
void reisDelVec2 (Vec2 *v)
 Destroy a Vec2 instance.
 
MapreisMapNew ()
 
void reisMapInsert (Map *m, char key[], int value)
 
int reisMapGet (Map *m, char key[])
 
void reisMapPrint (Map *m)
 
void reisMapDel (Map *m)
 
ListreisListNew (size_t n)
 
void reisListDel (List *a)
 
MultiMapreisNewMultiMap ()
 
void reisMultiMapInsert (MultiMap *m, wchar_t *key, void *value, size_t size)
 
void ** reisMultiMapGet (MultiMap *m, wchar_t *key, size_t *numValues)
 
void reisMultiMapPrint (MultiMap *m)
 
void reisDelMultiMap (MultiMap *m)
 
wcs_dynarr_twcs_dynarr_init ()
 
void wcs_dynarr_kill (wcs_dynarr_t *arr)
 
void wcs_dynarr_push (wcs_dynarr_t *arr, wchar_t *item)
 
TrieNodeTrieNodeInit (wchar_t data, int numOfLetters)
 
void TrieNodeFree (TrieNode *node)
 
TrieNodeTrieInsert (TrieNode *root, wchar_t *word)
 Inserts word onto the trie.
 
TrieNodeTrieDelete (TrieNode *root, wchar_t *word)
 Deletes words from trie. Will try to delete the word sequence from trie only if it ends up in a leaf node.
 
bool TrieSearch (TrieNode *root, wchar_t *word)
 Searches for a given word.
 
void TriePrint (TrieNode *root)
 
bool TriePrintSearch (TrieNode *root, wchar_t *word)
 
hashtable_treisNewHashTable ()
 
void reisDelHashTable (hashtable_t *table)
 
void * HashTableGet_str (hashtable_t *table, const char *key)
 
void * HashTableGet_wcs (hashtable_t *table, const wchar_t *key)
 
const char * HashTableSet_str (hashtable_t *table, const char *key, void *value)
 
const wchar_t * HashTableSet_wcs (hashtable_t *table, const wchar_t *key, void *value)
 
size_t reisHashTableLength (hashtable_t *table)
 
hashtable_iterator_t reisNewHashTableIterator (hashtable_t *table)
 
bool reisHashTableIteratorNext (hashtable_iterator_t it)
 
int reisDaemonize (const char *name, char *path, int flags)
 
int randi ()
 Uses the defined INT_MAX instead of passing bounds.
 
int randib (int lb, int ub)
 
char randc ()
 
char * rands (size_t len)
 
int isNum (const char *str)
 
filesystem_tFS_Create (char *path)
 Create a filesystem_t object.
 
void FS_Destroy (filesystem_t *fs)
 Terminates a filesystem_t object.
 
char fpeek (FILE *stream)
 View the next character in stream, doesn't move pointer.
 
wchar_t fpeek_wc (FILE *stream)
 Same as fpeek but for wchar_t.
 
char fspeek (FILE *stream, long int offset, int position)
 View a character at position without moving pointer; Peeks a seek.
 
int frpeek (FILE *stream, char c)
 A recursive peek that goes to end of line or EOF to get # of occurences.
 
int frdpeek (FILE *stream, char d)
 A recursive peek that goes till the delimter d.
 
int fcounts (FILE *stream)
 Character count of current line of buffer.
 
void fcopy (FILE *dest, FILE *src)
 Copies data from src file to dest file.
 
bool fexists (const char *file)
 Checks if file exists.
 
bool fmove (char *oldpath, char *newpath)
 Move data from oldpath file to newpath.
 
const char * ExtractFileName (const char *path)
 Returns filename.
 
const char * ExtractFileExtension (const char *filename)
 Returns file extension.
 
bool dexists (const char *path)
 Checks if directory exists.
 
void sgets (char *str, int n)
 A safe way to read input that ensures no misc LF or breaks in read string.
 
bool PromptYesOrNo (const char *question)
 Prompts the user with a yes or no question.
 
 CHECK_PRINTF_FMT (1, 2) void eprintf(const char *fmt
 
 CHECK_PRINTF_FMT (1, 3) void cprintf(const char *color
 
const char char * strdupl (const char *str)
 Implmentation of 'strdup,' using my MALLOC.
 
char * strcov (char *str, const char *charset)
 Checks if string covers all of charset.
 
wchar_t * wcscov (wchar_t *str, const wchar_t *charset)
 
const char * strset (const char *string, const char *charset)
 Checks to see if string contains only characters in charset.
 
const wchar_t * wcsset (const wchar_t *string, const wchar_t *charset)
 
char * strpcat (char *dest, const char *src, size_t pos)
 concatenate but at a give 'p' position.
 
wchar_t * wcspcat (wchar_t *dest, const wchar_t *src, size_t pos)
 
char * chrcat (char *dest, const char src)
 Concatenate a char on to the end of a string.
 
wchar_t * wccat (wchar_t *dest, const wchar_t src)
 
int strchrn (const char *string, char ch)
 Get number of times that ch appears in string.
 
int wcswcn (const wchar_t *string, wchar_t ch)
 (Wide-char variant) Get number of times that ch appears in string.
 
wchar_t * wcsrev (wchar_t *str)
 Reverses the wide character string.
 
char * strpre (char *str, char chr)
 
wchar_t * wcspre (wchar_t *str, wchar_t chr)
 Prepends a character to a wide character string.
 
char * strpres (char *str, char *pre)
 
wchar_t * wcspres (wchar_t *str, wchar_t *pre)
 
char * strisdigit (char *str)
 Confirms that string is entirely composed on numbers.
 
wchar_t * wcsisdigit (wchar_t *str)
 Confirms that wcstring is entirely composed on numbers.
 
long hash (const char *str)
 
void * reisMalloc (size_t size)
 
void * reisCalloc (size_t nitems, size_t size)
 
void * reisRealloc (void *ptr, size_t size)
 
size_t reisMemGet (void *ptr)
 
size_t reisFree (void *ptr)
 
size_t reisMemGetAll ()
 
void reisInsertionSort (int arr[], int len)
 
void reisMergeSort (int arr[], int len)
 
void reisSort (int arr[], int len)
 

Variables

 bool
 
const char * fmt
 

Detailed Description

Shared typedefs and functions.

Author
yung-turabian
Date
4 8 2024

Macro Definition Documentation

◆ CALLOC

#define CALLOC ( nitems,
size )
Value:
reisCalloc(nitems, size)
void * reisCalloc(size_t nitems, size_t size)
Definition memory.c:25

◆ fnname

#define fnname ( name)
Value:
#name

◆ FREE

#define FREE ( ptr)
Value:
reisFree(ptr)

◆ MALLOC

#define MALLOC ( size)
Value:
void * reisMalloc(size_t size)
Definition memory.c:8

◆ MGET

#define MGET ( ptr)
Value:
reisMemGet(ptr)

◆ REALLOC

#define REALLOC ( ptr,
size )
Value:
reisRealloc(ptr, size)

◆ reisHashTableGet

#define reisHashTableGet ( table,
key )
Value:
_Generic((key), \
char *: HashTableGet_str, \
const char *: HashTableGet_str, \
wchar_t *: HashTableGet_wcs \
)(table, key)

◆ reisHashTableSet

#define reisHashTableSet ( table,
key,
value )
Value:
_Generic((key), \
char *: HashTableSet_str, \
const char *: HashTableSet_str, \
wchar_t *: HashTableSet_wcs \
)(table, key, value)

Function Documentation

◆ chrcat()

char * chrcat ( char * dest,
const char src )

Concatenate a char on to the end of a string.

Returns
dest string

◆ dexists()

bool dexists ( const char * path)

Checks if directory exists.

Returns
a boolean.

◆ ExtractFileExtension()

const char * ExtractFileExtension ( const char * filename)

Returns file extension.

Returns
file exteionsion.

◆ ExtractFileName()

const char * ExtractFileName ( const char * path)

Returns filename.

Returns
a filename.

◆ fcopy()

void fcopy ( FILE * dest,
FILE * src )

Copies data from src file to dest file.

Returns
void.

◆ fcounts()

int fcounts ( FILE * stream)

Character count of current line of buffer.

Returns
A count.

◆ fexists()

bool fexists ( const char * file)

Checks if file exists.

Returns
a boolean.

◆ fmove()

bool fmove ( char * oldpath,
char * newpath )

Move data from oldpath file to newpath.

Returns
a boolean if was succesful or not.

◆ fpeek()

char fpeek ( FILE * stream)

View the next character in stream, doesn't move pointer.

Returns
the character.

◆ fpeek_wc()

wchar_t fpeek_wc ( FILE * stream)

Same as fpeek but for wchar_t.

Returns
the character.

◆ frdpeek()

int frdpeek ( FILE * stream,
char d )

A recursive peek that goes till the delimter d.

Returns
The number of occurences.

◆ frpeek()

int frpeek ( FILE * stream,
char c )

A recursive peek that goes to end of line or EOF to get # of occurences.

Returns
the number of occurences.

◆ FS_Create()

filesystem_t * FS_Create ( char * path)

Create a filesystem_t object.

Returns
The new structure.

◆ FS_Destroy()

void FS_Destroy ( filesystem_t * fs)

Terminates a filesystem_t object.

Returns
nothing.

◆ fspeek()

char fspeek ( FILE * stream,
long int offset,
int position )

View a character at position without moving pointer; Peeks a seek.

Returns
seeked and peeked character.

◆ PromptYesOrNo()

bool PromptYesOrNo ( const char * question)

Prompts the user with a yes or no question.

Returns
boolean response.

◆ reisCalloc()

void * reisCalloc ( size_t nitems,
size_t size )
Warning
Must be freed with free_s.

◆ reisDelVec2()

void reisDelVec2 ( Vec2 * v)

Destroy a Vec2 instance.

Parameters
vThe vector.

◆ reisMalloc()

void * reisMalloc ( size_t size)
Warning
Must be freed with free_s.

◆ reisNewVec2()

Vec2 * reisNewVec2 ( int x,
int y )

Create a new Vec2 datatype instance.

Parameters
x
y
Returns
Vec2*

◆ sgets()

void sgets ( char * str,
int n )

A safe way to read input that ensures no misc LF or breaks in read string.

Parameters
[str]A buffer.
[n]The buffer's length.
Returns
nothing.

◆ strchrn()

int strchrn ( const char * string,
char ch )

Get number of times that ch appears in string.

Returns
the number of instances.

◆ strcov()

char * strcov ( char * str,
const char * charset )

Checks if string covers all of charset.

Warning
will not care if a character not present in the charset is found.
Returns
string on success or NULL on failure.

◆ strdupl()

const char char * strdupl ( const char * str)

Implmentation of 'strdup,' using my MALLOC.

Returns
copy of string or NULL if something went wrong.

◆ strpcat()

char * strpcat ( char * dest,
const char * src,
size_t pos )

concatenate but at a give 'p' position.

Returns
dest string.

◆ strset()

const char * strset ( const char * string,
const char * charset )

Checks to see if string contains only characters in charset.

Returns
string if true, NULL if a unexpected character is found.

◆ TrieInsert()

TrieNode * TrieInsert ( TrieNode * root,
wchar_t * word )

Inserts word onto the trie.

Warning
Assumes word only has lower case characters.

◆ wcspre()

wchar_t * wcspre ( wchar_t * str,
wchar_t chr )

Prepends a character to a wide character string.

Returns
on success return string.

◆ wcsrev()

wchar_t * wcsrev ( wchar_t * str)

Reverses the wide character string.

Returns
on success return string.

◆ wcswcn()

int wcswcn ( const wchar_t * string,
wchar_t ch )

(Wide-char variant) Get number of times that ch appears in string.

Returns
the number of instances.