X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fwrite_entry.c;h=6d855e945d2d78762079529adc822b3e62cb68d5;hp=057b3c22a44782dd2593bcad485da579a57c4667;hb=331f875facea2b7897c1ce0425ce0d111cc4175b;hpb=9e3a472c069d718e4f510e8477373618f80227ae diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index 057b3c22..6d855e94 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2008,2009 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 * @@ -39,14 +39,7 @@ #include #include -#include - #include -#include - -#ifndef S_ISDIR -#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR) -#endif #if 1 #define TRACE_OUT(p) DEBUG(2, p) @@ -54,7 +47,7 @@ #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.74 2009/09/19 20:30:48 Daniel.Jacobowitz Exp $") +MODULE_ID("$Id: write_entry.c,v 1.79 2011/06/05 00:46:26 tom Exp $") static int total_written; @@ -137,10 +130,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 +357,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 +391,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; } @@ -468,22 +463,22 @@ _nc_write_entry(TERMTYPE *const tp) #endif /* USE_HASHED_DB */ } -static unsigned +static size_t fake_write(char *dst, unsigned *offset, - unsigned limit, + size_t limit, char *src, - unsigned want, - unsigned size) + size_t want, + size_t size) { - unsigned have = (limit - *offset); + size_t have = (limit - *offset); want *= size; if (have > 0) { if (want > have) want = have; memcpy(dst + *offset, src, want); - *offset += want; + *offset += (unsigned) want; } else { want = 0; } @@ -501,10 +496,10 @@ fake_write(char *dst, #define WRITE_STRING(str) (Write(str, sizeof(char), strlen(str) + 1) == strlen(str) + 1) static int -compute_offsets(char **Strings, unsigned strmax, short *offsets) +compute_offsets(char **Strings, size_t strmax, short *offsets) { int nextfree = 0; - unsigned i; + size_t i; for (i = 0; i < strmax; i++) { if (Strings[i] == ABSENT_STRING) { @@ -522,9 +517,9 @@ compute_offsets(char **Strings, unsigned strmax, short *offsets) } static void -convert_shorts(unsigned char *buf, short *Numbers, unsigned count) +convert_shorts(unsigned char *buf, short *Numbers, size_t count) { - unsigned i; + size_t i; for (i = 0; i < count; i++) { if (Numbers[i] == ABSENT_NUMERIC) { /* HI/LO won't work */ buf[2 * i] = buf[2 * i + 1] = 0377; @@ -533,7 +528,7 @@ convert_shorts(unsigned char *buf, short *Numbers, unsigned count) buf[2 * i + 1] = 0377; } else { LITTLE_ENDIAN(buf + 2 * i, Numbers[i]); - TRACE_OUT(("put Numbers[%d]=%d", i, Numbers[i])); + TRACE_OUT(("put Numbers[%u]=%d", (unsigned) i, Numbers[i])); } } } @@ -576,7 +571,7 @@ extended_Strings(TERMTYPE *tp) for (i = 0; i < tp->ext_Strings; ++i) { if (tp->Strings[STRCOUNT + i] != ABSENT_STRING) - result = (i + 1); + result = (unsigned short) (i + 1); } return result; }