[pacman-dev] [PATCH] Removing strndup and a small typo fix
Code cleaning, removing strndup, because it's available with glibc in the same manner, and a small typo fix. Signed-off-by: Laszlo Papp <djszapi2@gmail.com> --- src/pacman/package.c | 2 +- src/pacman/util.c | 12 ------------ src/pacman/util.h | 4 ---- 3 files changed, 1 insertions(+), 17 deletions(-) diff --git a/src/pacman/package.c b/src/pacman/package.c index 328d5bf..3b14516 100644 --- a/src/pacman/package.c +++ b/src/pacman/package.c @@ -84,7 +84,7 @@ void dump_pkg_full(pmpkg_t *pkg, int level) } if(level>0) { - /* compute this here so we don't get a puase in the middle of output */ + /* compute this here so we don't get a pause in the middle of output */ requiredby = alpm_pkg_compute_requiredby(pkg); } diff --git a/src/pacman/util.c b/src/pacman/util.c index a02b43c..a95d82e 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -819,18 +819,6 @@ static size_t strnlen(const char *s, size_t max) for(p = s; *p && max--; ++p); return(p - s); } - -char *strndup(const char *s, size_t n) -{ - size_t len = strnlen(s, n); - char *new = (char *) malloc(len + 1); - - if (new == NULL) - return NULL; - - new[len] = '\0'; - return (char *) memcpy(new, s, len); -} #endif /* vim: set ts=2 sw=2 noet: */ diff --git a/src/pacman/util.h b/src/pacman/util.h index 1282422..ce5e019 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -64,10 +64,6 @@ int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attr int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0))); -#ifndef HAVE_STRNDUP -char *strndup(const char *s, size_t n); -#endif - #endif /* _PM_UTIL_H */ /* vim: set ts=2 sw=2 noet: */ -- 1.6.4.1
Laszlo Papp wrote:
Code cleaning, removing strndup, because it's available with glibc in the same manner, and a small typo fix.
Signed-off-by: Laszlo Papp <djszapi2@gmail.com> --- <snip>
-#ifndef HAVE_STRNDUP -char *strndup(const char *s, size_t n); -#endif - #endif /* _PM_UTIL_H */
I believe that strndup is a GNU library extension so is not universally supported. Hence the #ifndef here. Has this changed since the original commit (581769b7)? Allan
On Tue, Sep 1, 2009 at 8:49 PM, Allan McRae<allan@archlinux.org> wrote:
Laszlo Papp wrote:
Code cleaning, removing strndup, because it's available with glibc in the same manner, and a small typo fix.
Signed-off-by: Laszlo Papp <djszapi2@gmail.com> --- <snip> -#ifndef HAVE_STRNDUP -char *strndup(const char *s, size_t n); -#endif - #endif /* _PM_UTIL_H */
I believe that strndup is a GNU library extension so is not universally supported. Hence the #ifndef here. Has this changed since the original commit (581769b7)?
You are correct; glibc has this but other OSes (e.g. BSD, cygwin, darwin) may lack the srtnlen and strndup functions so we provide an alternative. No reason to remove them. The comment change in the other file also appears to be unrelated to this commit. By the way, don't take these as discouraging remarks towards submitting patches, as we do appreciate them- we just have a review process as well that doesn't accept everything we receive at face value. The commit Allan referenced was most likely added to get pacman to compile on cygwin as an FYI, since I had a Windows machine for my work use at the time. -Dan
On Wed, Sep 2, 2009 at 6:05 AM, Dan McGee <dpmcgee@gmail.com> wrote:
On Tue, Sep 1, 2009 at 8:49 PM, Allan McRae<allan@archlinux.org> wrote:
Laszlo Papp wrote:
Code cleaning, removing strndup, because it's available with glibc in the same manner, and a small typo fix.
Signed-off-by: Laszlo Papp <djszapi2@gmail.com> --- <snip> -#ifndef HAVE_STRNDUP -char *strndup(const char *s, size_t n); -#endif - #endif /* _PM_UTIL_H */
I believe that strndup is a GNU library extension so is not universally supported. Hence the #ifndef here. Has this changed since the original commit (581769b7)?
You are correct; glibc has this but other OSes (e.g. BSD, cygwin, darwin) may lack the srtnlen and strndup functions so we provide an alternative. No reason to remove them.
The comment change in the other file also appears to be unrelated to this commit. By the way, don't take these as discouraging remarks towards submitting patches, as we do appreciate them- we just have a review process as well that doesn't accept everything we receive at face value.
The commit Allan referenced was most likely added to get pacman to compile on cygwin as an FYI, since I had a Windows machine for my work use at the time.
-Dan
Ah, okay, in this case sorry, you're right! Best Regards, Laszlo Papp
participants (3)
-
Allan McRae
-
Dan McGee
-
Laszlo Papp