From: Richard Russon Date: Wed, 11 Jan 2017 13:18:18 +0000 (+0000) Subject: notmuch: drop strndup, replace with mutt_substrdup X-Git-Tag: neomutt-20170113~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4d682320acc237b86b44a26973071d2a1c05360;p=neomutt notmuch: drop strndup, replace with mutt_substrdup Closes: #242 --- diff --git a/configure.ac b/configure.ac index 37c856db1..bf0334dca 100644 --- a/configure.ac +++ b/configure.ac @@ -492,7 +492,7 @@ AC_CHECK_TYPE(ssize_t, int) AC_CHECK_FUNCS(fgetpos memmove setegid srand48 strerror) -AC_REPLACE_FUNCS([setenv strcasecmp strdup strndup strnlen strsep strtok_r wcscasecmp]) +AC_REPLACE_FUNCS([setenv strcasecmp strdup strsep strtok_r wcscasecmp]) AC_REPLACE_FUNCS([strcasestr mkdtemp]) AC_CHECK_FUNC(getopt) diff --git a/mutt_notmuch.c b/mutt_notmuch.c index 08a47c3d5..35210329c 100644 --- a/mutt_notmuch.c +++ b/mutt_notmuch.c @@ -150,7 +150,7 @@ static int url_parse_query(char *url, char **filename, struct uri_tag **tags) e = strchr(p, '?'); - *filename = e ? e == p ? NULL : strndup(p, e - p) : safe_strdup(p); + *filename = e ? e == p ? NULL : mutt_substrdup(p, e) : safe_strdup(p); if (!e) return 0; /* only filename */ @@ -175,7 +175,7 @@ static int url_parse_query(char *url, char **filename, struct uri_tag **tags) e = strchr(p, '='); if (!e) e = strchr(p, '&'); - tag->name = e ? strndup(p, e - p) : safe_strdup(p); + tag->name = e ? mutt_substrdup(p, e) : safe_strdup(p); if (!tag->name || url_pct_decode(tag->name) < 0) goto err; if (!e) @@ -187,7 +187,7 @@ static int url_parse_query(char *url, char **filename, struct uri_tag **tags) continue; e = strchr(p, '&'); - tag->value = e ? strndup(p, e - p) : safe_strdup(p); + tag->value = e ? mutt_substrdup(p, e) : safe_strdup(p); if (!tag->value || url_pct_decode(tag->value) < 0) goto err; if (!e) @@ -787,7 +787,7 @@ static int update_message_path(HEADER *h, const char *path) for (; p > path && *(p - 1) == '/'; p--); - data->folder = strndup(path, p - path); + data->folder = mutt_substrdup(path, p); dprint(2, (debugfile, "nm: folder='%s', file='%s'\n", data->folder, h->path)); return 0; @@ -808,7 +808,7 @@ static char *get_folder_from_path(const char *path) p -= 3; for (; p > path && *(p - 1) == '/'; p--); - return strndup(path, p - path); + return mutt_substrdup(path, p); } return NULL; diff --git a/protos.h b/protos.h index 9ee839338..4c636b1d1 100644 --- a/protos.h +++ b/protos.h @@ -597,10 +597,3 @@ char *strcasestr (const char *, const char *); char *mkdtemp (char *tmpl); #endif -#ifndef HAVE_STRNLEN -size_t strnlen(const char *s, size_t maxlen); -#endif - -#ifndef strndup -char *strndup(const char *s, size_t n); -#endif diff --git a/strndup.c b/strndup.c deleted file mode 100644 index 7e395389e..000000000 --- a/strndup.c +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (C) 2013 Karel Zak - */ - -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include "mutt.h" - -char *strndup(const char *s, size_t n) -{ - size_t len = strnlen(s, n); - char *new = malloc((len + 1) * sizeof(char)); /* __MEM_CHECKED__ */ - if (!new) - return NULL; - new[len] = '\0'; - return (char *) memcpy(new, s, len); -} diff --git a/strnlen.c b/strnlen.c deleted file mode 100644 index 278a988d7..000000000 --- a/strnlen.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright (C) 2013 Karel Zak - */ - -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include "mutt.h" - -size_t strnlen(const char *s, size_t maxlen) -{ - int i; - - for (i = 0; i < maxlen; i++) { - if (s[i] == '\0') - return i + 1; - } - return maxlen; -}