Blame elf/stringtable.h

Packit Service c77dc9
/* String tables for ld.so.cache construction.
Packit Service c77dc9
   Copyright (C) 2020 Free Software Foundation, Inc.
Packit Service c77dc9
   This file is part of the GNU C Library.
Packit Service c77dc9
Packit Service c77dc9
   This program is free software; you can redistribute it and/or modify
Packit Service c77dc9
   it under the terms of the GNU General Public License as published
Packit Service c77dc9
   by the Free Software Foundation; version 2 of the License, or
Packit Service c77dc9
   (at your option) any later version.
Packit Service c77dc9
Packit Service c77dc9
   This program is distributed in the hope that it will be useful,
Packit Service c77dc9
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service c77dc9
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service c77dc9
   GNU General Public License for more details.
Packit Service c77dc9
Packit Service c77dc9
   You should have received a copy of the GNU General Public License
Packit Service c77dc9
   along with this program; if not, see <https://www.gnu.org/licenses/>.  */
Packit Service c77dc9
Packit Service c77dc9
#ifndef _STRINGTABLE_H
Packit Service c77dc9
#define _STRINGTABLE_H
Packit Service c77dc9
Packit Service c77dc9
#include <stddef.h>
Packit Service c77dc9
#include <stdint.h>
Packit Service c77dc9
Packit Service c77dc9
/* An entry in the string table.  Only the length and string fields are
Packit Service c77dc9
   expected to be used outside the string table code.  */
Packit Service c77dc9
struct stringtable_entry
Packit Service c77dc9
{
Packit Service c77dc9
  struct stringtable_entry *next; /* For collision resolution.  */
Packit Service c77dc9
  uint32_t length;                /* Length of then string.  */
Packit Service c77dc9
  uint32_t offset;                /* From start of finalized table.  */
Packit Service c77dc9
  char string[];                  /* Null-terminated string.  */
Packit Service c77dc9
};
Packit Service c77dc9
Packit Service c77dc9
/* A string table.  Zero-initialization produces a valid atable.  */
Packit Service c77dc9
struct stringtable
Packit Service c77dc9
{
Packit Service c77dc9
  struct stringtable_entry **entries;  /* Array of hash table buckets.  */
Packit Service c77dc9
  uint32_t count;                 /* Number of elements in the table.  */
Packit Service c77dc9
  uint32_t allocated;             /* Length of the entries array.  */
Packit Service c77dc9
};
Packit Service c77dc9
Packit Service c77dc9
/* Adds STRING to TABLE.  May return the address of an existing entry.  */
Packit Service c77dc9
struct stringtable_entry *stringtable_add (struct stringtable *table,
Packit Service c77dc9
                                           const char *string);
Packit Service c77dc9
Packit Service c77dc9
/* Result of stringtable_finalize.  SIZE bytes at STRINGS should be
Packit Service c77dc9
   written to the file.  */
Packit Service c77dc9
struct stringtable_finalized
Packit Service c77dc9
{
Packit Service c77dc9
  char *strings;
Packit Service c77dc9
  size_t size;
Packit Service c77dc9
};
Packit Service c77dc9
Packit Service c77dc9
/* Assigns offsets to string table entries and computes the serialized
Packit Service c77dc9
   form of the string table.  */
Packit Service c77dc9
void stringtable_finalize (struct stringtable *table,
Packit Service c77dc9
                           struct stringtable_finalized *result);
Packit Service c77dc9
Packit Service c77dc9
/* Deallocate the string table (but not the TABLE pointer itself).
Packit Service c77dc9
   (The table can be re-used for adding more strings without
Packit Service c77dc9
   initialization.)  */
Packit Service c77dc9
void stringtable_free (struct stringtable *table);
Packit Service c77dc9
Packit Service c77dc9
#endif /* _STRINGTABLE_H */