diff options
author | Guillem Jover <guillem@debian.org> | 2010-10-24 03:49:22 +0200 |
---|---|---|
committer | Guillem Jover <guillem@debian.org> | 2010-11-19 05:21:14 +0100 |
commit | e66836854ef51b5b5ce0b95a61adbf13f8dcd660 (patch) | |
tree | 589f75f5da71b820c42cc45cb3fc0e99a90eb02c /lib | |
parent | 8c234c5698645a759f6153fd1be4d7b90059bb88 (diff) | |
download | dpkg-e66836854ef51b5b5ce0b95a61adbf13f8dcd660.tar.gz |
libdpkg: Add new namevalue_find_by_name function
Diffstat (limited to 'lib')
-rw-r--r-- | lib/dpkg/Makefile.am | 1 | ||||
-rw-r--r-- | lib/dpkg/libdpkg.Versions | 3 | ||||
-rw-r--r-- | lib/dpkg/namevalue.c | 38 | ||||
-rw-r--r-- | lib/dpkg/namevalue.h | 5 |
4 files changed, 46 insertions, 1 deletions
diff --git a/lib/dpkg/Makefile.am b/lib/dpkg/Makefile.am index 160454967..9f2012546 100644 --- a/lib/dpkg/Makefile.am +++ b/lib/dpkg/Makefile.am @@ -41,6 +41,7 @@ libdpkg_a_SOURCES = \ md5.c md5.h \ mlib.c \ myopt.c \ + namevalue.c \ nfmalloc.c \ parse.c \ parsehelp.c \ diff --git a/lib/dpkg/libdpkg.Versions b/lib/dpkg/libdpkg.Versions index 319d89531..8bffb37da 100644 --- a/lib/dpkg/libdpkg.Versions +++ b/lib/dpkg/libdpkg.Versions @@ -77,6 +77,9 @@ LIBDPKG_PRIVATE { glob_list_prepend; glob_list_free; + # Data structure functions + namevalue_find_by_name; + # Buffer I/O functions buffer_init; buffer_read; diff --git a/lib/dpkg/namevalue.c b/lib/dpkg/namevalue.c new file mode 100644 index 000000000..f425c4cc0 --- /dev/null +++ b/lib/dpkg/namevalue.c @@ -0,0 +1,38 @@ +/* + * libdpkg - Debian packaging suite library routines + * namevalue.c - name value structure handling + * + * Copyright © 2010 Guillem Jover <guillem@debian.org> + * + * This is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#include <config.h> +#include <compat.h> + +#include <stddef.h> + +#include <dpkg/namevalue.h> + +const struct namevalue * +namevalue_find_by_name(const struct namevalue *head, const char *str) +{ + const struct namevalue *nv; + + for (nv = head; nv->name; nv++) + if (strncasecmp(str, nv->name, nv->length) == 0) + return nv; + + return NULL; +} diff --git a/lib/dpkg/namevalue.h b/lib/dpkg/namevalue.h index a512a4e21..c896e3ef5 100644 --- a/lib/dpkg/namevalue.h +++ b/lib/dpkg/namevalue.h @@ -3,7 +3,7 @@ * namevalue.h - name value structure handling * * Copyright © 1994,1995 Ian Jackson <ian@chiark.greenend.org.uk> - * Copyright © 2009 Guillem Jover <guillem@debian.org> + * Copyright © 2009-2010 Guillem Jover <guillem@debian.org> * * This is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,6 +35,9 @@ struct namevalue { #define NAMEVALUE_DEF(n, v) \ [v] = { .name = n, .value = v, .length = sizeof(n) - 1 } +const struct namevalue *namevalue_find_by_name(const struct namevalue *head, + const char *str); + DPKG_END_DECLS #endif /* LIBDPKG_NAMEVALUE_H */ |