File: dstring.h

package info (click to toggle)
libsmi 0.4.8%2Bdfsg2-17
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 13,972 kB
  • sloc: ansic: 49,659; java: 13,722; sh: 9,311; yacc: 8,705; lex: 1,448; javascript: 544; makefile: 347; perl: 117
file content (90 lines) | stat: -rw-r--r-- 1,798 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/*
 * dstring.h --
 *
 *	This file implements an abstract data type for dynamic strings.
 *
 *	Note: The behavior of the functions that modify the a dynamic
 *	string is undefined if an argument strings points into the
 *	dynamic string itself.
 *
 * Copyright (c) 2006 Juergen Schoenwaelder, International University Bremen.
 *
 * See the file "COPYING" for information on usage and redistribution
 * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
 *
 * @(#) $Id: smilint.c 1867 2004-10-06 13:45:31Z strauss $
 */

#ifndef _DSTRING_H_
#define _DSTRING_H_

#include <stdarg.h>

#ifdef __GNUC__
# define inline /* extern */ static inline
#else 
#ifdef HAVE_WIN_H
# define inline __inline
#endif
#endif

struct dstring {
    char   *str;
    size_t len;
};

typedef struct dstring dstring_t;

inline char*
dstring_str(dstring_t *ds)
{
    return ds ? ds->str : NULL;
}

inline size_t
dstring_len(dstring_t *ds)
{
    return ds ? ds->len : 0;
}

extern dstring_t*
dstring_new(void);

extern dstring_t*
dstring_delete(dstring_t *ds);

extern dstring_t*
dstring_assign(dstring_t *ds, const char *s);

extern dstring_t*
dstring_concat(dstring_t *ds, ...);

extern dstring_t*
dstring_append(dstring_t *ds, const char *s);

extern dstring_t*
dstring_append_char(dstring_t *ds, const char c);

extern dstring_t*
dstring_append_printf(dstring_t *ds, const char *format, ...);

extern dstring_t*
dstring_append_vprintf(dstring_t *ds, const char *format, va_list ap);

extern dstring_t*
dstring_printf(dstring_t *ds, const char *format, ...);

extern dstring_t*
dstring_vprintf(dstring_t *ds, const char *format, va_list ap);

extern dstring_t*
dstring_truncate(dstring_t *ds, int len);

extern dstring_t*
dstring_expand(dstring_t *ds, int len, char fill);

#ifdef __GNUC__
#undef inline
#endif

#endif