xref: /rk3399_rockchip-uboot/include/search.h (revision a6826fbc5c3802075d98e86488e1116ed0ad6fe5)
1*a6826fbcSWolfgang Denk /*
2*a6826fbcSWolfgang Denk  * Declarations for System V style searching functions.
3*a6826fbcSWolfgang Denk  * Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
4*a6826fbcSWolfgang Denk  * This file is part of the GNU C Library.
5*a6826fbcSWolfgang Denk  *
6*a6826fbcSWolfgang Denk  * The GNU C Library is free software; you can redistribute it and/or
7*a6826fbcSWolfgang Denk  * modify it under the terms of the GNU Lesser General Public
8*a6826fbcSWolfgang Denk  * License as published by the Free Software Foundation; either
9*a6826fbcSWolfgang Denk  * version 2.1 of the License, or (at your option) any later version.
10*a6826fbcSWolfgang Denk  *
11*a6826fbcSWolfgang Denk  * The GNU C Library is distributed in the hope that it will be useful,
12*a6826fbcSWolfgang Denk  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*a6826fbcSWolfgang Denk  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*a6826fbcSWolfgang Denk  * Lesser General Public License for more details.
15*a6826fbcSWolfgang Denk  *
16*a6826fbcSWolfgang Denk  * You should have received a copy of the GNU Lesser General Public
17*a6826fbcSWolfgang Denk  * License along with the GNU C Library; if not, write to the Free
18*a6826fbcSWolfgang Denk  * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19*a6826fbcSWolfgang Denk  * 02111-1307 USA.
20*a6826fbcSWolfgang Denk  */
21*a6826fbcSWolfgang Denk 
22*a6826fbcSWolfgang Denk /*
23*a6826fbcSWolfgang Denk  * Based on code from uClibc-0.9.30.3
24*a6826fbcSWolfgang Denk  * Extensions for use within U-Boot
25*a6826fbcSWolfgang Denk  * Copyright (C) 2010 Wolfgang Denk <wd@denx.de>
26*a6826fbcSWolfgang Denk  */
27*a6826fbcSWolfgang Denk 
28*a6826fbcSWolfgang Denk #ifndef _SEARCH_H
29*a6826fbcSWolfgang Denk #define	_SEARCH_H 1
30*a6826fbcSWolfgang Denk 
31*a6826fbcSWolfgang Denk #include <stddef.h>
32*a6826fbcSWolfgang Denk 
33*a6826fbcSWolfgang Denk #define __set_errno(val) do { errno = val; } while (0)
34*a6826fbcSWolfgang Denk 
35*a6826fbcSWolfgang Denk /*
36*a6826fbcSWolfgang Denk  * Prototype structure for a linked-list data structure.
37*a6826fbcSWolfgang Denk  * This is the type used by the `insque' and `remque' functions.
38*a6826fbcSWolfgang Denk  */
39*a6826fbcSWolfgang Denk 
40*a6826fbcSWolfgang Denk /* For use with hsearch(3).  */
41*a6826fbcSWolfgang Denk typedef int (*__compar_fn_t) (__const void *, __const void *);
42*a6826fbcSWolfgang Denk typedef __compar_fn_t comparison_fn_t;
43*a6826fbcSWolfgang Denk 
44*a6826fbcSWolfgang Denk /* Action which shall be performed in the call the hsearch.  */
45*a6826fbcSWolfgang Denk typedef enum {
46*a6826fbcSWolfgang Denk 	FIND,
47*a6826fbcSWolfgang Denk 	ENTER
48*a6826fbcSWolfgang Denk } ACTION;
49*a6826fbcSWolfgang Denk 
50*a6826fbcSWolfgang Denk typedef struct entry {
51*a6826fbcSWolfgang Denk 	char *key;
52*a6826fbcSWolfgang Denk 	char *data;
53*a6826fbcSWolfgang Denk } ENTRY;
54*a6826fbcSWolfgang Denk 
55*a6826fbcSWolfgang Denk /* Opaque type for internal use.  */
56*a6826fbcSWolfgang Denk struct _ENTRY;
57*a6826fbcSWolfgang Denk 
58*a6826fbcSWolfgang Denk /*
59*a6826fbcSWolfgang Denk  * Family of hash table handling functions.  The functions also
60*a6826fbcSWolfgang Denk  * have reentrant counterparts ending with _r.  The non-reentrant
61*a6826fbcSWolfgang Denk  * functions all work on a signle internal hashing table.
62*a6826fbcSWolfgang Denk  */
63*a6826fbcSWolfgang Denk 
64*a6826fbcSWolfgang Denk /* Data type for reentrant functions.  */
65*a6826fbcSWolfgang Denk struct hsearch_data {
66*a6826fbcSWolfgang Denk 	struct _ENTRY *table;
67*a6826fbcSWolfgang Denk 	unsigned int size;
68*a6826fbcSWolfgang Denk 	unsigned int filled;
69*a6826fbcSWolfgang Denk };
70*a6826fbcSWolfgang Denk 
71*a6826fbcSWolfgang Denk /* Create a new hashing table which will at most contain NEL elements.  */
72*a6826fbcSWolfgang Denk extern int hcreate(size_t __nel);
73*a6826fbcSWolfgang Denk extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
74*a6826fbcSWolfgang Denk 
75*a6826fbcSWolfgang Denk /* Destroy current internal hashing table.  */
76*a6826fbcSWolfgang Denk extern void hdestroy(void);
77*a6826fbcSWolfgang Denk extern void hdestroy_r(struct hsearch_data *__htab);
78*a6826fbcSWolfgang Denk 
79*a6826fbcSWolfgang Denk /*
80*a6826fbcSWolfgang Denk  * Search for entry matching ITEM.key in internal hash table.  If
81*a6826fbcSWolfgang Denk  * ACTION is `FIND' return found entry or signal error by returning
82*a6826fbcSWolfgang Denk  * NULL.  If ACTION is `ENTER' replace existing data (if any) with
83*a6826fbcSWolfgang Denk  * ITEM.data.
84*a6826fbcSWolfgang Denk  * */
85*a6826fbcSWolfgang Denk extern ENTRY *hsearch(ENTRY __item, ACTION __action);
86*a6826fbcSWolfgang Denk extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
87*a6826fbcSWolfgang Denk 		     struct hsearch_data *__htab);
88*a6826fbcSWolfgang Denk 
89*a6826fbcSWolfgang Denk /* Search and delete entry matching ITEM.key in internal hash table. */
90*a6826fbcSWolfgang Denk extern int hdelete(const char *__key);
91*a6826fbcSWolfgang Denk extern int hdelete_r(const char *__key, struct hsearch_data *__htab);
92*a6826fbcSWolfgang Denk 
93*a6826fbcSWolfgang Denk extern ssize_t hexport(const char __sep, char **__resp, size_t __size);
94*a6826fbcSWolfgang Denk extern ssize_t hexport_r(struct hsearch_data *__htab,
95*a6826fbcSWolfgang Denk 		     const char __sep, char **__resp, size_t __size);
96*a6826fbcSWolfgang Denk 
97*a6826fbcSWolfgang Denk extern int himport(const char *__env, size_t __size, const char __sep,
98*a6826fbcSWolfgang Denk 		   int __flag);
99*a6826fbcSWolfgang Denk extern int himport_r(struct hsearch_data *__htab,
100*a6826fbcSWolfgang Denk 		     const char *__env, size_t __size, const char __sep,
101*a6826fbcSWolfgang Denk 		     int __flag);
102*a6826fbcSWolfgang Denk 
103*a6826fbcSWolfgang Denk /* Flags for himport() / himport_r() */
104*a6826fbcSWolfgang Denk #define	H_NOCLEAR	1	/* do not clear hash table before importing */
105*a6826fbcSWolfgang Denk 
106*a6826fbcSWolfgang Denk #endif /* search.h */
107