X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fdb_iterator.c;h=8af267bcb8559fb504b0be2f62692744b58f4dd6;hp=4e4a8aacf2c50e9b70b2e708be122419e7838e4d;hb=b0916ab669030bac5c8590c0d66e36e1b9b34e9b;hpb=cba932f979e14e49b63e06715e80f64d9ffe6e5e diff --git a/ncurses/tinfo/db_iterator.c b/ncurses/tinfo/db_iterator.c index 4e4a8aac..8af267bc 100644 --- a/ncurses/tinfo/db_iterator.c +++ b/ncurses/tinfo/db_iterator.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2006-2010,2011 Free Software Foundation, Inc. * + * Copyright (c) 2006-2011,2012 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -43,7 +43,7 @@ #include #endif -MODULE_ID("$Id: db_iterator.c,v 1.24 2011/12/10 19:48:07 tom Exp $") +MODULE_ID("$Id: db_iterator.c,v 1.31 2012/02/22 22:40:24 tom Exp $") #define HaveTicDirectory _nc_globals.have_tic_directory #define KeepTicDirectory _nc_globals.keep_tic_directory @@ -55,13 +55,15 @@ MODULE_ID("$Id: db_iterator.c,v 1.24 2011/12/10 19:48:07 tom Exp $") #define my_vars _nc_globals.dbd_vars static void -add_to_blob(const char *text) +add_to_blob(const char *text, size_t limit) { + (void) limit; + if (*text != '\0') { char *last = my_blob + strlen(my_blob); if (last != my_blob) - *last++ = ':'; - strcpy(last, text); + *last++ = NCURSES_PATHSEP; + _nc_STRCPY(last, text, limit); } } @@ -70,19 +72,19 @@ check_existence(const char *name, struct stat *sb) { bool result = FALSE; - if (stat(name, sb) == 0 && sb->st_size) { + if (stat(name, sb) == 0 + && (S_ISDIR(sb->st_mode) || S_ISREG(sb->st_mode))) { result = TRUE; } #if USE_HASHED_DB else if (strlen(name) < PATH_MAX - sizeof(DBM_SUFFIX)) { char temp[PATH_MAX]; - sprintf(temp, "%s%s", name, DBM_SUFFIX); - if (stat(temp, sb) == 0 && sb->st_size) { + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "%s%s", name, DBM_SUFFIX); + if (stat(temp, sb) == 0 && S_ISREG(sb->st_mode)) { result = TRUE; } } #endif - return result; } @@ -280,6 +282,7 @@ _nc_first_db(DBDIRS * state, int *offset) values[dbdHome] = _nc_home_terminfo(); (void) cache_getenv("HOME", dbdHome); values[dbdEnvList] = cache_getenv("TERMINFO_DIRS", dbdEnvList); + #endif #if USE_TERMCAP values[dbdEnvOnce2] = cache_getenv("TERMCAP", dbdEnvOnce2); @@ -302,7 +305,7 @@ _nc_first_db(DBDIRS * state, int *offset) if (my_blob != 0) { *my_blob = '\0'; for (j = 0; j < dbdLAST; ++j) { - add_to_blob(values[j]); + add_to_blob(values[j], blobsize); } /* Now, build an array which will be pointers to the distinct @@ -310,7 +313,7 @@ _nc_first_db(DBDIRS * state, int *offset) */ blobsize = 2; for (j = 0; my_blob[j] != '\0'; ++j) { - if (my_blob[j] == ':') + if (my_blob[j] == NCURSES_PATHSEP) ++blobsize; } my_list = typeCalloc(char *, blobsize); @@ -319,7 +322,7 @@ _nc_first_db(DBDIRS * state, int *offset) k = 0; my_list[k++] = my_blob; for (j = 0; my_blob[j] != '\0'; ++j) { - if (my_blob[j] == ':') { + if (my_blob[j] == NCURSES_PATHSEP) { my_blob[j] = '\0'; my_list[k++] = &my_blob[j + 1]; } @@ -331,7 +334,7 @@ _nc_first_db(DBDIRS * state, int *offset) for (j = 0; my_list[j] != 0; ++j) { #ifdef TERMINFO if (*my_list[j] == '\0') - my_list[j] = TERMINFO; + my_list[j] = strdup(TERMINFO); #endif for (k = 0; k < j; ++k) { if (!strcmp(my_list[j], my_list[k])) {