XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Enumerations | Functions | Variables
cutils.h File Reference
#include <stdlib.h>
#include <string.h>
#include <inttypes.h>
Include dependency graph for cutils.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DynBuf
 

Macros

#define likely(x)   __builtin_expect(!!(x), 1)
 
#define unlikely(x)   __builtin_expect(!!(x), 0)
 
#define force_inline   inline __attribute__((always_inline))
 
#define no_inline   __attribute__((noinline))
 
#define __maybe_unused   __attribute__((unused))
 
#define xglue(x, y)   x ## y
 
#define glue(x, y)   xglue(x, y)
 
#define stringify(s)   tostring(s)
 
#define tostring(s)   #s
 
#define offsetof(type, field)   ((size_t) &((type *)0)->field)
 
#define countof(x)   (sizeof(x) / sizeof((x)[0]))
 
#define container_of(ptr, type, member)   ((type *)((uint8_t *)(ptr) - offsetof(type, member)))
 
#define minimum_length(n)   n
 
#define UTF8_CHAR_LEN_MAX   6
 

Typedefs

typedef int BOOL
 
typedef void * DynBufReallocFunc(void *opaque, void *ptr, size_t size)
 
typedef struct DynBuf DynBuf
 

Enumerations

enum  { FALSE = 0 , TRUE = 1 }
 

Functions

void pstrcpy (char *buf, int buf_size, const char *str)
 
char * pstrcat (char *buf, int buf_size, const char *s)
 
int strstart (const char *str, const char *val, const char **ptr)
 
int has_suffix (const char *str, const char *suffix)
 
struct __attribute__ ((packed)) packed_u64
 
void dbuf_init (DynBuf *s)
 
void dbuf_init2 (DynBuf *s, void *opaque, DynBufReallocFunc *realloc_func)
 
int dbuf_claim (DynBuf *s, size_t len)
 
int dbuf_put (DynBuf *s, const uint8_t *data, size_t len)
 
int dbuf_put_self (DynBuf *s, size_t offset, size_t len)
 
int dbuf_putstr (DynBuf *s, const char *str)
 
int __dbuf_putc (DynBuf *s, uint8_t c)
 
int __dbuf_put_u16 (DynBuf *s, uint16_t val)
 
int __dbuf_put_u32 (DynBuf *s, uint32_t val)
 
int __dbuf_put_u64 (DynBuf *s, uint64_t val)
 
int __attribute__ ((format(printf, 2, 3))) dbuf_printf(DynBuf *s
 
int const char void dbuf_free (DynBuf *s)
 
int unicode_to_utf8 (uint8_t *buf, unsigned int c)
 
int unicode_from_utf8 (const uint8_t *p, int max_len, const uint8_t **pp)
 
void rqsort (void *base, size_t nmemb, size_t size, int(*cmp)(const void *, const void *, void *), void *arg)
 

Variables

int const char * fmt
 

Macro Definition Documentation

◆ __maybe_unused

#define __maybe_unused   __attribute__((unused))

◆ container_of

#define container_of (   ptr,
  type,
  member 
)    ((type *)((uint8_t *)(ptr) - offsetof(type, member)))

◆ countof

#define countof (   x)    (sizeof(x) / sizeof((x)[0]))

◆ force_inline

#define force_inline   inline __attribute__((always_inline))

◆ glue

#define glue (   x,
  y 
)    xglue(x, y)

◆ likely

#define likely (   x)    __builtin_expect(!!(x), 1)

◆ minimum_length

#define minimum_length (   n)    n

◆ no_inline

#define no_inline   __attribute__((noinline))

◆ offsetof

#define offsetof (   type,
  field 
)    ((size_t) &((type *)0)->field)

◆ stringify

#define stringify (   s)    tostring(s)

◆ tostring

#define tostring (   s)    #s

◆ unlikely

#define unlikely (   x)    __builtin_expect(!!(x), 0)

◆ UTF8_CHAR_LEN_MAX

#define UTF8_CHAR_LEN_MAX   6

◆ xglue

#define xglue (   x,
  y 
)    x ## y

Typedef Documentation

◆ BOOL

typedef int BOOL

◆ DynBuf

typedef struct DynBuf DynBuf

◆ DynBufReallocFunc

typedef void * DynBufReallocFunc(void *opaque, void *ptr, size_t size)

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
FALSE 
TRUE 

Function Documentation

◆ __attribute__() [1/2]

int __attribute__ ( (format(printf, 2, 3))  )

◆ __attribute__() [2/2]

struct __attribute__ ( (packed)  )

BSD 2-Clause License

Copyright (c) 2022-2025, Manas Kamal Choudhury All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

◆ __dbuf_put_u16()

int __dbuf_put_u16 ( DynBuf *  s,
uint16_t  val 
)

◆ __dbuf_put_u32()

int __dbuf_put_u32 ( DynBuf *  s,
uint32_t  val 
)

◆ __dbuf_put_u64()

int __dbuf_put_u64 ( DynBuf *  s,
uint64_t  val 
)

◆ __dbuf_putc()

int __dbuf_putc ( DynBuf *  s,
uint8_t  c 
)

◆ dbuf_claim()

int dbuf_claim ( DynBuf *  s,
size_t  len 
)

◆ dbuf_free()

int const char void dbuf_free ( DynBuf *  s)

◆ dbuf_init()

void dbuf_init ( DynBuf *  s)

◆ dbuf_init2()

void dbuf_init2 ( DynBuf *  s,
void *  opaque,
DynBufReallocFunc *  realloc_func 
)

◆ dbuf_put()

int dbuf_put ( DynBuf *  s,
const uint8_t *  data,
size_t  len 
)

◆ dbuf_put_self()

int dbuf_put_self ( DynBuf *  s,
size_t  offset,
size_t  len 
)

◆ dbuf_putstr()

int dbuf_putstr ( DynBuf *  s,
const char *  str 
)

◆ has_suffix()

int has_suffix ( const char *  str,
const char *  suffix 
)

◆ pstrcat()

char * pstrcat ( char *  buf,
int  buf_size,
const char *  s 
)

◆ pstrcpy()

void pstrcpy ( char *  buf,
int  buf_size,
const char *  str 
)

◆ rqsort()

void rqsort ( void *  base,
size_t  nmemb,
size_t  size,
int(*)(const void *, const void *, void *)  cmp,
void *  arg 
)

◆ strstart()

int strstart ( const char *  str,
const char *  val,
const char **  ptr 
)

◆ unicode_from_utf8()

int unicode_from_utf8 ( const uint8_t *  p,
int  max_len,
const uint8_t **  pp 
)

◆ unicode_to_utf8()

int unicode_to_utf8 ( uint8_t *  buf,
unsigned int  c 
)

Variable Documentation

◆ fmt

int const char* fmt