E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 1 | .. This work is licensed under a Creative Commons Attribution 4.0 International License. |
| 2 | .. SPDX-License-Identifier: CC-BY-4.0 |
| 3 | .. CAUTION: this document is generated from source in doc/src/rtd. |
| 4 | .. To make changes edit the source and recompile the document. |
| 5 | .. Do NOT make changes directly to .rst or .md files. |
| 6 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 7 | ============================================================================================ |
| 8 | Man Page: rmr_support |
| 9 | ============================================================================================ |
| 10 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 11 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 12 | |
| 13 | |
| 14 | RMR LIBRARY FUNCTIONS |
| 15 | ===================== |
| 16 | |
| 17 | |
| 18 | |
| 19 | NAME |
| 20 | ---- |
| 21 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 22 | RMR support functions |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 23 | |
| 24 | |
| 25 | SYNOPSIS |
| 26 | -------- |
| 27 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 28 | |
| 29 | :: |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 30 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 31 | #include <rmr/rmr.h> |
| 32 | #include <rmr/ring_inline.h> |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 33 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 34 | char* rmr_fib( char* fname ); |
| 35 | int rmr_has_str( char const* buf, char const* str, char sep, int max ); |
| 36 | int rmr_tokenise( char* buf, char** tokens, int max, char sep ); |
| 37 | void* rmr_mk_ring( int size ); |
| 38 | void rmr_ring_free( void* vr ); |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 39 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 40 | static inline void* rmr_ring_extract( void* vr ) |
| 41 | static inline int rmr_ring_insert( void* vr, void* new_data ) |
| 42 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 43 | |
| 44 | |
| 45 | DESCRIPTION |
| 46 | ----------- |
| 47 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 48 | These functions support the RMR library, and are made |
| 49 | available to user applications as some (e.g. route table |
| 50 | generators) might need and/or want to make use of them. The |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 51 | ``rmr_fib`` function accepts a file name and reads the entire |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 52 | file into a single buffer. The intent is to provide an easy |
| 53 | way to load a static route table without a lot of buffered |
| 54 | I/O hoops. |
| 55 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 56 | The ``rmr_has_str`` function accepts a *buffer* containing a |
| 57 | set of delimited tokens (e.g. foo,bar,goo) and returns true |
| 58 | if the target string, *str,* matches one of the tokens. The |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 59 | *sep* parameter provides the separation character in the |
| 60 | buffer (e.g a comma) and *max* indicates the maximum number |
| 61 | of tokens to split the buffer into before checking. |
| 62 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 63 | The ``rmr_tokenise`` function is a simple tokeniser which |
| 64 | splits *buf* into tokens at each occurrence of *sep*. |
| 65 | Multiple occurrences of the separator character (e.g. a,,b) |
| 66 | result in a nil token. Pointers to the tokens are placed into |
| 67 | the *tokens* array provided by the caller which is assumed to |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 68 | have at least enough space for *max* entries. |
| 69 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 70 | The ``rmr_mk_ring`` function creates a buffer ring with |
| 71 | *size* entries. |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 72 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 73 | The ``rmr_ring_free`` function accepts a pointer to a ring |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 74 | context and frees the associated memory. |
| 75 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 76 | The ``rmr_ring_insert`` and ``rmr_ring_extract`` functions |
| 77 | are provided as static inline functions via the |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 78 | *rmr/ring_inline.h* header file. These functions both accept |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 79 | the ring *context* returned by ``mk_ring,`` and either insert |
| 80 | a pointer at the next available slot (tail) or extract the |
| 81 | data at the head. |
| 82 | |
| 83 | |
| 84 | RETURN VALUES |
| 85 | ------------- |
| 86 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 87 | The following are the return values for each of these |
| 88 | functions. |
| 89 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 90 | The ``rmr_fib`` function returns a pointer to the buffer |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 91 | containing the contents of the file. The buffer is terminated |
| 92 | with a single nil character (0) making it a legitimate C |
| 93 | string. If the file was empty or nonexistent, a buffer with |
| 94 | an immediate nil character. If it is important to the calling |
| 95 | programme to know if the file was empty or did not exist, the |
| 96 | caller should use the system stat function call to make that |
| 97 | determination. |
| 98 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 99 | The ``rmr_has_str`` function returns 1 if *buf* contains the |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 100 | token referenced by &ita and false (0) if it does not. On |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 101 | error, a -1 value is returned and ``errno`` is set |
| 102 | accordingly. |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 103 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 104 | The ``rmr_tokenise`` function returns the actual number of |
| 105 | token pointers placed into *tokens* |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 106 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 107 | The ``rmr_mk_ring`` function returns a void pointer which is |
| 108 | the *context* for the ring. |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 109 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 110 | The ``rmr_ring_insert`` function returns 1 if the data was |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 111 | successfully inserted into the ring, and 0 if the ring is |
| 112 | full and the pointer could not be deposited. |
| 113 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 114 | The ``rmr_ring_extract`` will return the data which is at the |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 115 | head of the ring, or NULL if the ring is empty. |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 116 | |
| 117 | |
| 118 | ERRORS |
| 119 | ------ |
| 120 | |
| 121 | Not many of these functions set the value in ``errno,`` |
| 122 | however the value may be one of the following: |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 123 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 124 | .. list-table:: |
| 125 | :widths: auto |
| 126 | :header-rows: 0 |
| 127 | :class: borderless |
| 128 | |
| 129 | * - **INVAL** |
| 130 | - |
| 131 | Parameter(s) passed to the function were not valid. |
| 132 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 133 | |
E. Scott Daniels | a3a121c | 2020-05-06 09:07:08 -0400 | [diff] [blame] | 134 | |
| 135 | |
| 136 | EXAMPLE |
| 137 | ------- |
| 138 | |
| 139 | |
| 140 | |
| 141 | SEE ALSO |
| 142 | -------- |
| 143 | |
E. Scott Daniels | 117030c | 2020-04-10 17:17:02 -0400 | [diff] [blame] | 144 | rmr_alloc_msg(3), rmr_call(3), rmr_free_msg(3), rmr_init(3), |
| 145 | rmr_payload_size(3), rmr_send_msg(3), rmr_rcv_msg(3), |
| 146 | rmr_rcv_specific(3), rmr_rts_msg(3), rmr_ready(3), |