Deleted Added
full compact
dbm_map.c (316420) dbm_map.c (322249)
1/* $Id: dbm_map.c,v 1.7 2016/10/22 10:09:27 schwarze Exp $ */
1/* $Id: dbm_map.c,v 1.8 2017/02/17 14:43:54 schwarze Exp $ */
2/*
3 * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 160 unchanged lines hidden (view full) ---

170 * The reverse of dbm_get().
171 * Take pointer into the database file
172 * and convert it to the raw integer
173 * that would be used to refer to that place in the file.
174 */
175int32_t
176dbm_addr(const void *p)
177{
2/*
3 * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES

--- 160 unchanged lines hidden (view full) ---

170 * The reverse of dbm_get().
171 * Take pointer into the database file
172 * and convert it to the raw integer
173 * that would be used to refer to that place in the file.
174 */
175int32_t
176dbm_addr(const void *p)
177{
178 return htobe32((char *)p - dbm_base);
178 return htobe32((const char *)p - dbm_base);
179}
180
181int
182dbm_match(const struct dbm_match *match, const char *str)
183{
184 switch (match->type) {
185 case DBM_EXACT:
186 return strcmp(str, match->str) == 0;
187 case DBM_SUB:
188 return strcasestr(str, match->str) != NULL;
189 case DBM_REGEX:
190 return regexec(match->re, str, 0, NULL, 0) == 0;
191 default:
192 abort();
193 }
194}
179}
180
181int
182dbm_match(const struct dbm_match *match, const char *str)
183{
184 switch (match->type) {
185 case DBM_EXACT:
186 return strcmp(str, match->str) == 0;
187 case DBM_SUB:
188 return strcasestr(str, match->str) != NULL;
189 case DBM_REGEX:
190 return regexec(match->re, str, 0, NULL, 0) == 0;
191 default:
192 abort();
193 }
194}