blob: 7001d40759a17d28f954edd9a2b829e1791cfac1 [file] [log] [blame]
Greg Hartman76d05dc2016-11-23 15:51:27 -08001/* ----------------------------------------------------------------------- *
2 *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
10 *
11 * ----------------------------------------------------------------------- */
12
13/*
14 * refstr.h
15 *
16 * Simple reference-counted strings
17 */
18
19#ifndef REFSTR_H
20#define REFSTR_H
21
22#include <stddef.h>
23#include <stdarg.h>
24
25static inline __attribute__ ((always_inline))
26const char *refstr_get(const char *r)
27{
28 if (r)
29 ((unsigned int *)r)[-1]++;
30 return r;
31}
32
33void refstr_put(const char *);
34char *refstr_alloc(size_t);
35const char *refstrdup(const char *);
36const char *refstrndup(const char *, size_t);
37int rsprintf(const char **, const char *, ...);
38int vrsprintf(const char **, const char *, va_list);
39
40#endif