X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fwrite_entry.c;h=2552eea56df9bcfc5f93de186ff21887c2debf3e;hp=a89da90531a8876ade785b12091c326fe1397327;hb=99c50261a07b29bfad4ab33ebe9f6597558e8c88;hpb=7a6bbc8cf41c5186d46accc3d08622dc86526b34 diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index a89da905..2552eea5 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -54,7 +54,7 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.73 2009/04/18 21:01:38 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.75 2009/12/05 21:25:01 tom Exp $") static int total_written; @@ -137,10 +137,12 @@ make_db_path(char *dst, const char *src, unsigned limit) if (_nc_is_dir_path(dst)) { rc = -1; } else { + static const char suffix[] = DBM_SUFFIX; unsigned have = strlen(dst); - if (have > 3 && strcmp(dst + have - 3, DBM_SUFFIX)) { - if (have + 3 <= limit) - strcat(dst, DBM_SUFFIX); + unsigned need = strlen(suffix); + if (have > need && strcmp(dst + have - need, suffix)) { + if (have + need <= limit) + strcat(dst, suffix); else rc = -1; } @@ -362,7 +364,7 @@ _nc_write_entry(TERMTYPE *const tp) start_time = 0; } - if (strlen(first_name) >= sizeof(filename) - 3) + if (strlen(first_name) >= sizeof(filename) - (2 + LEAF_LEN)) _nc_warning("terminal name too long."); sprintf(filename, LEAF_FMT "/%s", first_name[0], first_name); @@ -396,7 +398,7 @@ _nc_write_entry(TERMTYPE *const tp) if (*other_names != '\0') *(other_names++) = '\0'; - if (strlen(ptr) > sizeof(linkname) - 3) { + if (strlen(ptr) > sizeof(linkname) - (2 + LEAF_LEN)) { _nc_warning("terminal alias %s too long.", ptr); continue; } @@ -418,8 +420,12 @@ _nc_write_entry(TERMTYPE *const tp) { int code; #if USE_SYMLINKS - strcpy(symlinkname, "../"); - strncat(symlinkname, filename, sizeof(symlinkname) - 4); + if (first_name[0] == linkname[0]) + strncpy(symlinkname, first_name, sizeof(symlinkname) - 1); + else { + strcpy(symlinkname, "../"); + strncat(symlinkname, filename, sizeof(symlinkname) - 4); + } symlinkname[sizeof(symlinkname) - 1] = '\0'; #endif /* USE_SYMLINKS */ #if HAVE_REMOVE