]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/write_entry.c
ncurses 6.4 - patch 20230311
[ncurses.git] / ncurses / tinfo / write_entry.c
index 3d3e36aa23f8e1bbc9c6523fe98420fb252c618f..002b117ce92dcc1f32a0b5989b26da0f589ca652 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
+ * Copyright 2018-2022,2023 Thomas E. Dickey                                *
+ * Copyright 1998-2016,2017 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            *
@@ -50,7 +51,7 @@
 #define TRACE_NUM(n)           /* nothing */
 #endif
 
-MODULE_ID("$Id: write_entry.c,v 1.113 2019/03/23 23:47:16 tom Exp $")
+MODULE_ID("$Id: write_entry.c,v 1.121 2023/03/05 18:45:59 tom Exp $")
 
 static int total_written;
 static int total_parts;
@@ -70,7 +71,7 @@ write_file(char *filename, TERMTYPE2 *tp)
        _nc_warning("entry is larger than %u bytes", limit);
     } else {
        FILE *fp = ((_nc_access(filename, W_OK) == 0)
-                   ? fopen(filename, BIN_W)
+                   ? safe_fopen(filename, BIN_W)
                    : 0);
        size_t actual;
 
@@ -144,7 +145,7 @@ make_db_path(char *dst, const char *src, size_t limit)
            rc = 0;
        }
     } else {
-       if (strlen(top) + strlen(src) + 2 <= limit) {
+       if ((strlen(top) + strlen(src) + 6) <= limit) {
            _nc_SPRINTF(dst, _nc_SLIMIT(limit) "%s/%s", top, src);
            rc = 0;
        }
@@ -189,9 +190,9 @@ make_db_root(const char *path)
 #else
        struct stat statbuf;
 
-       if ((rc = stat(path, &statbuf)) < 0) {
+       if ((rc = stat(path, &statbuf)) == -1) {
            rc = mkdir(path
-#if !defined(_WIN32)
+#ifndef _NC_WINDOWS
                       ,0777
 #endif
                );
@@ -247,7 +248,7 @@ _nc_set_writedir(const char *dir)
        || getcwd(actual, sizeof(actual)) == 0)
        _nc_err_abort("%s: not a directory", destination);
 #endif
-    _nc_keep_tic_dir(strdup(actual));
+    _nc_keep_tic_dir(actual);
 }
 
 /*
@@ -405,7 +406,7 @@ _nc_write_entry(TERMTYPE2 *const tp)
 
     _nc_SPRINTF(filename, _nc_SLIMIT(sizeof(filename))
                LEAF_FMT "/%.*s", UChar(first_name[0]),
-               (int) (sizeof(filename) - LEAF_LEN - 2),
+               (int) (sizeof(filename) - (LEAF_LEN + 2)),
                first_name);
 
     if (saved)
@@ -441,7 +442,7 @@ _nc_write_entry(TERMTYPE2 *const tp)
     write_file(filename, tp);
 
     if (start_time == 0) {
-       if (stat(filename, &statbuf) < 0
+       if (stat(filename, &statbuf) == -1
            || (start_time = statbuf.st_mtime) == 0) {
            _nc_syserr_abort("error obtaining time from %s/%s",
                             _nc_tic_dir(0), filename);
@@ -466,12 +467,13 @@ _nc_write_entry(TERMTYPE2 *const tp)
 
        check_writeable(ptr[0]);
        _nc_SPRINTF(linkname, _nc_SLIMIT(sizeof(linkname))
-                   LEAF_FMT "/%.*s", ptr[0], (int) sizeof(linkname) - 3, ptr);
+                   LEAF_FMT "/%.*s", ptr[0],
+                   (int) sizeof(linkname) - (2 + LEAF_LEN), ptr);
 
        if (strcmp(filename, linkname) == 0) {
            _nc_warning("self-synonym ignored");
        } else if (stat(linkname, &statbuf) >= 0 &&
-                  statbuf.st_mtime < start_time) {
+                  statbuf.st_mtime > start_time) {
            _nc_warning("alias %s multiply defined.", ptr);
        } else if (_nc_access(linkname, W_OK) == 0)
 #if HAVE_LINK