commit e00d0f1ac3c70571d650bc8ad5c24c3107ef0659
Author: Oswald Buddenhagen <[email protected]>
Date: Thu Mar 26 17:16:37 2015 +0100
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
@@ -355,15 +355,20 @@ nfrealloc( void *mem, size_t sz )
}
char *
-nfstrdup( const char *str )
+nfstrndup( const char *str, size_t nchars )
{
- char *ret;
-
- if (!(ret = strdup( str )))
- oom();
+ char *ret = nfmalloc( nchars + 1 );
+ memcpy( ret, str, nchars );
+ ret[nchars] = 0;
return ret;
}
+char *
+nfstrdup( const char *str )
+{
+ return nfstrndup( str, strlen( str ) );
+}
+
int
nfvasprintf( char **str, const char *fmt, va_list va )
{
@@ -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
------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
isync-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/isync-devel