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