/****************************************************************************
- * 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 *
#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))
_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) {
} else {
code = TGETENT_NO;
}
- close(fd);
+ fclose(fp);
}
return (code);
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,
(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;
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);
}
}
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 */
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());