From 68ea0f43533096d5c46bad4aee6e5d5864307f4a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 12 Dec 1997 12:03:58 +0000 Subject: added option file handling --- util/fileutil.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'util/fileutil.c') diff --git a/util/fileutil.c b/util/fileutil.c index e2ea9b20e..28bd866c5 100644 --- a/util/fileutil.c +++ b/util/fileutil.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -29,3 +30,37 @@ #include "ttyio.h" +/**************** + * Construct a filename form the NULL terminated list of parts. + * Tilde expansion is done here. + */ +char * +make_filename( const char *first_part, ... ) +{ + va_list arg_ptr ; + size_t n; + const char *s; + char *name, *home, *p; + + va_start( arg_ptr, first_part ) ; + n = strlen(first_part)+1; + while( (s=va_arg(arg_ptr, const char *)) ) + n += strlen(s) + 1; + va_end(arg_ptr); + + home = NULL; + if( *first_part == '~' && first_part[1] == '/' + && (home = getenv("HOME")) && *home ) + n += strlen(home); + + name = m_alloc(n); + p = home ? stpcpy(stpcpy(name,home), first_part+1) + : stpcpy(name, first_part); + va_start( arg_ptr, first_part ) ; + while( (s=va_arg(arg_ptr, const char *)) ) + p = stpcpy(stpcpy(p,"/"), s); + va_end(arg_ptr); + + return name; +} + -- cgit