move expand_strdup() to config.c

it's not really a generic function.
This commit is contained in:
Oswald Buddenhagen 2022-02-08 15:02:15 +01:00
parent 7d02d6c1fe
commit 603e740b63
4 changed files with 36 additions and 36 deletions

View File

@ -184,8 +184,6 @@ int ATTR_PRINTFLIKE(3, 4) nfsnprintf( char *buf, int blen, const char *fmt, ...
void ATTR_NORETURN oob( void );
void ATTR_NORETURN oom( void );
char *expand_strdup( const char *s );
int map_name( const char *arg, char **result, uint reserve, const char *in, const char *out );
#define DEFINE_ARRAY_TYPE(T) \

View File

@ -20,6 +20,40 @@ char FieldDelimiter = ':';
static store_conf_t *stores;
char *
expand_strdup( const char *s )
{
struct passwd *pw;
const char *p, *q;
char *r;
if (*s == '~') {
s++;
if (!*s) {
p = NULL;
q = Home;
} else if (*s == '/') {
p = s;
q = Home;
} else {
if ((p = strchr( s, '/' ))) {
r = nfstrndup( s, (size_t)(p - s) );
pw = getpwnam( r );
free( r );
} else {
pw = getpwnam( s );
}
if (!pw)
return NULL;
q = pw->pw_dir;
}
nfasprintf( &r, "%s%s", q, p ? p : "" );
return r;
} else {
return nfstrdup( s );
}
}
char *
get_arg( conffile_t *cfile, int required, int *comment )
{

View File

@ -26,6 +26,8 @@ extern char FieldDelimiter;
#define ARG_OPTIONAL 0
#define ARG_REQUIRED 1
char *expand_strdup( const char *s );
char *get_arg( conffile_t *cfile, int required, int *comment );
char parse_bool( conffile_t *cfile );

View File

@ -480,40 +480,6 @@ cur_user( void )
}
*/
char *
expand_strdup( const char *s )
{
struct passwd *pw;
const char *p, *q;
char *r;
if (*s == '~') {
s++;
if (!*s) {
p = NULL;
q = Home;
} else if (*s == '/') {
p = s;
q = Home;
} else {
if ((p = strchr( s, '/' ))) {
r = nfstrndup( s, (size_t)(p - s) );
pw = getpwnam( r );
free( r );
} else {
pw = getpwnam( s );
}
if (!pw)
return NULL;
q = pw->pw_dir;
}
nfasprintf( &r, "%s%s", q, p ? p : "" );
return r;
} else {
return nfstrdup( s );
}
}
/* Return value: 0 = ok, -1 = out found in arg, -2 = in found in arg but no out specified */
int
map_name( const char *arg, char **result, uint reserve, const char *in, const char *out )