diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2014-09-17 12:33:55 -0700 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2014-09-17 20:37:48 -0700 |
commit | 1b76ead152e0a14b3c4b8469d74f44dad60617ae (patch) | |
tree | 6b8d45f687ba06ffe327bf2263051f90e13ef566 | |
parent | d795d6d194a594792b2a5bb35527a84a484ebeea (diff) | |
download | grep-1b76ead152e0a14b3c4b8469d74f44dad60617ae.tar.gz |
grep: port to platforms lacking SEEK_DATA
Reported by Norihiro Tanaka in: http://bugs.gnu.org/18454#38
* src/grep.c (SEEK_DATA): Default to SEEK_SET if not defined.
(SEEK_HOLE): Move to top level, and default it to SEEK_SET.
(file_textbin): Adjust to new default.
(fillbuf): Don't bother with SEEK_DATA if it defaults to SEEK_SET.
-rw-r--r-- | src/grep.c | 17 |
1 files changed, 11 insertions, 6 deletions
@@ -415,6 +415,15 @@ usable_st_size (struct stat const *st) return S_ISREG (st->st_mode) || S_TYPEISSHM (st) || S_TYPEISTMO (st); } +/* Lame substitutes for SEEK_DATA and SEEK_HOLE on platforms lacking them. + Do not rely on these finding data or holes if they equal SEEK_SET. */ +#ifndef SEEK_DATA +enum { SEEK_DATA = SEEK_SET }; +#endif +#ifndef SEEK_HOLE +enum { SEEK_HOLE = SEEK_SET }; +#endif + /* Functions we'll use to search. */ typedef void (*compile_fp_t) (char const *, size_t); typedef size_t (*execute_fp_t) (char const *, size_t, size_t *, char const *); @@ -474,10 +483,6 @@ buffer_textbin (char const *buf, size_t size) static enum textbin file_textbin (char const *buf, size_t bufsize, int fd, struct stat const *st) { - #ifndef SEEK_HOLE - enum { SEEK_HOLE = SEEK_END }; - #endif - enum textbin textbin = buffer_textbin (buf, bufsize); if (textbin_is_binary (textbin)) return textbin; @@ -488,7 +493,7 @@ file_textbin (char const *buf, size_t bufsize, int fd, struct stat const *st) return textbin == TEXTBIN_UNKNOWN ? TEXTBIN_BINARY : textbin; /* If the file has holes, it must contain a null byte somewhere. */ - if (SEEK_HOLE != SEEK_END && eolbyte) + if (SEEK_HOLE != SEEK_SET && eolbyte) { off_t cur = bufsize; if (O_BINARY || fd == STDIN_FILENO) @@ -713,7 +718,7 @@ fillbuf (size_t save, struct stat const *st) break; totalnl = add_count (totalnl, fillsize); - if (!seek_data_failed) + if (SEEK_DATA != SEEK_SET && !seek_data_failed) { off_t data_start = lseek (bufdesc, bufoffset, SEEK_DATA); if (data_start < 0) |