Gentoo Archives: gentoo-commits

From: "Mike Frysinger (vapier)" <vapier@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-projects commit in portage-utils/libq: libq.c xarray.c xmalloc.c
Date: Mon, 03 Oct 2011 16:18:36
Message-Id: 20111003161825.6A2842004C@flycatcher.gentoo.org
1 vapier 11/10/03 16:18:25
2
3 Modified: libq.c xmalloc.c
4 Added: xarray.c
5 Log:
6 use array helpers from pax-utils
7
8 Revision Changes Path
9 1.27 portage-utils/libq/libq.c
10
11 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.27&view=markup
12 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?rev=1.27&content-type=text/plain
13 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/libq.c?r1=1.26&r2=1.27
14
15 Index: libq.c
16 ===================================================================
17 RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/libq.c,v
18 retrieving revision 1.26
19 retrieving revision 1.27
20 diff -u -r1.26 -r1.27
21 --- libq.c 3 Oct 2011 01:25:54 -0000 1.26
22 +++ libq.c 3 Oct 2011 16:18:25 -0000 1.27
23 @@ -28,6 +28,7 @@
24 #include "xreadlink.c"
25 #include "xregex.c"
26 #include "xsystem.c"
27 +#include "xarray.c"
28
29 /* custom libs */
30 #include "atom_explode.c"
31
32
33
34 1.5 portage-utils/libq/xmalloc.c
35
36 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmalloc.c?rev=1.5&view=markup
37 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmalloc.c?rev=1.5&content-type=text/plain
38 diff : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xmalloc.c?r1=1.4&r2=1.5
39
40 Index: xmalloc.c
41 ===================================================================
42 RCS file: /var/cvsroot/gentoo-projects/portage-utils/libq/xmalloc.c,v
43 retrieving revision 1.4
44 retrieving revision 1.5
45 diff -u -r1.4 -r1.5
46 --- xmalloc.c 15 Jan 2008 08:03:34 -0000 1.4
47 +++ xmalloc.c 3 Oct 2011 16:18:25 -0000 1.5
48 @@ -27,8 +27,7 @@
49 #include <unistd.h>
50 #include <fcntl.h>
51
52 -void *xmalloc(size_t size);
53 -void *xmalloc(size_t size)
54 +static void *xmalloc(size_t size)
55 {
56 void *ptr = malloc(size);
57 if (ptr == NULL)
58 @@ -36,8 +35,7 @@
59 return ptr;
60 }
61
62 -void *xcalloc(size_t nmemb, size_t size);
63 -void *xcalloc(size_t nmemb, size_t size)
64 +static void *xcalloc(size_t nmemb, size_t size)
65 {
66 void *ptr = calloc(nmemb, size);
67 if (ptr == NULL)
68 @@ -45,8 +43,7 @@
69 return ptr;
70 }
71
72 -void *xzalloc(size_t size);
73 -void *xzalloc(size_t size)
74 +static void *xzalloc(size_t size)
75 {
76 void *ptr = xmalloc(size);
77 if (ptr == NULL)
78 @@ -55,11 +52,17 @@
79 return ptr;
80 }
81
82 -void *xrealloc(void *optr, size_t size);
83 -void *xrealloc(void *optr, size_t size)
84 +static void *xrealloc(void *optr, size_t size)
85 {
86 void *ptr = realloc(optr, size);
87 if (ptr == NULL)
88 err("Out of memory");
89 return ptr;
90 }
91 +
92 +static void *xmemdup(const void *src, size_t n)
93 +{
94 + void *ret = xmalloc(n);
95 + memcpy(ret, src, n);
96 + return ret;
97 +}
98
99
100
101 1.1 portage-utils/libq/xarray.c
102
103 file : http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xarray.c?rev=1.1&view=markup
104 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-projects/portage-utils/libq/xarray.c?rev=1.1&content-type=text/plain
105
106 Index: xarray.c
107 ===================================================================
108 /*
109 * Copyright 2003-2007 Gentoo Foundation
110 * Distributed under the terms of the GNU General Public License v2
111 * $Header: /var/cvsroot/gentoo-projects/portage-utils/libq/xarray.c,v 1.1 2011/10/03 16:18:25 vapier Exp $
112 *
113 * Copyright 2003-2007 Ned Ludd - <solar@g.o>
114 * Copyright 2004-2007 Mike Frysinger - <vapier@g.o>
115 */
116
117 typedef struct {
118 void **eles;
119 size_t num;
120 } array_t;
121
122 #define xrealloc_array(ptr, size, ele_size) xrealloc(ptr, (size) * (ele_size))
123 #define array_for_each(arr, n, ele) \
124 for (n = 0, ele = arr->eles[n]; n < arr->num; ++n, ele = arr->eles[n])
125 #define array_init_decl { .eles = NULL, .num = 0, }
126 #define array_cnt(arr) (arr)->num
127 #define DECLARE_ARRAY(arr) array_t _##arr = array_init_decl, *arr = &_##arr
128
129 static void xarraypush(array_t *arr, const void *ele, size_t ele_len)
130 {
131 size_t n = arr->num++;
132 arr->eles = xrealloc_array(arr->eles, arr->num, sizeof(ele));
133 arr->eles[n] = xmemdup(ele, ele_len);
134 }
135 #define xarraypush_str(arr, ele) xarraypush(arr, ele, strlen(ele) + 1 /*NUL*/)
136
137 static void xarrayfree(array_t *arr)
138 {
139 array_t blank = array_init_decl;
140 size_t n;
141
142 for (n = 0; n < arr->num; ++n)
143 free(arr->eles[n]);
144 free(arr->eles);
145
146 *arr = blank;
147 }