1 /* ----------------------------------------------------------------------- * 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 25 static inline __attribute__ ((always_inline)) 26 const char *refstr_get(const char *r) 27 { 28 if (r) 29 ((unsigned int *)r)[-1]++; 30 return r; 31 } 32 33 void refstr_put(const char *); 34 char *refstr_alloc(size_t); 35 const char *refstrdup(const char *); 36 const char *refstrndup(const char *, size_t); 37 int rsprintf(const char **, const char *, ...); 38 int vrsprintf(const char **, const char *, va_list); 39 40 #endif 41