NeoMutt  2021-02-05-666-ge300cd
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 
33 struct 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 
42 void mutt_buffer_alloc (struct Buffer *buf, size_t size);
43 void mutt_buffer_dealloc (struct Buffer *buf);
44 void mutt_buffer_fix_dptr (struct Buffer *buf);
45 struct Buffer *mutt_buffer_init (struct Buffer *buf);
46 bool mutt_buffer_is_empty (const struct Buffer *buf);
47 size_t mutt_buffer_len (const struct Buffer *buf);
48 struct Buffer mutt_buffer_make (size_t size);
49 void mutt_buffer_reset (struct Buffer *buf);
50 char * mutt_buffer_strdup (const struct Buffer *buf);
51 void mutt_buffer_seek (struct Buffer *buf, size_t offset);
52 
53 // Functions that APPEND to a Buffer
54 size_t mutt_buffer_addch (struct Buffer *buf, char c);
55 size_t mutt_buffer_addstr (struct Buffer *buf, const char *s);
56 size_t mutt_buffer_addstr_n (struct Buffer *buf, const char *s, size_t len);
57 int mutt_buffer_add_printf (struct Buffer *buf, const char *fmt, ...);
58 
59 // Functions that OVERWRITE a Buffer
60 size_t mutt_buffer_concat_path (struct Buffer *buf, const char *dir, const char *fname);
61 size_t mutt_buffer_concatn_path (struct Buffer *dst, const char *dir, size_t dirlen, const char *fname, size_t fnamelen);
62 size_t mutt_buffer_copy (struct Buffer *dst, const struct Buffer *src);
63 int mutt_buffer_printf (struct Buffer *buf, const char *fmt, ...);
64 size_t mutt_buffer_strcpy (struct Buffer *buf, const char *s);
65 size_t mutt_buffer_strcpy_n (struct Buffer *buf, const char *s, size_t len);
66 size_t mutt_buffer_substrcpy (struct Buffer *buf, const char *beg, const char *end);
67 
77 static 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:61
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:356
String manipulation buffer.
Definition: buffer.h:33
size_t mutt_buffer_copy(struct Buffer *dst, const struct Buffer *src)
Copy a Buffer&#39;s contents to another Buffer.
Definition: buffer.c:445
void mutt_buffer_alloc(struct Buffer *buf, size_t size)
Make sure a buffer can store at least new_size bytes.
Definition: buffer.c:265
void mutt_buffer_seek(struct Buffer *buf, size_t offset)
set current read/write position to offset from beginning
Definition: buffer.c:466
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:203
size_t mutt_buffer_substrcpy(struct Buffer *buf, const char *beg, const char *end)
Copy a partial string into a Buffer.
Definition: buffer.c:342
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
size_t dsize
Length of data.
Definition: buffer.h:37
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:294
size_t mutt_buffer_strcpy_n(struct Buffer *buf, const char *s, size_t len)
Copy a string into a Buffer.
Definition: buffer.c:327
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:99
char * dptr
Current read/write position.
Definition: buffer.h:36
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:374
char * data
Pointer to data.
Definition: buffer.h:35
void mutt_buffer_fix_dptr(struct Buffer *buf)
Move the dptr to end of the Buffer.
Definition: buffer.c:181
struct Buffer * mutt_buffer_init(struct Buffer *buf)
Initialise a new Buffer.
Definition: buffer.c:46
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:240
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:79
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:411
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:160
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
Definition: buffer.c:225
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
Definition: buffer.c:252
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer&#39;s string.
Definition: buffer.c:432