/[gentoo-projects]/pax-utils/xfuncs.h
Gentoo

Contents of /pax-utils/xfuncs.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.8 - (show annotations) (download) (as text)
Thu Mar 20 07:59:27 2014 UTC (8 months, 4 weeks ago) by vapier
Branch: MAIN
CVS Tags: HEAD
Changes since 1.7: +4 -2 lines
File MIME type: text/x-chdr
move array_cnt check into array_for_each init

atm, if you try to use array_for_each or array_flatten_str on an array that has no members, you will get a segfault.  this is an easy rule to forget (and the current code does just that in at least one place), so move the array_cnt check into the init phase.  theres negligible code size impact so it should not be a big deal.

1 /*
2 * Copyright 2003-2012 Gentoo Foundation
3 * Distributed under the terms of the GNU General Public License v2
4 * $Header: /var/cvsroot/gentoo-projects/pax-utils/xfuncs.h,v 1.7 2012/11/04 07:26:24 vapier Exp $
5 *
6 * Copyright 2003-2012 Ned Ludd - <solar@gentoo.org>
7 * Copyright 2004-2012 Mike Frysinger - <vapier@gentoo.org>
8 */
9
10 #ifndef __XFUNCS_H__
11 #define __XFUNCS_H__
12
13 char *xstrdup(const char *s);
14 void *xmalloc(size_t size);
15 void *xzalloc(size_t size);
16 void *xrealloc(void *ptr, size_t size);
17 void xstrncat(char **dst, const char *src, size_t *curr_len, size_t n);
18 #define xstrcat(dst,src,curr_len) xstrncat(dst,src,curr_len,0)
19 void xchrcat(char **dst, const char append, size_t *curr_len);
20
21 void *xmemdup(const void *src, size_t n);
22
23 typedef struct {
24 void **eles;
25 size_t num;
26 } array_t;
27 void xarraypush(array_t *array, const void *ele, size_t ele_len);
28 #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/)
29 void xarrayfree(array_t *array);
30 #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size))
31 #define array_for_each(arr, n, ele) \
32 for (n = 0, ele = array_cnt(arr) ? arr->eles[n] : NULL; \
33 n < array_cnt(arr); \
34 ele = arr->eles[++n])
35 #define array_init_decl { .eles = NULL, .num = 0, }
36 #define array_cnt(arr) (arr)->num
37 char *array_flatten_str(array_t *array);
38
39 #endif

  ViewVC Help
Powered by ViewVC 1.1.20