Blame elf/stringtable.h

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