Git-Url: http://git.frugalware.org/gitweb/gitweb.cgi?p=fwsetup-ng.git;a=commitdiff;h=5ddbf40b6127d765efa9f1b12b70cf6240abaf55
commit 5ddbf40b6127d765efa9f1b12b70cf6240abaf55 Author: James Buren <[email protected]> Date: Fri Sep 7 07:06:20 2012 -0500 add function for getting list of timezones diff --git a/src/local.h b/src/local.h index 43177ee..f1c6031 100644 --- a/src/local.h +++ b/src/local.h @@ -6,6 +6,7 @@ #include <string.h> #include <unistd.h> #include <fcntl.h> +#include <ftw.h> #include <sys/stat.h> #include <sys/time.h> #include <sys/wait.h> diff --git a/src/postconfig.c b/src/postconfig.c index b6dfd85..2364c95 100644 --- a/src/postconfig.c +++ b/src/postconfig.c @@ -1,5 +1,12 @@ #include "local.h" +#define TZSEARCHDIR "usr/share/zoneinfo/posix" +#define TZSEARCHSIZE (sizeof(TZSEARCHDIR)-1) + +static size_t tz_size = 0; +static size_t tz_count = 0; +static char **tz_data = 0; + static bool is_root_setup(void) { FILE *file = 0; @@ -145,6 +152,55 @@ static void account_free(struct account *account) memset(account,0,sizeof(struct account)); } +static int timezone_nftw_callback(const char *path,const struct stat *st,int type,struct FTW *fb) +{ + if(type == FTW_D || type == FTW_DP) + return 0; + + if(tz_data == 0) + { + ++tz_size; + } + else + { + tz_data[tz_count] = strdup(path + TZSEARCHSIZE + 1); + ++tz_count; + } + + return 0; +} + +static int timezone_cmp_callback(const void *a,const void *b) +{ + const char *A = *(const char **) a; + const char *B = *(const char **) b; + + return strcmp(A,B); +} + +static bool get_timezone_data(void) +{ + if(nftw(TZSEARCHDIR,timezone_nftw_callback,512,FTW_DEPTH|FTW_PHYS) == -1) + { + fprintf(logfile,"%s: %s\n",__func__,strerror(errno)); + return false; + } + + tz_data = malloc(sizeof(char *) * (tz_size + 1)); + + if(nftw(TZSEARCHDIR,timezone_nftw_callback,512,FTW_DEPTH|FTW_PHYS) == -1) + { + fprintf(logfile,"%s: %s\n",__func__,strerror(errno)); + return false; + } + + tz_data[tz_size] = 0; + + qsort(tz_data,tz_size,sizeof(char *),timezone_cmp_callback); + + return true; +} + static bool postconfig_run(void) { struct account account = {0}; @@ -212,6 +268,19 @@ static bool postconfig_run(void) static void postconfig_reset(void) { + tz_size = 0; + + tz_count = 0; + + if(tz_data != 0) + { + for( size_t i = 0 ; tz_data[i] != 0 ; ++i ) + free(tz_data[i]); + + free(tz_data); + + tz_data = 0; + } } struct module postconfig_module = _______________________________________________ Frugalware-git mailing list [email protected] http://frugalware.org/mailman/listinfo/frugalware-git
