XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
libwapcaplet.c File Reference
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "libwapcaplet/libwapcaplet.h"
Include dependency graph for libwapcaplet.c:

Classes

struct  lwc_context_s
 

Macros

#define UNUSED(x)   ((x) = (x))
 
#define STR_OF(str)   ((char *)(str + 1))
 
#define CSTR_OF(str)   ((const char *)(str + 1))
 
#define NR_BUCKETS_DEFAULT   (4091)
 
#define LWC_ALLOC(s)   malloc(s)
 
#define LWC_FREE(p)   free(p)
 

Typedefs

typedef struct lwc_context_s lwc_context
 
typedef lwc_hash(* lwc_hasher) (const char *, size_t)
 
typedef int(* lwc_strncmp) (const char *, const char *, size_t)
 
typedef void *(* lwc_memcpy) (void *restrict, const void *restrict, size_t)
 

Functions

lwc_error lwc_intern_string (const char *s, size_t slen, lwc_string **ret)
 
lwc_error lwc_intern_substring (lwc_string *str, size_t ssoffset, size_t sslen, lwc_string **ret)
 
lwc_error lwc_string_tolower (lwc_string *str, lwc_string **ret)
 
void lwc_string_destroy (lwc_string *str)
 
lwc_error lwc__intern_caseless_string (lwc_string *str)
 
void lwc_iterate_strings (lwc_iteration_callback_fn cb, void *pw)
 

Macro Definition Documentation

◆ CSTR_OF

#define CSTR_OF (   str)    ((const char *)(str + 1))

◆ LWC_ALLOC

#define LWC_ALLOC (   s)    malloc(s)

◆ LWC_FREE

#define LWC_FREE (   p)    free(p)

◆ NR_BUCKETS_DEFAULT

#define NR_BUCKETS_DEFAULT   (4091)

◆ STR_OF

#define STR_OF (   str)    ((char *)(str + 1))

◆ UNUSED

#define UNUSED (   x)    ((x) = (x))

Typedef Documentation

◆ lwc_context

typedef struct lwc_context_s lwc_context

◆ lwc_hasher

typedef lwc_hash(* lwc_hasher) (const char *, size_t)

◆ lwc_memcpy

typedef void *(* lwc_memcpy) (void *restrict, const void *restrict, size_t)

◆ lwc_strncmp

typedef int(* lwc_strncmp) (const char *, const char *, size_t)

Function Documentation

◆ lwc__intern_caseless_string()

lwc_error lwc__intern_caseless_string ( lwc_string *  str)

Intern a caseless copy of the passed string.

Parameters
strThe string to intern the caseless copy of.
Returns
lwc_error_ok if successful, otherwise the error code describing the issue.,
Note
This is for "internal" use by the caseless comparison macro and not for users.

◆ lwc_intern_string()

lwc_error lwc_intern_string ( const char *  s,
size_t  slen,
lwc_string **  ret 
)

Intern a string.

Take a copy of the string data referred to by s and slen and intern it. The resulting lwc_string can be used for simple and caseless comparisons by lwc_string_isequal and lwc_string_caseless_isequal respectively.

Parameters
sPointer to the start of the string to intern.
slenLength of the string in characters. (Not including any terminators)
retPointer to lwc_string pointer to fill out.
Returns
Result of operation, if not OK then the value pointed to by ret will not be valid.
Note
The memory pointed to by s is not referenced by the result.
If the string was already present, its reference count is incremented rather than allocating more memory.
The returned string is currently NULL-terminated but this will not necessarily be the case in future. Try not to rely on it.

◆ lwc_intern_substring()

lwc_error lwc_intern_substring ( lwc_string *  str,
size_t  ssoffset,
size_t  sslen,
lwc_string **  ret 
)

Intern a substring.

Intern a subsequence of the provided lwc_string.

Parameters
strString to acquire substring from.
ssoffsetSubstring offset into str.
sslenSubstring length.
retPointer to pointer to lwc_string to fill out.
Returns
Result of operation, if not OK then the value pointed to by ret will not be valid.

◆ lwc_iterate_strings()

void lwc_iterate_strings ( lwc_iteration_callback_fn  cb,
void *  pw 
)

Iterate the context and return every string in it.

If there are no strings found in the context, then this has the side effect of removing the global context which will reduce the chances of false-positives on leak checkers.

Parameters
cbThe callback to give the string to.
pwThe private word for the callback.

◆ lwc_string_destroy()

void lwc_string_destroy ( lwc_string *  str)

Destroy an unreffed lwc_string.

This destroys an lwc_string whose reference count indicates that it should be.

Parameters
strThe string to unref.

◆ lwc_string_tolower()

lwc_error lwc_string_tolower ( lwc_string *  str,
lwc_string **  ret 
)

Optain a lowercased lwc_string from given lwc_string.

Parameters
strString to create lowercase string from.
retPointer to lwc_string pointer to fill out.
Returns
Result of operation, if not OK then the value pointed to by ret will not be valid.