diff options
author | James Youngman <jay@gnu.org> | 2007-06-09 12:53:42 +0000 |
---|---|---|
committer | James Youngman <jay@gnu.org> | 2007-06-09 12:53:42 +0000 |
commit | 4f76ac2b63e57c26dc507054a1598ca92593fcc8 (patch) | |
tree | 0577a49ca82fdbecd471f043c0331da2a3670e7d /locate | |
parent | 52836d78524a1bf4819d3e849efec715f9300ff1 (diff) | |
download | findutils-4f76ac2b63e57c26dc507054a1598ca92593fcc8.tar.gz |
Fix Savannah bug #19980, by avoiding the non-POSIX function putw() (and in previous changes, getw(), and wcwidth())
Diffstat (limited to 'locate')
-rw-r--r-- | locate/Makefile.am | 1 | ||||
-rw-r--r-- | locate/code.c | 15 | ||||
-rw-r--r-- | locate/frcode.c | 3 | ||||
-rw-r--r-- | locate/locate.c | 3 | ||||
-rw-r--r-- | locate/locatedb.h | 5 | ||||
-rw-r--r-- | locate/word_io.c | 27 |
6 files changed, 46 insertions, 8 deletions
diff --git a/locate/Makefile.am b/locate/Makefile.am index 11123710..7466ed36 100644 --- a/locate/Makefile.am +++ b/locate/Makefile.am @@ -12,6 +12,7 @@ BUILT_SOURCES = dblocation.texi EXTRA_DIST = locatedb.h updatedb.sh $(man_MANS) CLEANFILES = updatedb dblocation.texi locate_SOURCES = locate.c word_io.c +code_SOURCES = code.c word_io.c INCLUDES = -I$(top_srcdir)/lib -I../gnulib/lib -I$(top_srcdir)/gnulib/lib -I../intl -DLOCATE_DB=\"$(LOCATE_DB)\" -DLOCALEDIR=\"$(localedir)\" diff --git a/locate/code.c b/locate/code.c index aab41392..a00f6356 100644 --- a/locate/code.c +++ b/locate/code.c @@ -1,5 +1,5 @@ /* code -- bigram- and front-encode filenames for locate - Copyright (C) 1994 Free Software Foundation, Inc. + Copyright (C) 1994, 2005, 2007 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,6 +50,7 @@ #include <sys/types.h> #include <string.h> #include <errno.h> +#include <stdbool.h> #ifdef STDC_HEADERS @@ -239,15 +240,17 @@ main (int argc, char **argv) if (diffcount < -LOCATEDB_OLD_OFFSET || diffcount > LOCATEDB_OLD_OFFSET) { if (EOF ==- putc (LOCATEDB_OLD_ESCAPE, stdout)) - outerr(); - - if (EOF == putw (diffcount + LOCATEDB_OLD_OFFSET, stdout)) - outerr(); + outerr (); + + if (!putword (stdout, + diffcount+LOCATEDB_OLD_OFFSET, + GetwordEndianStateNative)) + outerr (); } else { if (EOF == putc (diffcount + LOCATEDB_OLD_OFFSET, stdout)) - outerr(); + outerr (); } /* Look for bigrams in the remainder of the path. */ diff --git a/locate/frcode.c b/locate/frcode.c index 45a102a0..0cd40dc0 100644 --- a/locate/frcode.c +++ b/locate/frcode.c @@ -65,11 +65,14 @@ */ #include <config.h> + + #include <stdio.h> #include <limits.h> #include <assert.h> #include <errno.h> #include <sys/types.h> +#include <stdbool.h> #if defined(HAVE_STRING_H) || defined(STDC_HEADERS) #include <string.h> diff --git a/locate/locate.c b/locate/locate.c index 7f669914..46d55954 100644 --- a/locate/locate.c +++ b/locate/locate.c @@ -61,6 +61,7 @@ */ #include <config.h> + #include <stdio.h> #include <signal.h> #include <ctype.h> @@ -72,6 +73,8 @@ #include <getopt.h> #include <xstrtol.h> +#include <stdbool.h> /* for bool/boolean */ + /* The presence of unistd.h is assumed by gnulib these days, so we * might as well assume it too. */ diff --git a/locate/locatedb.h b/locate/locatedb.h index 8423317f..42cede8c 100644 --- a/locate/locatedb.h +++ b/locate/locatedb.h @@ -20,8 +20,6 @@ #ifndef _LOCATEDB_H #define _LOCATEDB_H 1 -#include <stdio.h> - /* The magic string at the start of a locate database, to make sure it's in the right format. The 02 is the database format version number. This string has the same format as a database entry, but you can't @@ -75,6 +73,9 @@ int getword (FILE *fp, const char *filename, size_t minvalue, size_t maxvalue, GetwordEndianState *endian_state_flag); +bool putword (FILE *fp, int word, + GetwordEndianState endian_state_flag); + #define SLOCATE_DB_MAGIC_LEN 2 diff --git a/locate/word_io.c b/locate/word_io.c index df42b6f3..9e44957f 100644 --- a/locate/word_io.c +++ b/locate/word_io.c @@ -18,8 +18,12 @@ */ #include <config.h> + #include <string.h> +#include <stdio.h> #include <errno.h> +#include <stdbool.h> /* for bool */ +#include <assert.h> #include "quote.h" #include "quotearg.h" @@ -147,3 +151,26 @@ getword (FILE *fp, } } + +bool +putword (FILE *fp, int word, + GetwordEndianState endian_state_flag) +{ + size_t items_written; + + /* You must decide before calling this function which + * endianness you want to use. + */ + assert(endian_state_flag != GetwordEndianStateInitial); + if (GetwordEndianStateSwab == endian_state_flag) + { + word = bswap_32(word); + } + + items_written = fwrite(&word, sizeof(word), 1, fp); + if (1 == items_written) + return true; + else + return false; +} + |