libmicrohttpd

HTTP/1.x server C library (MHD 1.x, stable)
Log | Files | Refs | Submodules | README | LICENSE

commit 8731a130e0eee35b2fb4e7db3c4f9c328ca1712c
parent 9d25d25ed3eae4a58cdfca4ed80dcee30468f843
Author: Evgeny Grin (Karlson2k) <k2k@narod.ru>
Date:   Sun,  6 Sep 2015 16:01:56 +0000

Update built-in tsearch replacement

Diffstat:
Msrc/microhttpd/tsearch.c | 37++++++++++++++++++-------------------
Msrc/microhttpd/tsearch.h | 42++++++++----------------------------------
2 files changed, 26 insertions(+), 53 deletions(-)

diff --git a/src/microhttpd/tsearch.c b/src/microhttpd/tsearch.c @@ -1,5 +1,3 @@ -/* $NetBSD: tsearch.c,v 1.3 1999/09/16 11:45:37 lukem Exp $ */ - /* * Tree search generalized from Knuth (6.2.2) Algorithm T just like * the AT&T man page says. @@ -11,19 +9,20 @@ * Totally public domain. */ -#ifndef _MSC_FULL_VER -#include <sys/cdefs.h> -#endif /*! _MSC_FULL_VER */ -#define _SEARCH_PRIVATE #include "tsearch.h" #include <stdlib.h> +typedef struct node { + const void *key; + struct node *llink, *rlink; +} node_t; + +/* $NetBSD: tsearch.c,v 1.5 2005/11/29 03:12:00 christos Exp $ */ /* find or insert datum into search tree */ void * -tsearch(vkey, vrootp, compar) - const void *vkey; /* key to be located */ - void **vrootp; /* address of tree root */ - int (*compar)(const void *, const void *); +tsearch(const void *vkey, /* key to be located */ + void **vrootp, /* address of tree root */ + int (*compar)(const void *, const void *)) { node_t *q; node_t **rootp = (node_t **)vrootp; @@ -43,23 +42,22 @@ tsearch(vkey, vrootp, compar) } q = malloc(sizeof(node_t)); /* T5: key not found */ - if (q != 0) { /* make new node */ + if (q) { /* make new node */ *rootp = q; /* link new node to old */ - /* LINTED const castaway ok */ - q->key = (void *)vkey; /* initialize new node */ + q->key = vkey; /* initialize new node */ q->llink = q->rlink = NULL; } return q; } -/* find a node, or return 0 */ +/* $NetBSD: tfind.c,v 1.5 2005/03/23 08:16:53 kleink Exp $ */ +/* find a node, or return NULL */ void * -tfind(vkey, vrootp, compar) - const void *vkey; /* key to be found */ - void * const *vrootp; /* address of the tree root */ - int (*compar)(const void *, const void *); +tfind(const void *vkey, /* key to be found */ + void * const *vrootp, /* address of the tree root */ + int (*compar)(const void *, const void *)) { - node_t **rootp = (node_t **)vrootp; + node_t * const *rootp = (node_t * const*)vrootp; if (rootp == NULL) return NULL; @@ -76,6 +74,7 @@ tfind(vkey, vrootp, compar) return NULL; } +/* $NetBSD: tdelete.c,v 1.2 1999/09/16 11:45:37 lukem Exp $ */ /* * delete node with given key * diff --git a/src/microhttpd/tsearch.h b/src/microhttpd/tsearch.h @@ -6,45 +6,19 @@ * $FreeBSD: release/9.0.0/include/search.h 105250 2002-10-16 14:29:23Z robert $ */ -#ifndef _SEARCH_H_ -#define _SEARCH_H_ +#ifndef _TSEARCH_H_ +#define _TSEARCH_H_ -#ifndef _MSC_FULL_VER -#include <sys/cdefs.h> -#endif /* _MSC_FULL_VER */ -#if !defined(__BEGIN_DECLS) || !defined(__END_DECLS) #if defined(__cplusplus) -#define __BEGIN_DECLS extern "C" { -#define __END_DECLS }; -#else /* !__cplusplus */ -#define __BEGIN_DECLS -#define __END_DECLS -#endif /* !__cplusplus */ -#endif /* !__BEGIN_DECLS || !__END_DECLS */ -#include <sys/types.h> - -typedef enum { - preorder, - postorder, - endorder, - leaf -} VISIT; - -#ifdef _SEARCH_PRIVATE -typedef struct node { - char *key; - struct node *llink, *rlink; -} node_t; -#endif - -__BEGIN_DECLS +extern "C" { +#endif /* __cplusplus */ void *tdelete(const void * __restrict, void ** __restrict, int (*)(const void *, const void *)); void *tfind(const void *, void * const *, int (*)(const void *, const void *)); void *tsearch(const void *, void **, int (*)(const void *, const void *)); -void twalk(const void *, void (*)(const void *, VISIT, int)); -void tdestroy(void *, void (*)(void *)); -__END_DECLS +#if defined(__cplusplus) +}; +#endif /* __cplusplus */ -#endif /* !_SEARCH_H_ */ +#endif /* !_TSEARCH_H_ */