]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/read_entry.c
ncurses 5.9 - patch 20110807
[ncurses.git] / ncurses / tinfo / read_entry.c
index 51b4a2b28e9be775cd262e0cd6e263a34d18de66..8eee695eee3890091da5ae25a786051119071f49 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2011 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            *
@@ -41,7 +41,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: read_entry.c,v 1.107 2010/04/24 23:47:42 tom Exp $")
+MODULE_ID("$Id: read_entry.c,v 1.109 2011/07/25 22:21:34 tom Exp $")
 
 #define TYPE_CALLOC(type,elts) typeCalloc(type, (unsigned)(elts))
 
@@ -364,16 +364,18 @@ NCURSES_EXPORT(int)
 _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
 /* return 1 if read, 0 if not found or garbled */
 {
-    int code, fd = -1;
+    FILE *fp = 0;
+    int code;
     int limit;
     char buffer[MAX_ENTRY_SIZE + 1];
 
     if (_nc_access(filename, R_OK) < 0
-       || (fd = open(filename, O_RDONLY | O_BINARY)) < 0) {
+       || (fp = fopen(filename, "rb")) == 0) {
        T(("cannot open terminfo %s (errno=%d)", filename, errno));
        code = TGETENT_NO;
     } else {
-       if ((limit = (int) read(fd, buffer, sizeof(buffer))) > 0) {
+       if ((limit = (int) fread(buffer, sizeof(char), sizeof(buffer), fp))
+           > 0) {
 
            T(("read terminfo %s", filename));
            if ((code = _nc_read_termtype(ptr, buffer, limit)) == TGETENT_NO) {
@@ -382,7 +384,7 @@ _nc_read_file_entry(const char *const filename, TERMTYPE *ptr)
        } else {
            code = TGETENT_NO;
        }
-       close(fd);
+       fclose(fp);
     }
 
     return (code);
@@ -399,7 +401,7 @@ _nc_read_tic_entry(char *filename,
                   const char *name,
                   TERMTYPE *const tp)
 {
-    int result = TGETENT_NO;
+    int code = TGETENT_NO;
 
     /*
      * If we are looking in a directory, assume the entry is a file under that,
@@ -410,9 +412,9 @@ _nc_read_tic_entry(char *filename,
        (void) sprintf(filename, "%s/" LEAF_FMT "/%s", path, *name, name);
 
     if (_nc_is_dir_path(path))
-       result = _nc_read_file_entry(filename, tp);
-#if USE_HASHED_DB
+       code = _nc_read_file_entry(filename, tp);
     else {
+#if USE_HASHED_DB
        static const char suffix[] = DBM_SUFFIX;
        DB *capdbp;
        unsigned lens = sizeof(suffix) - 1;
@@ -465,8 +467,8 @@ _nc_read_tic_entry(char *filename,
                    if (*have++ == 0) {
                        if (data.size > key.size
                            && IS_TIC_MAGIC(have)) {
-                           result = _nc_read_termtype(tp, have, used);
-                           if (result == TGETENT_NO) {
+                           code = _nc_read_termtype(tp, have, used);
+                           if (code == TGETENT_NO) {
                                _nc_free_termtype(tp);
                            }
                        }
@@ -491,9 +493,15 @@ _nc_read_tic_entry(char *filename,
                free(save);
            }
        }
-    }
 #endif
-    return result;
+#if USE_TERMCAP
+       if (code != TGETENT_YES) {
+           code = _nc_read_termcap_entry(name, tp);
+           sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source());
+       }
+#endif
+    }
+    return code;
 }
 #endif /* USE_DATABASE */
 
@@ -531,8 +539,7 @@ _nc_read_entry(const char *const name, char *const filename, TERMTYPE *const tp)
                break;
            }
        }
-#endif
-#if USE_TERMCAP
+#elif USE_TERMCAP
        if (code != TGETENT_YES) {
            code = _nc_read_termcap_entry(name, tp);
            sprintf(filename, "%.*s", PATH_MAX - 1, _nc_get_source());