commit 603e740b63d4d9828ddbf350788071c5d6cef05d
parent 7d02d6c1fe57e6abaa1bf03b27c2ed1487aef71f
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date: Tue, 8 Feb 2022 15:02:15 +0100
move expand_strdup() to config.c
it's not really a generic function.
Diffstat:
4 files changed, 36 insertions(+), 36 deletions(-)
diff --git a/src/common.h b/src/common.h
@@ -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) \
diff --git a/src/config.c b/src/config.c
@@ -21,6 +21,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 )
{
char *ret, *p, *t;
diff --git a/src/config.h b/src/config.h
@@ -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 );
diff --git a/src/util.c b/src/util.c
@@ -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 )