NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
buffer.h
Go to the documentation of this file.
1
24#ifndef MUTT_LIB_BUFFER_H
25#define MUTT_LIB_BUFFER_H
26
27#include <stddef.h>
28#include <stdbool.h>
29
33struct Buffer
34{
35 char *data;
36 char *dptr;
37 size_t dsize;
38};
39
40#define MoreArgs(buf) (*(buf)->dptr && (*(buf)->dptr != ';') && (*(buf)->dptr != '#'))
41
42void mutt_buffer_alloc (struct Buffer *buf, size_t size);
43void mutt_buffer_dealloc (struct Buffer *buf);
44void mutt_buffer_fix_dptr (struct Buffer *buf);
45struct Buffer *mutt_buffer_init (struct Buffer *buf);
46bool mutt_buffer_is_empty (const struct Buffer *buf);
47size_t mutt_buffer_len (const struct Buffer *buf);
48struct Buffer mutt_buffer_make (size_t size);
49void mutt_buffer_reset (struct Buffer *buf);
50char * mutt_buffer_strdup (const struct Buffer *buf);
51void mutt_buffer_seek (struct Buffer *buf, size_t offset);
52
53// Functions that APPEND to a Buffer
54size_t mutt_buffer_addch (struct Buffer *buf, char c);
55size_t mutt_buffer_addstr (struct Buffer *buf, const char *s);
56size_t mutt_buffer_addstr_n (struct Buffer *buf, const char *s, size_t len);
57int mutt_buffer_add_printf (struct Buffer *buf, const char *fmt, ...);
58
59// Functions that OVERWRITE a Buffer
60size_t mutt_buffer_concat_path (struct Buffer *buf, const char *dir, const char *fname);
61size_t mutt_buffer_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
62size_t mutt_buffer_copy (struct Buffer *dst, const struct Buffer *src);
63int mutt_buffer_printf (struct Buffer *buf, const char *fmt, ...);
64size_t mutt_buffer_strcpy (struct Buffer *buf, const char *s);
65size_t mutt_buffer_strcpy_n (struct Buffer *buf, const char *s, size_t len);
66size_t mutt_buffer_substrcpy (struct Buffer *buf, const char *beg, const char *end);
67
77static inline const char *mutt_buffer_string(const struct Buffer *buf)
78{
79 if (!buf || !buf->data)
80 return "";
81
82 return buf->data;
83}
84
85#endif /* MUTT_LIB_BUFFER_H */
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:260
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:327
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:309
size_t mutt_buffer_addstr_n(struct Buffer *buf, const char *s, size_t len)
Add a string to a Buffer, expanding it if necessary.
Definition: buffer.c:105
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:371
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:52
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:248
size_t mutt_buffer_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
Definition: buffer.c:357
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:233
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:189
size_t mutt_buffer_concatn_path(struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen)
Join a directory name and a filename.
Definition: buffer.c:426
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:211
void mutt_buffer_seek(struct Buffer *buf, size_t offset)
Set current read/write position to offset from beginning.
Definition: buffer.c:483
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:168
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer's contents to another Buffer.
Definition: buffer.c:462
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:85
size_t mutt_buffer_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:342
void mutt_buffer_alloc(struct Buffer *buf, size_t size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:275
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
Definition: buffer.c:447
size_t mutt_buffer_concat_path(struct Buffer *buf, const char *dir, const char *fname)
Join a directory name and a filename.
Definition: buffer.c:389
String manipulation buffer.
Definition: buffer.h:34
char * dptr
Current read/write position.
Definition: buffer.h:36
size_t dsize
Length of data.
Definition: buffer.h:37
char * data
Pointer to data.
Definition: buffer.h:35