diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:52:54 +0100 |
| commit | dcacc00e3750300617ba6e16eb346713f91a783a (patch) | |
| tree | 38e2d4fb5ed9d119711d4295c6eda4b014af73fd /examples/redis-unstable/deps/lua/src/strbuf.h | |
| parent | 58dac10aeb8f5a041c46bddbeaf4c7966a99b998 (diff) | |
| download | crep-dcacc00e3750300617ba6e16eb346713f91a783a.tar.gz | |
Remove testing data
Diffstat (limited to 'examples/redis-unstable/deps/lua/src/strbuf.h')
| -rw-r--r-- | examples/redis-unstable/deps/lua/src/strbuf.h | 146 |
1 files changed, 0 insertions, 146 deletions
diff --git a/examples/redis-unstable/deps/lua/src/strbuf.h b/examples/redis-unstable/deps/lua/src/strbuf.h deleted file mode 100644 index c10f83f..0000000 --- a/examples/redis-unstable/deps/lua/src/strbuf.h +++ /dev/null | |||
| @@ -1,146 +0,0 @@ | |||
| 1 | /* strbuf - String buffer routines | ||
| 2 | * | ||
| 3 | * Copyright (c) 2010-2012 Mark Pulford <mark@kyne.com.au> | ||
| 4 | * | ||
| 5 | * Permission is hereby granted, free of charge, to any person obtaining | ||
| 6 | * a copy of this software and associated documentation files (the | ||
| 7 | * "Software"), to deal in the Software without restriction, including | ||
| 8 | * without limitation the rights to use, copy, modify, merge, publish, | ||
| 9 | * distribute, sublicense, and/or sell copies of the Software, and to | ||
| 10 | * permit persons to whom the Software is furnished to do so, subject to | ||
| 11 | * the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice shall be | ||
| 14 | * included in all copies or substantial portions of the Software. | ||
| 15 | * | ||
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 19 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 20 | * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 21 | * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include <stdlib.h> | ||
| 26 | #include <stdarg.h> | ||
| 27 | |||
| 28 | /* Size: Total bytes allocated to *buf | ||
| 29 | * Length: String length, excluding optional NULL terminator. | ||
| 30 | * Dynamic: True if created via strbuf_new() | ||
| 31 | */ | ||
| 32 | |||
| 33 | typedef struct { | ||
| 34 | char *buf; | ||
| 35 | size_t size; | ||
| 36 | size_t length; | ||
| 37 | int dynamic; | ||
| 38 | int reallocs; | ||
| 39 | int debug; | ||
| 40 | } strbuf_t; | ||
| 41 | |||
| 42 | #ifndef STRBUF_DEFAULT_SIZE | ||
| 43 | #define STRBUF_DEFAULT_SIZE 1023 | ||
| 44 | #endif | ||
| 45 | |||
| 46 | /* Initialise */ | ||
| 47 | extern strbuf_t *strbuf_new(size_t len); | ||
| 48 | extern void strbuf_init(strbuf_t *s, size_t len); | ||
| 49 | |||
| 50 | /* Release */ | ||
| 51 | extern void strbuf_free(strbuf_t *s); | ||
| 52 | extern char *strbuf_free_to_string(strbuf_t *s, size_t *len); | ||
| 53 | |||
| 54 | /* Management */ | ||
| 55 | extern void strbuf_resize(strbuf_t *s, size_t len); | ||
| 56 | static size_t strbuf_empty_length(strbuf_t *s); | ||
| 57 | static size_t strbuf_length(strbuf_t *s); | ||
| 58 | static char *strbuf_string(strbuf_t *s, size_t *len); | ||
| 59 | static void strbuf_ensure_empty_length(strbuf_t *s, size_t len); | ||
| 60 | static char *strbuf_empty_ptr(strbuf_t *s); | ||
| 61 | static void strbuf_extend_length(strbuf_t *s, size_t len); | ||
| 62 | |||
| 63 | /* Update */ | ||
| 64 | static void strbuf_append_mem(strbuf_t *s, const char *c, size_t len); | ||
| 65 | extern void strbuf_append_string(strbuf_t *s, const char *str); | ||
| 66 | static void strbuf_append_char(strbuf_t *s, const char c); | ||
| 67 | static void strbuf_ensure_null(strbuf_t *s); | ||
| 68 | |||
| 69 | /* Reset string for before use */ | ||
| 70 | static inline void strbuf_reset(strbuf_t *s) | ||
| 71 | { | ||
| 72 | s->length = 0; | ||
| 73 | } | ||
| 74 | |||
| 75 | static inline int strbuf_allocated(strbuf_t *s) | ||
| 76 | { | ||
| 77 | return s->buf != NULL; | ||
| 78 | } | ||
| 79 | |||
| 80 | /* Return bytes remaining in the string buffer | ||
| 81 | * Ensure there is space for a NULL terminator. */ | ||
| 82 | static inline size_t strbuf_empty_length(strbuf_t *s) | ||
| 83 | { | ||
| 84 | return s->size - s->length - 1; | ||
| 85 | } | ||
| 86 | |||
| 87 | static inline void strbuf_ensure_empty_length(strbuf_t *s, size_t len) | ||
| 88 | { | ||
| 89 | if (len > strbuf_empty_length(s)) | ||
| 90 | strbuf_resize(s, s->length + len); | ||
| 91 | } | ||
| 92 | |||
| 93 | static inline char *strbuf_empty_ptr(strbuf_t *s) | ||
| 94 | { | ||
| 95 | return s->buf + s->length; | ||
| 96 | } | ||
| 97 | |||
| 98 | static inline void strbuf_extend_length(strbuf_t *s, size_t len) | ||
| 99 | { | ||
| 100 | s->length += len; | ||
| 101 | } | ||
| 102 | |||
| 103 | static inline size_t strbuf_length(strbuf_t *s) | ||
| 104 | { | ||
| 105 | return s->length; | ||
| 106 | } | ||
| 107 | |||
| 108 | static inline void strbuf_append_char(strbuf_t *s, const char c) | ||
| 109 | { | ||
| 110 | strbuf_ensure_empty_length(s, 1); | ||
| 111 | s->buf[s->length++] = c; | ||
| 112 | } | ||
| 113 | |||
| 114 | static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c) | ||
| 115 | { | ||
| 116 | s->buf[s->length++] = c; | ||
| 117 | } | ||
| 118 | |||
| 119 | static inline void strbuf_append_mem(strbuf_t *s, const char *c, size_t len) | ||
| 120 | { | ||
| 121 | strbuf_ensure_empty_length(s, len); | ||
| 122 | memcpy(s->buf + s->length, c, len); | ||
| 123 | s->length += len; | ||
| 124 | } | ||
| 125 | |||
| 126 | static inline void strbuf_append_mem_unsafe(strbuf_t *s, const char *c, size_t len) | ||
| 127 | { | ||
| 128 | memcpy(s->buf + s->length, c, len); | ||
| 129 | s->length += len; | ||
| 130 | } | ||
| 131 | |||
| 132 | static inline void strbuf_ensure_null(strbuf_t *s) | ||
| 133 | { | ||
| 134 | s->buf[s->length] = 0; | ||
| 135 | } | ||
| 136 | |||
| 137 | static inline char *strbuf_string(strbuf_t *s, size_t *len) | ||
| 138 | { | ||
| 139 | if (len) | ||
| 140 | *len = s->length; | ||
| 141 | |||
| 142 | return s->buf; | ||
| 143 | } | ||
| 144 | |||
| 145 | /* vi:ai et sw=4 ts=4: | ||
| 146 | */ | ||
