diff options
Diffstat (limited to 'ncurses/tinfo/hashed_db.c')
| -rw-r--r-- | ncurses/tinfo/hashed_db.c | 49 |
1 files changed, 27 insertions, 22 deletions
diff --git a/ncurses/tinfo/hashed_db.c b/ncurses/tinfo/hashed_db.c index b78d98f874fe..afd1bda827d4 100644 --- a/ncurses/tinfo/hashed_db.c +++ b/ncurses/tinfo/hashed_db.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2019,2020 Thomas E. Dickey * + * Copyright 2019-2024,2025 Thomas E. Dickey * * Copyright 2006-2011,2013 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -37,7 +37,7 @@ #if USE_HASHED_DB -MODULE_ID("$Id: hashed_db.c,v 1.19 2020/02/02 23:34:34 tom Exp $") +MODULE_ID("$Id: hashed_db.c,v 1.22 2025/01/11 23:52:18 tom Exp $") #if HASHED_DB_API >= 2 static DBC *cursor; @@ -55,7 +55,7 @@ static MYCONN *connections; static void cleanup(void) { - while (connections != 0) { + while (connections != NULL) { _nc_db_close(connections->db); } } @@ -63,10 +63,10 @@ cleanup(void) static DB * find_connection(const char *path, bool modify) { - DB *result = 0; + DB *result = NULL; MYCONN *p; - for (p = connections; p != 0; p = p->next) { + for (p = connections; p != NULL; p = p->next) { if (!strcmp(p->path, path) && p->modify == modify) { result = p->db; break; @@ -81,9 +81,9 @@ drop_connection(DB * db) { MYCONN *p, *q; - for (p = connections, q = 0; p != 0; q = p, p = p->next) { + for (p = connections, q = NULL; p != NULL; q = p, p = p->next) { if (p->db == db) { - if (q != 0) + if (q != NULL) q->next = p->next; else connections = p->next; @@ -94,22 +94,25 @@ drop_connection(DB * db) } } -static void +static bool make_connection(DB * db, const char *path, bool modify) { + bool code = FALSE; MYCONN *p = typeCalloc(MYCONN, 1); - if (p != 0) { - p->db = db; + if (p != NULL) { p->path = strdup(path); - p->modify = modify; - if (p->path != 0) { + if (p->path != NULL) { + p->db = db; + p->modify = modify; p->next = connections; connections = p; + code = TRUE; } else { free(p); } } + return code; } /* @@ -118,13 +121,13 @@ make_connection(DB * db, const char *path, bool modify) NCURSES_EXPORT(DB *) _nc_db_open(const char *path, bool modify) { - DB *result = 0; + DB *result = NULL; int code; - if (connections == 0) + if (connections == NULL) atexit(cleanup); - if ((result = find_connection(path, modify)) == 0) { + if ((result = find_connection(path, modify)) == NULL) { #if HASHED_DB_API >= 4 db_create(&result, NULL, 0); @@ -135,7 +138,7 @@ _nc_db_open(const char *path, bool modify) DB_HASH, modify ? DB_CREATE : DB_RDONLY, 0644)) != 0) { - result = 0; + result = NULL; } #elif HASHED_DB_API >= 3 db_create(&result, NULL, 0); @@ -145,7 +148,7 @@ _nc_db_open(const char *path, bool modify) DB_HASH, modify ? DB_CREATE : DB_RDONLY, 0644)) != 0) { - result = 0; + result = NULL; } #elif HASHED_DB_API >= 2 if ((code = db_open(path, @@ -155,22 +158,24 @@ _nc_db_open(const char *path, bool modify) (DB_ENV *) 0, (DB_INFO *) 0, &result)) != 0) { - result = 0; + result = NULL; } #else if ((result = dbopen(path, modify ? (O_CREAT | O_RDWR) : O_RDONLY, 0644, DB_HASH, - NULL)) == 0) { + NULL)) == NULL) { code = errno; + } else { + code = 0; } #endif - if (result != 0) { - make_connection(result, path, modify); + if (result != NULL && make_connection(result, path, modify)) { T(("opened %s", path)); } else { - T(("cannot open %s: %s", path, strerror(code))); + T(("cannot open %s: (errno %d) %s", path, code, strerror(code))); + errno = code; } } return result; |
