Deleted Added
full compact
file.c (226271) file.c (245171)
1/* $NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $ */
1/* $NetBSD: file.c,v 1.5 2011/02/16 18:35:39 joerg Exp $ */
2/* $FreeBSD: head/usr.bin/grep/file.c 226271 2011-10-11 22:27:23Z gabor $ */
2/* $FreeBSD: head/usr.bin/grep/file.c 245171 2013-01-08 18:37:12Z obrien $ */
3/* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */
4
5/*-
6 * Copyright (c) 1999 James Howard and Dag-Erling Co��dan Sm��rgrav
7 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org>
8 * Copyright (C) 2010 Dimitry Andric <dimitry@andric.com>
9 * All rights reserved.
10 *

--- 15 unchanged lines hidden (view full) ---

26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
3/* $OpenBSD: file.c,v 1.11 2010/07/02 20:48:48 nicm Exp $ */
4
5/*-
6 * Copyright (c) 1999 James Howard and Dag-Erling Co��dan Sm��rgrav
7 * Copyright (C) 2008-2010 Gabor Kovesdan <gabor@FreeBSD.org>
8 * Copyright (C) 2010 Dimitry Andric <dimitry@andric.com>
9 * All rights reserved.
10 *

--- 15 unchanged lines hidden (view full) ---

26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/usr.bin/grep/file.c 226271 2011-10-11 22:27:23Z gabor $");
34__FBSDID("$FreeBSD: head/usr.bin/grep/file.c 245171 2013-01-08 18:37:12Z obrien $");
35
36#include <sys/param.h>
37#include <sys/mman.h>
38#include <sys/stat.h>
39#include <sys/types.h>
40
41#include <err.h>
42#include <errno.h>
43#include <fcntl.h>
35
36#include <sys/param.h>
37#include <sys/mman.h>
38#include <sys/stat.h>
39#include <sys/types.h>
40
41#include <err.h>
42#include <errno.h>
43#include <fcntl.h>
44#include <lzma.h>
45#include <stddef.h>
46#include <stdlib.h>
47#include <string.h>
48#include <unistd.h>
49#include <wchar.h>
50#include <wctype.h>
51#include <zlib.h>
52
44#include <stddef.h>
45#include <stdlib.h>
46#include <string.h>
47#include <unistd.h>
48#include <wchar.h>
49#include <wctype.h>
50#include <zlib.h>
51
52#ifndef WITHOUT_LZMA
53#include <lzma.h>
54#endif
55
53#ifndef WITHOUT_BZIP2
54#include <bzlib.h>
55#endif
56
57#include "grep.h"
58
59#define MAXBUFSIZ (32 * 1024)
60#define LNBUFBUMP 80
61
62static gzFile gzbufdesc;
56#ifndef WITHOUT_BZIP2
57#include <bzlib.h>
58#endif
59
60#include "grep.h"
61
62#define MAXBUFSIZ (32 * 1024)
63#define LNBUFBUMP 80
64
65static gzFile gzbufdesc;
66#ifndef WITHOUT_LZMA
63static lzma_stream lstrm = LZMA_STREAM_INIT;
67static lzma_stream lstrm = LZMA_STREAM_INIT;
68#endif
64#ifndef WITHOUT_BZIP2
65static BZFILE* bzbufdesc;
66#endif
67
68static unsigned char *buffer;
69static unsigned char *bufpos;
70static size_t bufrem;
71static size_t fsiz;

--- 39 unchanged lines hidden (view full) ---

111 return (-1);
112 nr = read(f->fd, buffer, MAXBUFSIZ);
113 break;
114 default:
115 /* Make sure we exit with an error */
116 nr = -1;
117 }
118#endif
69#ifndef WITHOUT_BZIP2
70static BZFILE* bzbufdesc;
71#endif
72
73static unsigned char *buffer;
74static unsigned char *bufpos;
75static size_t bufrem;
76static size_t fsiz;

--- 39 unchanged lines hidden (view full) ---

116 return (-1);
117 nr = read(f->fd, buffer, MAXBUFSIZ);
118 break;
119 default:
120 /* Make sure we exit with an error */
121 nr = -1;
122 }
123#endif
124#ifndef WITHOUT_LZMA
119 } else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) {
120 lzma_action action = LZMA_RUN;
121 uint8_t in_buf[MAXBUFSIZ];
122 lzma_ret ret;
123
124 ret = (filebehave == FILE_XZ) ?
125 lzma_stream_decoder(&lstrm, UINT64_MAX,
126 LZMA_CONCATENATED) :

--- 14 unchanged lines hidden (view full) ---

141
142 lstrm.avail_in = nr;
143 ret = lzma_code(&lstrm, action);
144
145 if (ret != LZMA_OK && ret != LZMA_STREAM_END)
146 return (-1);
147 bufrem = MAXBUFSIZ - lstrm.avail_out;
148 return (0);
125 } else if ((filebehave == FILE_XZ) || (filebehave == FILE_LZMA)) {
126 lzma_action action = LZMA_RUN;
127 uint8_t in_buf[MAXBUFSIZ];
128 lzma_ret ret;
129
130 ret = (filebehave == FILE_XZ) ?
131 lzma_stream_decoder(&lstrm, UINT64_MAX,
132 LZMA_CONCATENATED) :

--- 14 unchanged lines hidden (view full) ---

147
148 lstrm.avail_in = nr;
149 ret = lzma_code(&lstrm, action);
150
151 if (ret != LZMA_OK && ret != LZMA_STREAM_END)
152 return (-1);
153 bufrem = MAXBUFSIZ - lstrm.avail_out;
154 return (0);
155#endif /* WIHTOUT_LZMA */
149 } else
150 nr = read(f->fd, buffer, MAXBUFSIZ);
151
152 if (nr < 0)
153 return (-1);
154
155 bufrem = nr;
156 return (0);

--- 169 unchanged lines hidden ---
156 } else
157 nr = read(f->fd, buffer, MAXBUFSIZ);
158
159 if (nr < 0)
160 return (-1);
161
162 bufrem = nr;
163 return (0);

--- 169 unchanged lines hidden ---