]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/db_iterator.c
ncurses 5.9 - patch 20120505
[ncurses.git] / ncurses / tinfo / db_iterator.c
index 3a4827df04627c8d710bd6e0177f62e98322fa88..8af267bcb8559fb504b0be2f62692744b58f4dd6 100644 (file)
@@ -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 <hashed_db.h>
 #endif
 
-MODULE_ID("$Id: db_iterator.c,v 1.26 2012/01/07 20:09:36 juergen 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.26 2012/01/07 20:09:36 juergen 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++ = NCURSES_PATHSEP;
-       strcpy(last, text);
+       _nc_STRCPY(last, text, limit);
     }
 }
 
@@ -69,22 +71,16 @@ static bool
 check_existence(const char *name, struct stat *sb)
 {
     bool result = FALSE;
+
     if (stat(name, sb) == 0
-#ifndef __MINGW32__
-       && sb->st_size
-#endif
-       ) {
+       && (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
-#ifndef __MINGW32__
-           && sb->st_size
-#endif
-           ) {
+       _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "%s%s", name, DBM_SUFFIX);
+       if (stat(temp, sb) == 0 && S_ISREG(sb->st_mode)) {
            result = TRUE;
        }
     }
@@ -309,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