kore-doc

The kore documentation found under https://docs.kore.io/
Commits | Files | Refs | README | git clone https://git.kore.io/kore-doc.git

miscellaneous.md (3494B)



      1 # Miscellaneous
      2 
      3 Kore provides several helper functions.
      4 
      5 ## Index
      6 
      7 * [kore\_log](#log)
      8 * [kore\_strlcpy](#strlcpy)
      9 * [kore\_strtonum](#strtonum)
     10 * [kore\_strtonum64](#strtonum64)
     11 * [kore\_split\_string](#splitstring)
     12 * [kore\_strip\_chars](#stripchars)
     13 
     14 ---
     15 
     16 # kore\_log {#log}
     17 ### Synopsis
     18 ```
     19 void kore_log(int prio, const char *fmt, ...)
     20 ```
     21 ### Description
     22 Output a log message via syslog.
     23 
     24 Note that when running in the foreground these go to stdout.
     25 
     26 | Parameter | Description |
     27 | -- | -- |
     28 | prio   |  The priority of the log message (see syslog(3)).  |
     29 | fmt | The format string. |
     30 | ... | List of arguments. |
     31 
     32 ### Returns
     33 Nothing
     34 
     35 ---
     36 
     37 # kore\_strlcpy {#strlcpy}
     38 ### Synopsis
     39 ```
     40 size_t kore_strlcpy(char *dst, const char *src, const size_t length)
     41 ```
     42 ### Description
     43 Bounded C string copying. The result is always NUL-terminated.
     44 
     45 | Parameter | Description |
     46 | -- | -- |
     47 | dst | The destination buffer. |
     48 | src | The source C string. |
     49 | length | The maximum number of bytes that the destination buffer holds. |
     50 
     51 ### Returns
     52 The length of the original string. If this length is equal or larger than the destination buffer then truncation of the string has occurred.
     53 
     54 ---
     55 
     56 # kore\_strtonum {#strtonum}
     57 ### Synopsis
     58 ```
     59 long long kore_strtonum(const char *str, int base, long long min, long long max, int *err)
     60 ```
     61 ### Description
     62 Safely convert a C string holding a number into an integer.
     63 
     64 | Parameter | Description |
     65 | -- | -- |
     66 | str | The C string to convert. |
     67 | base | The base on which to operate. |
     68 | min | The minimum value the converted integer is allowed to have. |
     69 | max | The maximum value the converted integer is allowed to have. |
     70 | err | A pointer to an integer that holds the error value. |
     71 
     72 ### Returns
     73 Returns the converted integer. If the *err* parameter was set to KORE_RESULT_OK the conversion went OK otherwise there was an error and the returned value is considered garbage.
     74 
     75 ---
     76 
     77 # kore\_strtonum64 {#strtonum64}
     78 ### Synopsis
     79 ```
     80 u_int64_t kore_strtonum64(const char *str, int sign, int *err)
     81 ```
     82 ### Description
     83 Safely convert a C string holding a number to a 64-bit integer.
     84 
     85 | Parameter | Description |
     86 | -- | -- |
     87 | str | The C string to convert. |
     88 | sign | If the 64-bit integer is allowed to be signed or not. |
     89 | err | A pointer to an integer that holds the error value. |
     90 
     91 ### Returns
     92 Returns the converted integer. If the *err* parameter was set to KORE_RESULT_OK the conversion went OK otherwise there was an error and the returned value is considered garbage.
     93 
     94 ---
     95 
     96 # kore\_split\_string {#splitstring}
     97 ### Synopsis
     98 ```
     99 int kore_split_string(char *input, char *delim, char **out, size_t ele)
    100 ```
    101 ### Description
    102 Safely split a string into several elements. The *out* array is NULL terminated.
    103 
    104 | Parameter | Description |
    105 | -- | -- |
    106 | input | The string to be split up. |
    107 | delim | The delimiter used for splitting. |
    108 | out | Pointer to an array where the components are stored. |
    109 | ele | The number of elements that can be held in *out*. |
    110 
    111 ### Returns
    112 The number of components.
    113 
    114 ---
    115 
    116 # kore\_strip\_chars {#stripchars}
    117 ### Synopsis
    118 ```
    119 void kore_strip_chars(char *in, const char strip, char **out)
    120 ```
    121 ### Description
    122 Safely strip all occurrences of a certain character from a C string. The result must be freed by the caller.
    123 
    124 | Parameter | Description |
    125 | -- | -- |
    126 | in | The input C string. |
    127 | strip | The character to be stripped out of the string. |
    128 | out | A pointer to where the new result is stored. |
    129 
    130 ### Returns
    131 Nothing
    132 
    133 ---