Blame elf/stringtable.h

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