]>
git.proxmox.com Git - wasi-libc.git/blob - libc-bottom-half/libpreopen/lib/po_map.c
2 * Copyright (c) 2016 Stanley Uche Godfrey
3 * Copyright (c) 2016, 2018 Jonathan Anderson
6 * This software was developed at Memorial University under the
7 * NSERC Discovery program (RGPIN-2015-06048).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @brief Implementation of po_map management functions
43 #ifdef __wasilibc_unmodified_upstream
48 po_map_create(int capacity
)
52 map
= malloc(sizeof(struct po_map
));
57 map
->entries
= calloc(sizeof(struct po_map_entry
), capacity
);
58 if (map
->entries
== NULL
) {
64 map
->capacity
= capacity
;
67 po_map_assertvalid(map
);
72 #ifdef __wasilibc_unmodified_upstream
77 po_map_enlarge(struct po_map
*map
)
79 struct po_map_entry
*enlarged
;
80 enlarged
= calloc(sizeof(struct po_map_entry
), 2 * map
->capacity
);
81 if (enlarged
== NULL
) {
84 memcpy(enlarged
, map
->entries
, map
->length
* sizeof(*enlarged
));
86 map
->entries
= enlarged
;
87 map
->capacity
= 2 * map
->capacity
;
91 #ifdef __wasilibc_unmodified_upstream
93 po_map_foreach(const struct po_map
*map
, po_map_iter_cb cb
)
95 struct po_map_entry
*entry
;
98 po_map_assertvalid(map
);
100 for (n
= 0; n
< map
->length
; n
++) {
101 entry
= map
->entries
+ n
;
103 if (!cb(entry
->name
, entry
->fd
, entry
->rights
)) {
112 #ifdef __wasilibc_unmodified_upstream
117 po_map_release(struct po_map
*map
)
123 po_map_assertvalid(map
);
127 if (map
->refcount
== 0) {