utstring.h (6cec9cad762b6476313fb1f8e931a1647822db6b) utstring.h (3dcf5eb70598c88befd62f61f81e283e568ec519)
1/*
2Copyright (c) 2008-2013, Troy D. Hanson http://troydhanson.github.com/uthash/
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39#include <stdarg.h>
40
41#ifndef oom
42#define oom() exit(-1)
43#endif
44
45typedef struct {
46 char *d;
1/*
2Copyright (c) 2008-2013, Troy D. Hanson http://troydhanson.github.com/uthash/
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, are permitted provided that the following conditions are met:
7
8 * Redistributions of source code must retain the above copyright

--- 30 unchanged lines hidden (view full) ---

39#include <stdarg.h>
40
41#ifndef oom
42#define oom() exit(-1)
43#endif
44
45typedef struct {
46 char *d;
47 void **pd;
47 size_t n; /* allocd size */
48 size_t i; /* index of first unused byte */
49} UT_string;
50
51#define utstring_reserve(s,amt) \
52do { \
53 if (((s)->n - (s)->i) < (size_t)(amt)) { \
54 (s)->d = (char*)realloc((s)->d, (s)->n + amt); \
55 if ((s)->d == NULL) oom(); \
56 (s)->n += amt; \
48 size_t n; /* allocd size */
49 size_t i; /* index of first unused byte */
50} UT_string;
51
52#define utstring_reserve(s,amt) \
53do { \
54 if (((s)->n - (s)->i) < (size_t)(amt)) { \
55 (s)->d = (char*)realloc((s)->d, (s)->n + amt); \
56 if ((s)->d == NULL) oom(); \
57 (s)->n += amt; \
58 if ((s)->pd) *((s)->pd) = (s)->d; \
57 } \
58} while(0)
59
60#define utstring_init(s) \
61do { \
62 (s)->n = 0; (s)->i = 0; (s)->d = NULL; \
63 utstring_reserve(s,128); \
64 (s)->d[0] = '\0'; \

--- 8 unchanged lines hidden (view full) ---

73#define utstring_free(s) \
74do { \
75 utstring_done(s); \
76 free(s); \
77} while(0)
78
79#define utstring_new(s) \
80do { \
59 } \
60} while(0)
61
62#define utstring_init(s) \
63do { \
64 (s)->n = 0; (s)->i = 0; (s)->d = NULL; \
65 utstring_reserve(s,128); \
66 (s)->d[0] = '\0'; \

--- 8 unchanged lines hidden (view full) ---

75#define utstring_free(s) \
76do { \
77 utstring_done(s); \
78 free(s); \
79} while(0)
80
81#define utstring_new(s) \
82do { \
81 s = (UT_string*)calloc(sizeof(UT_string),1); \
83 s = (UT_string*)calloc(1, sizeof(UT_string)); \
82 if (!s) oom(); \
83 utstring_init(s); \
84} while(0)
85
86#define utstring_renew(s) \
87do { \
88 if (s) { \
89 utstring_clear(s); \

--- 321 unchanged lines hidden ---
84 if (!s) oom(); \
85 utstring_init(s); \
86} while(0)
87
88#define utstring_renew(s) \
89do { \
90 if (s) { \
91 utstring_clear(s); \

--- 321 unchanged lines hidden ---