unistd: Improve fortify with clang
[glibc.git] / elf / stringtable.h
blobcccda251752402d6e2ecca3c233088123cd1d35e
1 /* String tables for ld.so.cache construction.
2 Copyright (C) 2020-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, see <https://www.gnu.org/licenses/>. */
18 #ifndef _STRINGTABLE_H
19 #define _STRINGTABLE_H
21 #include <stddef.h>
22 #include <stdint.h>
24 /* An entry in the string table. Only the length and string fields are
25 expected to be used outside the string table code. */
26 struct stringtable_entry
28 struct stringtable_entry *next; /* For collision resolution. */
29 uint32_t length; /* Length of then string. */
30 uint32_t offset; /* From start of finalized table. */
31 char string[]; /* Null-terminated string. */
34 /* A string table. Zero-initialization produces a valid atable. */
35 struct stringtable
37 struct stringtable_entry **entries; /* Array of hash table buckets. */
38 uint32_t count; /* Number of elements in the table. */
39 uint32_t allocated; /* Length of the entries array. */
42 /* Adds STRING to TABLE. May return the address of an existing entry. */
43 struct stringtable_entry *stringtable_add (struct stringtable *table,
44 const char *string);
46 /* Result of stringtable_finalize. SIZE bytes at STRINGS should be
47 written to the file. */
48 struct stringtable_finalized
50 char *strings;
51 size_t size;
54 /* Assigns offsets to string table entries and computes the serialized
55 form of the string table. */
56 void stringtable_finalize (struct stringtable *table,
57 struct stringtable_finalized *result);
59 /* Deallocate the string table (but not the TABLE pointer itself).
60 (The table can be re-used for adding more strings without
61 initialization.) */
62 void stringtable_free (struct stringtable *table);
64 #endif /* _STRINGTABLE_H */