Blame view

include/search.h 4.11 KB
83d290c56   Tom Rini   SPDX: Convert all...
1
  /* SPDX-License-Identifier: LGPL-2.1+ */
a6826fbc5   Wolfgang Denk   Add hash table su...
2
3
4
5
  /*
   * Declarations for System V style searching functions.
   * Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
   * This file is part of the GNU C Library.
a6826fbc5   Wolfgang Denk   Add hash table su...
6
7
8
9
10
   */
  
  /*
   * Based on code from uClibc-0.9.30.3
   * Extensions for use within U-Boot
ea009d474   Wolfgang Denk   hashtable: prepar...
11
   * Copyright (C) 2010-2013 Wolfgang Denk <wd@denx.de>
a6826fbc5   Wolfgang Denk   Add hash table su...
12
   */
362664356   Robert P. J. Day   search.h: Numerou...
13
14
  #ifndef _SEARCH_H_
  #define _SEARCH_H_
a6826fbc5   Wolfgang Denk   Add hash table su...
15
16
17
18
  
  #include <stddef.h>
  
  #define __set_errno(val) do { errno = val; } while (0)
7afcf3a55   Joe Hershberger   env: Refactor app...
19
20
21
22
23
  enum env_op {
  	env_op_create,
  	env_op_delete,
  	env_op_overwrite,
  };
362664356   Robert P. J. Day   search.h: Numerou...
24
  /* Action which shall be performed in the call to hsearch.  */
a6826fbc5   Wolfgang Denk   Add hash table su...
25
26
27
28
29
30
  typedef enum {
  	FIND,
  	ENTER
  } ACTION;
  
  typedef struct entry {
84b5e8022   Wolfgang Denk   Constify getenv()...
31
  	const char *key;
a6826fbc5   Wolfgang Denk   Add hash table su...
32
  	char *data;
170ab1107   Joe Hershberger   env: Add support ...
33
34
  	int (*callback)(const char *name, const char *value, enum env_op op,
  		int flags);
2598090b7   Joe Hershberger   env: Add environm...
35
  	int flags;
a6826fbc5   Wolfgang Denk   Add hash table su...
36
37
38
39
40
41
42
43
  } ENTRY;
  
  /* Opaque type for internal use.  */
  struct _ENTRY;
  
  /*
   * Family of hash table handling functions.  The functions also
   * have reentrant counterparts ending with _r.  The non-reentrant
362664356   Robert P. J. Day   search.h: Numerou...
44
   * functions all work on a single internal hash table.
a6826fbc5   Wolfgang Denk   Add hash table su...
45
46
47
48
49
50
51
   */
  
  /* Data type for reentrant functions.  */
  struct hsearch_data {
  	struct _ENTRY *table;
  	unsigned int size;
  	unsigned int filled;
c5983592e   Gerlando Falauto   env: add check/ap...
52
53
  /*
   * Callback function which will check whether the given change for variable
362664356   Robert P. J. Day   search.h: Numerou...
54
   * "__item" to "newval" may be applied or not, and possibly apply such change.
c5983592e   Gerlando Falauto   env: add check/ap...
55
56
   * When (flag & H_FORCE) is set, it shall not print out any error message and
   * shall force overwriting of write-once variables.
362664356   Robert P. J. Day   search.h: Numerou...
57
   * Must return 0 for approval, 1 for denial.
c5983592e   Gerlando Falauto   env: add check/ap...
58
   */
7afcf3a55   Joe Hershberger   env: Refactor app...
59
60
  	int (*change_ok)(const ENTRY *__item, const char *newval, enum env_op,
  		int flag);
a6826fbc5   Wolfgang Denk   Add hash table su...
61
  };
362664356   Robert P. J. Day   search.h: Numerou...
62
  /* Create a new hash table which will contain at most "__nel" elements.  */
a6826fbc5   Wolfgang Denk   Add hash table su...
63
  extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
362664356   Robert P. J. Day   search.h: Numerou...
64
  /* Destroy current internal hash table.  */
c4e0057fa   Joe Hershberger   env: Refactor do_...
65
  extern void hdestroy_r(struct hsearch_data *__htab);
a6826fbc5   Wolfgang Denk   Add hash table su...
66
67
  
  /*
362664356   Robert P. J. Day   search.h: Numerou...
68
   * Search for entry matching __item.key in internal hash table.  If
a6826fbc5   Wolfgang Denk   Add hash table su...
69
70
   * ACTION is `FIND' return found entry or signal error by returning
   * NULL.  If ACTION is `ENTER' replace existing data (if any) with
362664356   Robert P. J. Day   search.h: Numerou...
71
   * __item.data.
a6826fbc5   Wolfgang Denk   Add hash table su...
72
   * */
a6826fbc5   Wolfgang Denk   Add hash table su...
73
  extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
c4e0057fa   Joe Hershberger   env: Refactor do_...
74
  		     struct hsearch_data *__htab, int __flag);
a6826fbc5   Wolfgang Denk   Add hash table su...
75

560d424b6   Mike Frysinger   env: re-add suppo...
76
  /*
362664356   Robert P. J. Day   search.h: Numerou...
77
   * Search for an entry matching "__match".  Otherwise, Same semantics
560d424b6   Mike Frysinger   env: re-add suppo...
78
79
80
81
   * as hsearch_r().
   */
  extern int hmatch_r(const char *__match, int __last_idx, ENTRY ** __retval,
  		    struct hsearch_data *__htab);
362664356   Robert P. J. Day   search.h: Numerou...
82
  /* Search and delete entry matching "__key" in internal hash table. */
152874b65   Gerlando Falauto   env: check and ap...
83
  extern int hdelete_r(const char *__key, struct hsearch_data *__htab,
c4e0057fa   Joe Hershberger   env: Refactor do_...
84
  		     int __flag);
a6826fbc5   Wolfgang Denk   Add hash table su...
85

a6826fbc5   Wolfgang Denk   Add hash table su...
86
  extern ssize_t hexport_r(struct hsearch_data *__htab,
be11235ab   Joe Hershberger   env: Hide '.' var...
87
  		     const char __sep, int __flag, char **__resp, size_t __size,
37f2fe747   Wolfgang Denk   env: allow to exp...
88
  		     int argc, char * const argv[]);
a6826fbc5   Wolfgang Denk   Add hash table su...
89

348b1f1c6   Gerlando Falauto   env: make himport...
90
91
92
93
  /*
   * nvars: length of vars array
   * vars: array of strings (variable names) to import (nvars == 0 means all)
   */
a6826fbc5   Wolfgang Denk   Add hash table su...
94
95
  extern int himport_r(struct hsearch_data *__htab,
  		     const char *__env, size_t __size, const char __sep,
ecd1446fe   Alexander Holler   Add option -r to ...
96
97
  		     int __flag, int __crlf_is_lf, int nvars,
  		     char * const vars[]);
a6826fbc5   Wolfgang Denk   Add hash table su...
98

170ab1107   Joe Hershberger   env: Add support ...
99
100
  /* Walk the whole table calling the callback on each element */
  extern int hwalk_r(struct hsearch_data *__htab, int (*callback)(ENTRY *));
be11235ab   Joe Hershberger   env: Hide '.' var...
101
  /* Flags for himport_r(), hexport_r(), hdelete_r(), and hsearch_r() */
c4e0057fa   Joe Hershberger   env: Refactor do_...
102
103
104
  #define H_NOCLEAR	(1 << 0) /* do not clear hash table before importing */
  #define H_FORCE		(1 << 1) /* overwrite read-only/write-once variables */
  #define H_INTERACTIVE	(1 << 2) /* indicate that an import is user directed */
be11235ab   Joe Hershberger   env: Hide '.' var...
105
  #define H_HIDE_DOT	(1 << 3) /* don't print env vars that begin with '.' */
ea009d474   Wolfgang Denk   hashtable: prepar...
106
107
108
109
  #define H_MATCH_KEY	(1 << 4) /* search/grep key  = variable names	     */
  #define H_MATCH_DATA	(1 << 5) /* search/grep data = variable values	     */
  #define H_MATCH_BOTH	(H_MATCH_KEY | H_MATCH_DATA) /* search/grep both     */
  #define H_MATCH_IDENT	(1 << 6) /* search for indentical strings	     */
be29df6a1   Wolfgang Denk   "env grep" - add ...
110
111
112
  #define H_MATCH_SUBSTR	(1 << 7) /* search for substring matches	     */
  #define H_MATCH_REGEX	(1 << 8) /* search for regular expression matches    */
  #define H_MATCH_METHOD	(H_MATCH_IDENT | H_MATCH_SUBSTR | H_MATCH_REGEX)
382bee57f   Simon Glass   env: Rename seten...
113
  #define H_PROGRAMMATIC	(1 << 9) /* indicate that an import is from env_set() */
94b467b14   Joe Hershberger   env: Distinguish ...
114
  #define H_ORIGIN_FLAGS	(H_INTERACTIVE | H_PROGRAMMATIC)
a6826fbc5   Wolfgang Denk   Add hash table su...
115

362664356   Robert P. J. Day   search.h: Numerou...
116
  #endif /* _SEARCH_H_ */