(root)/
man-db-2.12.0/
lib/
glcontainers.c
       1  /*
       2   * glcontainers.c: common Gnulib container helpers
       3   *
       4   * Copyright (C) 2019 Colin Watson.
       5   *
       6   * This file is part of man-db.
       7   *
       8   * man-db is free software; you can redistribute it and/or modify it
       9   * under the terms of the GNU General Public License as published by
      10   * the Free Software Foundation; either version 2 of the License, or
      11   * (at your option) any later version.
      12   *
      13   * man-db is distributed in the hope that it will be useful, but
      14   * WITHOUT ANY WARRANTY; without even the implied warranty of
      15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16   * GNU General Public License for more details.
      17   *
      18   * You should have received a copy of the GNU General Public License
      19   * along with man-db; if not, write to the Free Software Foundation,
      20   * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
      21   */
      22  
      23  #ifdef HAVE_CONFIG_H
      24  #  include "config.h"
      25  #endif /* HAVE_CONFIG_H */
      26  
      27  #include <stdbool.h>
      28  #include <stdlib.h>
      29  #include <string.h>
      30  
      31  #include "attribute.h"
      32  #include "gl_xlist.h"
      33  #include "gl_xmap.h"
      34  #include "gl_xset.h"
      35  #include "hash-pjw-bare.h"
      36  
      37  #include "manconfig.h"
      38  
      39  #include "glcontainers.h"
      40  
      41  bool ATTRIBUTE_PURE string_equals (const void *s1, const void *s2)
      42  {
      43  	return STREQ ((const char *) s1, (const char *) s2);
      44  }
      45  
      46  size_t ATTRIBUTE_PURE string_hash (const void *s)
      47  {
      48  	return hash_pjw_bare (s, strlen ((const char *) s));
      49  }
      50  
      51  void plain_free (const void *s)
      52  {
      53  	/* gl_list declares the argument as const, but there doesn't seem to
      54  	 * be a good reason for this.
      55  	 */
      56  	free ((void *) s);
      57  }
      58  
      59  gl_list_t new_string_list (gl_list_implementation_t implementation,
      60  			   bool allow_duplicates)
      61  {
      62  	return gl_list_create_empty (implementation, string_equals,
      63  				     string_hash, plain_free,
      64  				     allow_duplicates);
      65  }
      66  
      67  gl_map_t new_string_map (gl_map_implementation_t implementation,
      68  			 gl_mapvalue_dispose_fn vdispose_fn)
      69  {
      70  	return gl_map_create_empty (implementation, string_equals, string_hash,
      71  				    plain_free, vdispose_fn);
      72  }
      73  
      74  gl_set_t new_string_set (gl_set_implementation_t implementation)
      75  {
      76  	return gl_set_create_empty (implementation, string_equals, string_hash,
      77  				    plain_free);
      78  }