"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/maxminddb-compat-util.h" between
libmaxminddb-1.5.0.tar.gz and libmaxminddb-1.5.2.tar.gz

About: libmaxminddb is a library that provides functions for working with MaxMind DB files (free GeoLite 2 or commercial GeoIP2).

maxminddb-compat-util.h  (libmaxminddb-1.5.0):maxminddb-compat-util.h  (libmaxminddb-1.5.2)
skipping to change at line 46 skipping to change at line 46
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
static void * static void *
mmdb_memmem(const void *l, size_t l_len, const void *s, size_t s_len) mmdb_memmem(const void *l, size_t l_len, const void *s, size_t s_len) {
{ register char *cur, *last;
register char *cur, *last; const char *cl = (const char *)l;
const char *cl = (const char *)l; const char *cs = (const char *)s;
const char *cs = (const char *)s;
/* we need something to compare */
/* we need something to compare */ if (l_len == 0 || s_len == 0)
if (l_len == 0 || s_len == 0) return NULL;
return NULL;
/* "s" must be smaller or equal to "l" */
/* "s" must be smaller or equal to "l" */ if (l_len < s_len)
if (l_len < s_len) return NULL;
return NULL;
/* special case where s_len == 1 */
/* special case where s_len == 1 */ if (s_len == 1)
if (s_len == 1) return memchr(l, (int)*cs, l_len);
return memchr(l, (int)*cs, l_len);
/* the last position where its possible to find "s" in "l" */
/* the last position where its possible to find "s" in "l" */ last = (char *)cl + l_len - s_len;
last = (char *)cl + l_len - s_len;
for (cur = (char *)cl; cur <= last; cur++)
for (cur = (char *)cl; cur <= last; cur++) if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0)
if (cur[0] == cs[0] && memcmp(cur, cs, s_len) == 0) return cur;
return cur;
return NULL; return NULL;
} }
/* Applies to strnlen implementation */ /* Applies to strnlen implementation */
/*- /*-
* Copyright (c) 2009 David Schultz <das@FreeBSD.org> * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
skipping to change at line 100 skipping to change at line 99
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
static size_t static size_t mmdb_strnlen(const char *s, size_t maxlen) {
mmdb_strnlen(const char *s, size_t maxlen) size_t len;
{
size_t len; for (len = 0; len < maxlen; len++, s++) {
if (!*s)
for (len = 0; len < maxlen; len++, s++) { break;
if (!*s) }
break; return (len);
}
return (len);
} }
/* Applies to strdup and strndup implementation */ /* Applies to strdup and strndup implementation */
/* /*
* Copyright (c) 1988, 1993 * Copyright (c) 1988, 1993
* The Regents of the University of California. All rights reserved. * The Regents of the University of California. All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
* are met: * are met:
skipping to change at line 141 skipping to change at line 138
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*/ */
static char * static char *mmdb_strdup(const char *str) {
mmdb_strdup(const char *str) size_t len;
{ char *copy;
size_t len;
char *copy; len = strlen(str) + 1;
if ((copy = malloc(len)) == NULL)
len = strlen(str) + 1; return (NULL);
if ((copy = malloc(len)) == NULL) memcpy(copy, str, len);
return (NULL); return (copy);
memcpy(copy, str, len);
return (copy);
} }
static char * static char *mmdb_strndup(const char *str, size_t n) {
mmdb_strndup(const char *str, size_t n) size_t len;
{ char *copy;
size_t len;
char *copy; len = mmdb_strnlen(str, n);
if ((copy = malloc(len + 1)) == NULL)
len = mmdb_strnlen(str, n); return (NULL);
if ((copy = malloc(len + 1)) == NULL) memcpy(copy, str, len);
return (NULL); copy[len] = '\0';
memcpy(copy, str, len); return (copy);
copy[len] = '\0';
return (copy);
} }
/* *INDENT-ON* */ /* *INDENT-ON* */
 End of changes. 5 change blocks. 
58 lines changed or deleted 51 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)