Browse Source

static my_strndup() => extern nfstrndup()

wip/server-refactor
Oswald Buddenhagen 10 years ago
parent
commit
e00d0f1ac3
  1. 1
      src/common.h
  2. 26
      src/util.c

1
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, ... );

26
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

Loading…
Cancel
Save