(root)/
glibc-2.38/
elf/
stringtable.h
       1  /* String tables for ld.so.cache construction.
       2     Copyright (C) 2020-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       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.
       9  
      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.
      14  
      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/>.  */
      17  
      18  #ifndef _STRINGTABLE_H
      19  #define _STRINGTABLE_H
      20  
      21  #include <stddef.h>
      22  #include <stdint.h>
      23  
      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
      27  {
      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.  */
      32  };
      33  
      34  /* A string table.  Zero-initialization produces a valid atable.  */
      35  struct stringtable
      36  {
      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.  */
      40  };
      41  
      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);
      45  
      46  /* Result of stringtable_finalize.  SIZE bytes at STRINGS should be
      47     written to the file.  */
      48  struct stringtable_finalized
      49  {
      50    char *strings;
      51    size_t size;
      52  };
      53  
      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);
      58  
      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);
      63  
      64  #endif /* _STRINGTABLE_H */