|
65 | 65 | #define STDERR_FILENO 2 /* Standard error output. */
|
66 | 66 | #endif
|
67 | 67 |
|
| 68 | +#include "buf.h" |
68 | 69 | #include "xmalloc.h"
|
69 | 70 |
|
70 | 71 | /* version string printable in gdb tracking */
|
@@ -106,7 +107,6 @@ typedef unsigned short bit32;
|
106 | 107 | #endif
|
107 | 108 |
|
108 | 109 | typedef unsigned long long int bit64;
|
109 |
| -typedef unsigned long long int modseq_t; |
110 | 110 | #define MODSEQ_FMT "%llu"
|
111 | 111 | #define atomodseq_t(s) strtoull(s, NULL, 10)
|
112 | 112 |
|
@@ -189,12 +189,6 @@ int strcmpnull(const char *a, const char *b);
|
189 | 189 | extern keyvalue *kv_bsearch (const char *key, keyvalue *kv, int nelem,
|
190 | 190 | int (*cmpf)(const char *s1, const char *s2));
|
191 | 191 |
|
192 |
| -/* Examine the name of a file, and return a single character |
193 |
| - * (as an int) that can be used as the name of a hash |
194 |
| - * directory. Caller is responsible for skipping any prefix |
195 |
| - * of the name. |
196 |
| - */ |
197 |
| -extern int dir_hash_c(const char *name, int full); |
198 | 192 | /*
|
199 | 193 | * Like dir_hash_c() but builds the result as a single-byte
|
200 | 194 | * C string in the provided buffer, and returns the buffer,
|
@@ -277,77 +271,18 @@ extern int64_t now_ms(void);
|
277 | 271 |
|
278 | 272 | extern clock_t sclock(void);
|
279 | 273 |
|
280 |
| -#define BUF_MMAP (1<<1) |
281 |
| - |
282 |
| -struct buf { |
283 |
| - char *s; |
284 |
| - size_t len; |
285 |
| - size_t alloc; |
286 |
| - unsigned flags; |
287 |
| -}; |
288 |
| -#define BUF_INITIALIZER { NULL, 0, 0, 0 } |
289 |
| - |
290 |
| -#define buf_new() ((struct buf *) xzmalloc(sizeof(struct buf))) |
291 |
| -#define buf_destroy(b) do { buf_free((b)); free((b)); } while (0) |
292 |
| -#define buf_ensure(b, n) do { if ((b)->alloc < (b)->len + (n)) _buf_ensure((b), (n)); } while (0) |
293 |
| -#define buf_putc(b, c) do { buf_ensure((b), 1); (b)->s[(b)->len++] = (c); } while (0) |
294 |
| - |
295 |
| -void _buf_ensure(struct buf *buf, size_t len); |
296 |
| -const char *buf_cstring(const struct buf *buf); |
297 |
| -const char *buf_cstringnull(const struct buf *buf); |
298 |
| -const char *buf_cstringnull_ifempty(const struct buf *buf); |
299 |
| -char *buf_release(struct buf *buf); |
300 |
| -char *buf_newcstring(struct buf *buf); |
301 |
| -char *buf_releasenull(struct buf *buf); |
302 |
| -void buf_getmap(struct buf *buf, const char **base, size_t *len); |
303 | 274 | int buf_getline(struct buf *buf, FILE *fp);
|
304 |
| -size_t buf_len(const struct buf *buf); |
305 |
| -const char *buf_base(const struct buf *buf); |
306 |
| -void buf_reset(struct buf *buf); |
307 | 275 | void buf_truncate(struct buf *buf, ssize_t len);
|
308 |
| -void buf_setcstr(struct buf *buf, const char *str); |
309 |
| -void buf_setmap(struct buf *buf, const char *base, size_t len); |
310 |
| -void buf_copy(struct buf *dst, const struct buf *src); |
311 |
| -void buf_append(struct buf *dst, const struct buf *src); |
312 |
| -void buf_appendcstr(struct buf *buf, const char *str); |
313 |
| -void buf_appendoverlap(struct buf *buf, const char *str); |
314 | 276 | void buf_appendbit32(struct buf *buf, bit32 num);
|
315 | 277 | void buf_appendbit64(struct buf *buf, bit64 num);
|
316 |
| -void buf_appendmap(struct buf *buf, const char *base, size_t len); |
317 |
| -void buf_cowappendmap(struct buf *buf, const char *base, unsigned int len); |
318 |
| -void buf_cowappendfree(struct buf *buf, char *base, unsigned int len); |
319 |
| -void buf_insert(struct buf *dst, unsigned int off, const struct buf *src); |
320 |
| -void buf_insertcstr(struct buf *buf, unsigned int off, const char *str); |
321 |
| -void buf_insertmap(struct buf *buf, unsigned int off, const char *base, int len); |
322 | 278 | void buf_vprintf(struct buf *buf, const char *fmt, va_list args)
|
323 | 279 | __attribute__((format(printf, 2, 0)));
|
324 |
| -void buf_printf(struct buf *buf, const char *fmt, ...) |
325 |
| - __attribute__((format(printf, 2, 3))); |
326 |
| -int buf_replace_all(struct buf *buf, const char *match, |
327 |
| - const char *replace); |
328 |
| -int buf_replace_char(struct buf *buf, char match, char replace); |
329 | 280 | #ifdef ENABLE_REGEX
|
330 | 281 | int buf_replace_all_re(struct buf *buf, const regex_t *,
|
331 | 282 | const char *replace);
|
332 | 283 | int buf_replace_one_re(struct buf *buf, const regex_t *,
|
333 | 284 | const char *replace);
|
334 | 285 | #endif
|
335 |
| -void buf_remove(struct buf *buf, unsigned int off, unsigned int len); |
336 |
| -int buf_cmp(const struct buf *, const struct buf *); |
337 |
| -int buf_findchar(const struct buf *, unsigned int off, int c); |
338 |
| -int buf_findline(const struct buf *buf, const char *line); |
339 |
| -void buf_init_ro(struct buf *buf, const char *base, size_t len); |
340 |
| -void buf_initm(struct buf *buf, char *base, int len); |
341 |
| -void buf_initmcstr(struct buf *buf, char *str); |
342 |
| -void buf_init_ro_cstr(struct buf *buf, const char *str); |
343 |
| -void buf_refresh_mmap(struct buf *buf, int onceonly, int fd, |
344 |
| - const char *fname, size_t size, const char *mboxname); |
345 |
| -void buf_free(struct buf *buf); |
346 |
| -void buf_move(struct buf *dst, struct buf *src); |
347 |
| -const char *buf_lcase(struct buf *buf); |
348 |
| -const char *buf_ucase(struct buf *buf); |
349 |
| -const char *buf_tocrlf(struct buf *buf); |
350 |
| -void buf_trim(struct buf *buf); |
351 | 286 |
|
352 | 287 | /*
|
353 | 288 | * Given a list of strings, terminated by (char *)NULL,
|
|
0 commit comments