PERFORCE change 146988 for review
Gabor Kovesdan
gabor at FreeBSD.org
Sat Aug 9 13:40:17 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=146988
Change 146988 by gabor at gabor_server on 2008/08/09 13:40:04
- Check in a working and hopefully GNU compatible version of
binary detecting
Affected files ...
.. //depot/projects/soc2008/gabor_textproc/grep/file.c#33 edit
Differences ...
==== //depot/projects/soc2008/gabor_textproc/grep/file.c#33 (text+ko) ====
@@ -119,32 +119,19 @@
{
int i = 0;
char ch;
- size_t size;
- wchar_t wbinbuf[BUFSIZ];
- const char *src = binbuf;
- mbstate_t mbs;
/* Fill in the buffer if it is empty. */
if (binbufptr == NULL) {
/* Only pre-read to the buffer if we need the binary check. */
if (binbehave != BINFILE_TEXT) {
- for (; i < sizeof(wbinbuf) && !grep_feof(f); i++) {
+ for (; i < sizeof(binbuf) && !grep_feof(f); i++) {
ch = grep_fgetc(f);
if (ch != EOF)
binbuf[i] = ch;
else
break;
}
- /* Convert at most (BUFSIZ * sizeof(wint_t)) characters or
- (BUFSIZ - 1) bytes to wide character string. */
- size = mbsnrtowcs(wbinbuf, &src, sizeof(wbinbuf), BUFSIZ - 1, &mbs);
- f->binary = 0;
- for (; size > 0; size--)
- if (iswbinary(wbinbuf[size])) {
- f->binary = 1;
- break;
- }
-
+ f->binary = memchr(binbuf, (filebehave != FILE_GZIP) ? '\0' : '\200', i - 1) != 0;
}
binbufsiz = i;
binbufptr = binbuf;
More information about the p4-projects
mailing list