utstring.h (268831) | utstring.h (279549) |
---|---|
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 --- 25 unchanged lines hidden (view full) --- 34#define _UNUSED_ 35#endif 36 37#include <stdlib.h> 38#include <string.h> 39#include <stdarg.h> 40 41#ifndef oom | 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 --- 25 unchanged lines hidden (view full) --- 34#define _UNUSED_ 35#endif 36 37#include <stdlib.h> 38#include <string.h> 39#include <stdarg.h> 40 41#ifndef oom |
42#define oom() exit(-1) | 42#define oom abort |
43#endif 44 45typedef struct { 46 char *d; 47 void **pd; 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(); \ | 43#endif 44 45typedef struct { 46 char *d; 47 void **pd; 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 else {(s)->n += amt; \ 58 if ((s)->pd) *((s)->pd) = (s)->d;} \ |
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'; \ --- 10 unchanged lines hidden (view full) --- 77 utstring_done(s); \ 78 free(s); \ 79} while(0) 80 81#define utstring_new(s) \ 82do { \ 83 s = (UT_string*)calloc(1, sizeof(UT_string)); \ 84 if (!s) oom(); \ | 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'; \ --- 10 unchanged lines hidden (view full) --- 77 utstring_done(s); \ 78 free(s); \ 79} while(0) 80 81#define utstring_new(s) \ 82do { \ 83 s = (UT_string*)calloc(1, sizeof(UT_string)); \ 84 if (!s) oom(); \ |
85 utstring_init(s); \ | 85 else utstring_init(s); \ |
86} while(0) 87 88#define utstring_renew(s) \ 89do { \ 90 if (s) { \ 91 utstring_clear(s); \ 92 } else { \ 93 utstring_new(s); \ --- 319 unchanged lines hidden --- | 86} while(0) 87 88#define utstring_renew(s) \ 89do { \ 90 if (s) { \ 91 utstring_clear(s); \ 92 } else { \ 93 utstring_new(s); \ --- 319 unchanged lines hidden --- |