From e00d0f1ac3c70571d650bc8ad5c24c3107ef0659 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Thu, 26 Mar 2015 17:16:37 +0100 Subject: [PATCH] static my_strndup() => extern nfstrndup() --- src/common.h | 1 + src/util.c | 26 +++++++++++--------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/common.h b/src/common.h index ed278b4..2863024 100644 --- a/src/common.h +++ b/src/common.h @@ -112,6 +112,7 @@ time_t timegm( struct tm *tm ); void *nfmalloc( size_t sz ); void *nfcalloc( size_t sz ); void *nfrealloc( void *mem, size_t sz ); +char *nfstrndup( const char *str, size_t nchars ); char *nfstrdup( const char *str ); int nfvasprintf( char **str, const char *fmt, va_list va ); int ATTR_PRINTFLIKE(2, 3) nfasprintf( char **str, const char *fmt, ... ); diff --git a/src/util.c b/src/util.c index 3511cc5..9c347fd 100644 --- a/src/util.c +++ b/src/util.c @@ -354,14 +354,19 @@ nfrealloc( void *mem, size_t sz ) return ret; } +char * +nfstrndup( const char *str, size_t nchars ) +{ + char *ret = nfmalloc( nchars + 1 ); + memcpy( ret, str, nchars ); + ret[nchars] = 0; + return ret; +} + char * nfstrdup( const char *str ) { - char *ret; - - if (!(ret = strdup( str ))) - oom(); - return ret; + return nfstrndup( str, strlen( str ) ); } int @@ -405,15 +410,6 @@ cur_user( void ) } */ -static char * -my_strndup( const char *s, size_t nchars ) -{ - char *r = nfmalloc( nchars + 1 ); - memcpy( r, s, nchars ); - r[nchars] = 0; - return r; -} - char * expand_strdup( const char *s ) { @@ -431,7 +427,7 @@ expand_strdup( const char *s ) q = Home; } else { if ((p = strchr( s, '/' ))) { - r = my_strndup( s, (int)(p - s) ); + r = nfstrndup( s, (int)(p - s) ); pw = getpwnam( r ); free( r ); } else