X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Fwrite_entry.c;h=3f6eebfcb33d9ae1f35fac5b5dfde2c3b591d776;hp=97fa06ab591dd38fdf58fc27a61244c26920488d;hb=03f728e5bb3630a54fffc4a2ff2f8dbfcce9088e;hpb=d4ff840fddef2f6deb4a3daeb26d398a93b58dd2 diff --git a/ncurses/tinfo/write_entry.c b/ncurses/tinfo/write_entry.c index 97fa06ab..3f6eebfc 100644 --- a/ncurses/tinfo/write_entry.c +++ b/ncurses/tinfo/write_entry.c @@ -1,5 +1,5 @@ /**************************************************************************** - * 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 * @@ -39,21 +39,15 @@ #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) #else #define TRACE_OUT(p) /*nothing */ #endif -MODULE_ID("$Id: write_entry.c,v 1.77 2010/08/28 21:04:05 tom Exp $") +MODULE_ID("$Id: write_entry.c,v 1.81 2011/10/22 15:33:37 tom Exp $") static int total_written; @@ -76,7 +70,7 @@ write_file(char *filename, TERMTYPE *tp) DEBUG(1, ("Created %s", filename)); if (write_object(tp, buffer, &offset, limit) == ERR - || fwrite(buffer, sizeof(char), offset, fp) != offset) { + || fwrite(buffer, sizeof(char), (size_t) offset, fp) != offset) { _nc_syserr_abort("error writing %s/%s", _nc_tic_dir(0), filename); } @@ -115,7 +109,7 @@ check_writeable(int code) #endif /* !USE_HASHED_DB */ static int -make_db_path(char *dst, const char *src, unsigned limit) +make_db_path(char *dst, const char *src, size_t limit) { int rc = -1; const char *top = _nc_tic_dir(0); @@ -137,9 +131,9 @@ make_db_path(char *dst, const char *src, unsigned limit) rc = -1; } else { static const char suffix[] = DBM_SUFFIX; - unsigned have = strlen(dst); - unsigned need = strlen(suffix); - if (have > need && strcmp(dst + have - need, suffix)) { + size_t have = strlen(dst); + size_t need = strlen(suffix); + if (have > need && strcmp(dst + (int) (have - need), suffix)) { if (have + need <= limit) strcat(dst, suffix); else @@ -355,7 +349,6 @@ _nc_write_entry(TERMTYPE *const tp) _nc_db_put(capdb, &key, &data); } - _nc_db_close(capdb); } } #else /* !USE_HASHED_DB */ @@ -469,29 +462,29 @@ _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; } return (want / size); } -#define Write(buf, size, count) fake_write(buffer, offset, limit, (char *) buf, count, size) +#define Write(buf, size, count) fake_write(buffer, offset, (size_t) limit, (char *) buf, (size_t) count, (size_t) size) #undef LITTLE_ENDIAN /* BSD/OS defines this as a feature macro */ #define HI(x) ((x) / 256) @@ -502,10 +495,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) { @@ -523,9 +516,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; @@ -534,7 +527,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])); } } } @@ -706,7 +699,7 @@ write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) return (ERR); nextfree = compute_offsets(tp->Strings + STRCOUNT, - tp->ext_Strings, + (size_t) tp->ext_Strings, offsets); TRACE_OUT(("after extended string capabilities, nextfree=%d", nextfree)); @@ -714,7 +707,7 @@ write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) return (ERR); nextfree += compute_offsets(tp->ext_Names, - extcnt, + (size_t) extcnt, offsets + tp->ext_Strings); TRACE_OUT(("after extended capnames, nextfree=%d", nextfree)); strmax = tp->ext_Strings + extcnt; @@ -742,7 +735,7 @@ write_object(TERMTYPE *tp, char *buffer, unsigned *offset, unsigned limit) TRACE_OUT(("WRITE %d numbers @%d", tp->ext_Numbers, *offset)); if (tp->ext_Numbers) { - convert_shorts(buf, tp->Numbers + NUMCOUNT, tp->ext_Numbers); + convert_shorts(buf, tp->Numbers + NUMCOUNT, (size_t) tp->ext_Numbers); if (Write(buf, 2, tp->ext_Numbers) != tp->ext_Numbers) return (ERR); }