icedb  version 0.5.1
Snow particle scattering database API
Macros | Functions
util.h File Reference
#include "defs.h"
#include <string.h>
#include <uchar.h>
Include dependency graph for util.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define ICEDB_H_UTIL
 
#define ICEDB_COMPAT_fprintf_s   fprintf
 
#define ICEDB_COMPAT_fwprintf_s   fwprintf
 
#define ICEDB_COMPAT_fputs_s   fputs
 
#define ICEDB_COMPAT_fputws_s   fputws
 
#define ICEDB_COMPAT_wcsnlen_s   wcsnlen_s
 
#define ICEDB_COMPAT_strnlen_s   strnlen
 

Functions

ICEDB_BEGIN_DECL_C DL_ICEDB size_t ICEDB_COMPAT_strncpy_s (char *dest, size_t destSz, const char *src, size_t srcSz)
 
DL_ICEDB char * ICEDB_COMPAT_strdup_s (const char *src, size_t srcSz)
 
DL_ICEDB size_t ICEDB_COMPAT_wcsncpy_s (wchar_t *dest, size_t destSz, const wchar_t *src, size_t srcSz)
 
DL_ICEDB wchar_t * ICEDB_COMPAT_wcsdup_s (const wchar_t *src, size_t srcSz)
 
DL_ICEDB void * ICEDB_malloc (size_t numBytes)
 Allocate memory in bytes. Generally this is just malloced, but a custom allocator may be substituted. More...
 
DL_ICEDB void ICEDB_free (void *obj)
 Free memory region. Should not be double-freed. More...
 

Macro Definition Documentation

◆ ICEDB_COMPAT_fprintf_s

#define ICEDB_COMPAT_fprintf_s   fprintf

Safe file stream printf

Definition at line 26 of file util.h.

Referenced by error_context_to_stream(), ICEDB_DEBUG_RAISE_EXCEPTION_HANDLER_A(), and ICEDB_writeDebugString().

◆ ICEDB_COMPAT_fputs_s

#define ICEDB_COMPAT_fputs_s   fputs

Save file stream fputs

Definition at line 35 of file util.h.

Referenced by error_code_to_stream(), and error_context_to_stream().

◆ ICEDB_COMPAT_fputws_s

#define ICEDB_COMPAT_fputws_s   fputws

Definition at line 36 of file util.h.

◆ ICEDB_COMPAT_fwprintf_s

#define ICEDB_COMPAT_fwprintf_s   fwprintf

Definition at line 27 of file util.h.

Referenced by ICEDB_DEBUG_RAISE_EXCEPTION_HANDLER_WC().

◆ ICEDB_COMPAT_strnlen_s

#define ICEDB_COMPAT_strnlen_s   strnlen

◆ ICEDB_COMPAT_wcsnlen_s

#define ICEDB_COMPAT_wcsnlen_s   wcsnlen_s

Definition at line 43 of file util.h.

◆ ICEDB_H_UTIL

#define ICEDB_H_UTIL

Definition at line 3 of file util.h.

Function Documentation

◆ ICEDB_COMPAT_strdup_s()

DL_ICEDB char* ICEDB_COMPAT_strdup_s ( const char *  src,
size_t  srcSz 
)

Safe char array initialization and copy. Null appended at end (added to srcSz).

Definition at line 42 of file util.cpp.

References ICEDB_COMPAT_strncpy_s(), ICEDB_DEBUG_RAISE_EXCEPTION, and ICEDB_malloc().

Referenced by error_context_add_string(), and ICEDB_enumModules().

43 {
45  if (!src) ICEDB_DEBUG_RAISE_EXCEPTION();
46  char* res = (char*)ICEDB_malloc(sizeof(char)*(srcSz + 1));
47  ICEDB_COMPAT_strncpy_s(res, srcSz + 1, src, srcSz + 1);
48  return res;
49 }
#define ICEDB_DEBUG_RAISE_EXCEPTION()
Definition: defs.h:151
ICEDB_BEGIN_DECL_C ICEDB_SYMBOL_SHARED size_t ICEDB_COMPAT_strncpy_s(char *dest, size_t destSz, const char *src, size_t srcSz)
Definition: util.cpp:14
ICEDB_SYMBOL_SHARED void * ICEDB_malloc(size_t numBytes)
Allocate memory in bytes. Generally this is just malloced, but a custom allocator may be substituted...
Definition: util.cpp:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ICEDB_COMPAT_strncpy_s()

ICEDB_BEGIN_DECL_C DL_ICEDB size_t ICEDB_COMPAT_strncpy_s ( char *  dest,
size_t  destSz,
const char *  src,
size_t  srcSz 
)

Safe char array copy.

Returns
the number of characters actually written.
Parameters
destis the pointer to the destination. Always null terminated.
destSzis the size of the destination buller, including the trailing null character.
srcis the pointer to the source. Characters from src are copied either until the first null character or until srcSz. Note that null termination comes later.
srcSzis the max size of the source buffer.

Definition at line 14 of file util.cpp.

References ICEDB_DEBUG_RAISE_EXCEPTION.

Referenced by error_code_to_message(), error_context_append(), error_context_copy(), error_context_create_impl(), error_context_to_message(), error_context_to_message_size(), error_context_widen(), icedb::versioning::genVersionInfo(), ICEDB_COMPAT_strdup_s(), ICEDB_findModuleByFunc(), ICEDB_getAppDir(), ICEDB_getAppPath(), ICEDB_getCWD(), ICEDB_getLibDir(), ICEDB_getLibPath(), ICEDB_getPluginDir(), and ICEDB_WriteLibVersionInfoC().

17 {
26  if (!dest || !src)ICEDB_DEBUG_RAISE_EXCEPTION();
27 #if ICEDB_USING_SECURE_STRINGS
28  strncpy_s(dest, destSz, src, srcSz);
29 #else
30  if (srcSz <= destSz) {
31  strncpy(dest, src, srcSz);
32  }
33  else {
34  strncpy(dest, src, destSz);
35  }
36 #endif
37  dest[destSz - 1] = 0;
38  for (size_t i = 0; i < destSz; ++i) if (dest[i] == '\0') return i;
39  return 0; // Should never be reached
40 }
#define ICEDB_DEBUG_RAISE_EXCEPTION()
Definition: defs.h:151
Here is the caller graph for this function:

◆ ICEDB_COMPAT_wcsdup_s()

DL_ICEDB wchar_t* ICEDB_COMPAT_wcsdup_s ( const wchar_t *  src,
size_t  srcSz 
)

Safe char array initialization and copy. Null appended at end (added to srcSz).

Definition at line 80 of file util.cpp.

References ICEDB_COMPAT_wcsncpy_s(), ICEDB_DEBUG_RAISE_EXCEPTION, and ICEDB_malloc().

81 {
83  if (!src) ICEDB_DEBUG_RAISE_EXCEPTION();
84  wchar_t* res = (wchar_t*)ICEDB_malloc(sizeof(wchar_t)*(srcSz + 1));
85  ICEDB_COMPAT_wcsncpy_s(res, srcSz + 1, src, srcSz + 1);
86  return res;
87 }
#define ICEDB_DEBUG_RAISE_EXCEPTION()
Definition: defs.h:151
ICEDB_SYMBOL_SHARED void * ICEDB_malloc(size_t numBytes)
Allocate memory in bytes. Generally this is just malloced, but a custom allocator may be substituted...
Definition: util.cpp:90
ICEDB_SYMBOL_SHARED size_t ICEDB_COMPAT_wcsncpy_s(wchar_t *dest, size_t destSz, const wchar_t *src, size_t srcSz)
Definition: util.cpp:52
Here is the call graph for this function:

◆ ICEDB_COMPAT_wcsncpy_s()

DL_ICEDB size_t ICEDB_COMPAT_wcsncpy_s ( wchar_t *  dest,
size_t  destSz,
const wchar_t *  src,
size_t  srcSz 
)

Safe char array copy.

Returns
the number of characters actually written.
Parameters
destis the pointer to the destination. Always null terminated.
destSzis the size of the destination buller, including the trailing null character.
srcis the pointer to the source. Characters from src are copied either until the first null character or until srcSz. Note that null termination comes later.
srcSzis the max size of the source buffer.

Definition at line 52 of file util.cpp.

References ICEDB_DEBUG_RAISE_EXCEPTION.

Referenced by ICEDB_COMPAT_wcsdup_s().

55 {
64  if (!dest || !src)ICEDB_DEBUG_RAISE_EXCEPTION();
65 #if ICEDB_USING_SECURE_STRINGS
66  wcsncpy_s(dest, destSz, src, srcSz);
67 #else
68  if (srcSz <= destSz) {
69  wcsncpy(dest, src, srcSz);
70  }
71  else {
72  wcsncpy(dest, src, destSz);
73  }
74 #endif
75  dest[destSz - 1] = 0;
76  for (size_t i = 0; i < destSz; ++i) if (dest[i] == '\0') return i;
77  return 0; // Should never be reached
78 }
#define ICEDB_DEBUG_RAISE_EXCEPTION()
Definition: defs.h:151
Here is the caller graph for this function:

◆ ICEDB_free()

DL_ICEDB void ICEDB_free ( void *  obj)

Free memory region. Should not be double-freed.

Definition at line 97 of file util.cpp.

References icedb::free(), and ICEDB_DEBUG_RAISE_EXCEPTION.

Referenced by icedb::_free(), error_context_append(), error_context_create_impl(), error_context_deallocate(), error_context_to_message(), error_context_to_message_size(), error_context_widen(), ICEDB_free_enumModulesRes(), and icedb::os_functions::populateOSstrings().

98 {
99  if (!obj) ICEDB_DEBUG_RAISE_EXCEPTION();
100  free(obj);
101 }
#define ICEDB_DEBUG_RAISE_EXCEPTION()
Definition: defs.h:151
void free(T *obj)
Definition: util.hpp:21
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ICEDB_malloc()

DL_ICEDB void* ICEDB_malloc ( size_t  numBytes)

Allocate memory in bytes. Generally this is just malloced, but a custom allocator may be substituted.

Definition at line 90 of file util.cpp.

References ICEDB_DEBUG_RAISE_EXCEPTION, and icedb::malloc().

Referenced by icedb::_malloc(), error_context_append(), error_context_copy(), error_context_create_impl(), error_context_to_message(), error_context_to_message_size(), error_context_widen(), ICEDB_COMPAT_strdup_s(), ICEDB_COMPAT_wcsdup_s(), ICEDB_enumModules(), and icedb::os_functions::populateOSstrings().

91 {
92  void* res = malloc(numBytes);
93  if (!res) ICEDB_DEBUG_RAISE_EXCEPTION();
94  return res;
95 }
#define ICEDB_DEBUG_RAISE_EXCEPTION()
Definition: defs.h:151
T * malloc(size_t numBytes)
Definition: util.hpp:13
Here is the call graph for this function:
Here is the caller graph for this function: