/****************************************************************************
- * 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 *
#include <hashed_db.h>
#endif
-MODULE_ID("$Id: db_iterator.c,v 1.25 2011/12/17 21:30:20 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
#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);
}
}
{
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;
}
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);
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
*/
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);
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];
}