Skip to content

Commit 348a22f

Browse files
Move buf_ declarations to a separate, installed .h file
cyrusimap#5108 because sieve_intefrace.h depends on struct buf declaration and sieve_interface.h is installed. -- install libconfig.h, imap/message_guid.h -- charset.h (installed): do not depend on util.h and thus on config.h
1 parent 7a06241 commit 348a22f

File tree

6 files changed

+88
-74
lines changed

6 files changed

+88
-74
lines changed

Makefile.am

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ include_HEADERS = \
758758
lib/bitvector.h \
759759
lib/bloom.h \
760760
lib/bsearch.h \
761+
lib/buf.h \
761762
lib/bufarray.h \
762763
lib/charset.h \
763764
lib/chartable.h \
@@ -777,6 +778,7 @@ include_HEADERS = \
777778
lib/imparse.h \
778779
lib/iostat.h \
779780
lib/iptostring.h \
781+
lib/libconfig.h \
780782
lib/libcyr_cfg.h \
781783
lib/lsort.h \
782784
lib/map.h \
@@ -800,23 +802,25 @@ include_HEADERS = \
800802
lib/tok.h \
801803
lib/vparse.h \
802804
lib/wildmat.h \
803-
lib/xmalloc.h
805+
lib/xmalloc.h \
806+
lib/xsha1.h
804807

805808
nodist_include_HEADERS = \
806809
lib/imapopts.h
807810

808-
nobase_include_HEADERS = sieve/sieve_interface.h
811+
nobase_include_HEADERS = \
812+
imap/message_guid.h \
813+
sieve/sieve_interface.h
814+
809815
nobase_nodist_include_HEADERS = sieve/sieve_err.h
810816

811817
noinst_HEADERS += \
812818
lib/byteorder.h \
813819
lib/gai.h \
814-
lib/libconfig.h \
815820
lib/md5.h \
816821
lib/prot.h \
817822
lib/ptrarray.h \
818823
lib/util.h \
819-
lib/xsha1.h \
820824
lib/xstrlcat.h \
821825
lib/xstrlcpy.h \
822826
lib/xstrnchr.h
@@ -1039,7 +1043,6 @@ imap_libcyrus_imap_la_SOURCES = \
10391043
imap/mboxname.c \
10401044
imap/mboxname.h \
10411045
imap/message_guid.c \
1042-
imap/message_guid.h \
10431046
imap/message.c \
10441047
imap/message.h \
10451048
imap/message_priv.h \

imap/message.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545

4646
#include <stdio.h>
4747

48+
#include "arrayu64.h"
49+
#include "buf.h"
4850
#include "prot.h"
4951
#include "mailbox.h"
52+
#include "imap/message_guid.h"
5053
#include "strarray.h"
51-
#include "util.h"
5254
#include "charset.h"
5355

5456
/* (draft standard) MIME tspecials */

lib/buf.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef CYRUS_BUF_H
2+
#define CYRUS_BUF_H
3+
4+
/* Examine the name of a file, and return a single character
5+
* (as an int) that can be used as the name of a hash
6+
* directory. Caller is responsible for skipping any prefix
7+
* of the name.
8+
*/
9+
int dir_hash_c(const char *name, int full);
10+
11+
#include <stddef.h>
12+
#define BUF_MMAP (1<<1)
13+
typedef unsigned long long int modseq_t;
14+
15+
struct buf {
16+
char *s;
17+
size_t len;
18+
size_t alloc;
19+
unsigned flags;
20+
};
21+
#define BUF_INITIALIZER { NULL, 0, 0, 0 }
22+
23+
#define buf_new() ((struct buf *) xzmalloc(sizeof(struct buf)))
24+
#define buf_destroy(b) do { buf_free((b)); free((b)); } while (0)
25+
#define buf_ensure(b, n) do { if ((b)->alloc < (b)->len + (n)) _buf_ensure((b), (n)); } while (0)
26+
#define buf_putc(b, c) do { buf_ensure((b), 1); (b)->s[(b)->len++] = (c); } while (0)
27+
28+
void _buf_ensure(struct buf *buf, size_t len);
29+
const char *buf_cstring(const struct buf *buf);
30+
const char *buf_cstringnull(const struct buf *buf);
31+
const char *buf_cstringnull_ifempty(const struct buf *buf);
32+
const char *buf_cstring_or_empty(const struct buf *buf);
33+
char *buf_newcstring(struct buf *buf);
34+
char *buf_release(struct buf *buf);
35+
char *buf_releasenull(struct buf *buf);
36+
void buf_getmap(struct buf *buf, const char **base, size_t *len);
37+
size_t buf_len(const struct buf *buf);
38+
const char *buf_base(const struct buf *buf);
39+
void buf_reset(struct buf *buf);
40+
void buf_setcstr(struct buf *buf, const char *str);
41+
void buf_setmap(struct buf *buf, const char *base, size_t len);
42+
void buf_copy(struct buf *dst, const struct buf *src);
43+
void buf_append(struct buf *dst, const struct buf *src);
44+
void buf_appendcstr(struct buf *buf, const char *str);
45+
void buf_appendoverlap(struct buf *buf, const char *str);
46+
void buf_appendmap(struct buf *buf, const char *base, size_t len);
47+
void buf_cowappendmap(struct buf *buf, const char *base, unsigned int len);
48+
void buf_cowappendfree(struct buf *buf, char *base, unsigned int len);
49+
void buf_insert(struct buf *dst, unsigned int off, const struct buf *src);
50+
void buf_insertcstr(struct buf *buf, unsigned int off, const char *str);
51+
void buf_insertmap(struct buf *buf, unsigned int off, const char *base, int len);
52+
void buf_printf(struct buf *buf, const char *fmt, ...)
53+
__attribute__((format(printf, 2, 3)));
54+
int buf_replace_all(struct buf *buf, const char *match,
55+
const char *replace);
56+
int buf_replace_char(struct buf *buf, char match, char replace);
57+
void buf_remove(struct buf *buf, unsigned int off, unsigned int len);
58+
int buf_cmp(const struct buf *, const struct buf *);
59+
int buf_findchar(const struct buf *, unsigned int off, int c);
60+
int buf_findline(const struct buf *buf, const char *line);
61+
void buf_init_ro(struct buf *buf, const char *base, size_t len);
62+
void buf_initm(struct buf *buf, char *base, int len);
63+
void buf_initmcstr(struct buf *buf, char *str);
64+
void buf_init_ro_cstr(struct buf *buf, const char *str);
65+
void buf_refresh_mmap(struct buf *buf, int onceonly, int fd,
66+
const char *fname, size_t size, const char *mboxname);
67+
void buf_free(struct buf *buf);
68+
void buf_move(struct buf *dst, struct buf *src);
69+
const char *buf_lcase(struct buf *buf);
70+
const char *buf_ucase(struct buf *buf);
71+
const char *buf_tocrlf(struct buf *buf);
72+
void buf_trim(struct buf *buf);
73+
74+
#endif /* CYRUS_BUF_H */

lib/charset.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
#define CHARSET_UNKNOWN_CHARSET (NULL)
6464

65-
#include "util.h"
65+
#include "buf.h"
6666
#include "xsha1.h"
6767

6868
typedef int comp_pat;

lib/util.h

Lines changed: 1 addition & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
#define STDERR_FILENO 2 /* Standard error output. */
6666
#endif
6767

68+
#include "buf.h"
6869
#include "xmalloc.h"
6970

7071
/* version string printable in gdb tracking */
@@ -106,7 +107,6 @@ typedef unsigned short bit32;
106107
#endif
107108

108109
typedef unsigned long long int bit64;
109-
typedef unsigned long long int modseq_t;
110110
#define MODSEQ_FMT "%llu"
111111
#define atomodseq_t(s) strtoull(s, NULL, 10)
112112

@@ -189,12 +189,6 @@ int strcmpnull(const char *a, const char *b);
189189
extern keyvalue *kv_bsearch (const char *key, keyvalue *kv, int nelem,
190190
int (*cmpf)(const char *s1, const char *s2));
191191

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);
198192
/*
199193
* Like dir_hash_c() but builds the result as a single-byte
200194
* C string in the provided buffer, and returns the buffer,
@@ -277,77 +271,18 @@ extern int64_t now_ms(void);
277271

278272
extern clock_t sclock(void);
279273

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);
303274
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);
307275
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);
314276
void buf_appendbit32(struct buf *buf, bit32 num);
315277
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);
322278
void buf_vprintf(struct buf *buf, const char *fmt, va_list args)
323279
__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);
329280
#ifdef ENABLE_REGEX
330281
int buf_replace_all_re(struct buf *buf, const regex_t *,
331282
const char *replace);
332283
int buf_replace_one_re(struct buf *buf, const regex_t *,
333284
const char *replace);
334285
#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);
351286

352287
/*
353288
* Given a list of strings, terminated by (char *)NULL,

sieve/sieve_interface.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@
5151
#define SIEVE_OK (0)
5252

5353
#include "arrayu64.h"
54+
#include "buf.h"
5455
#include "strarray.h"
55-
#include "util.h"
5656
#include "sieve/sieve_err.h"
5757

5858
/* external sieve types */

0 commit comments

Comments
 (0)