1 /* ----------------------------------------------------------------------- *
3 * Copyright 2008 H. Peter Anvin - All Rights Reserved
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.
11 * ----------------------------------------------------------------------- */
16 * Simple reference-counted strings
23 const char *refstr_mkn(const char *str
, size_t len
)
27 len
= strnlen(str
, len
);
28 r
= malloc(sizeof(unsigned int)+len
+1);
29 *(unsigned int *)r
= 1;
30 r
+= sizeof(unsigned int);
36 const char *refstr_mk(const char *str
)
42 r
= malloc(sizeof(unsigned int)+len
+1);
43 *(unsigned int *)r
= 1;
44 r
+= sizeof(unsigned int);
50 void refstr_put(const char *r
)
52 unsigned int *ref
= (unsigned int *)r
- 1;