Home | History | Annotate | Line # | Download | only in libsa
cread.c revision 1.10
      1  1.10   thorpej /*	$NetBSD: cread.c,v 1.10 1999/11/11 20:23:16 thorpej Exp $	*/
      2   1.1       cgd 
      3   1.1       cgd /*
      4   1.1       cgd  * Copyright (c) 1996
      5   1.1       cgd  *	Matthias Drochner.  All rights reserved.
      6   1.1       cgd  *
      7   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      8   1.1       cgd  * modification, are permitted provided that the following conditions
      9   1.1       cgd  * are met:
     10   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     11   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     12   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     14   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     15   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     16   1.1       cgd  *    must display the following acknowledgement:
     17   1.1       cgd  *	This product includes software developed for the NetBSD Project
     18   1.1       cgd  *	by Matthias Drochner.
     19   1.1       cgd  * 4. The name of the author may not be used to endorse or promote products
     20   1.1       cgd  *    derived from this software without specific prior written permission.
     21   1.1       cgd  *
     22   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23   1.1       cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1       cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1       cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26   1.1       cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27   1.1       cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28   1.1       cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29   1.1       cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30   1.1       cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31   1.1       cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1       cgd  *
     33   1.1       cgd  */
     34   1.1       cgd 
     35   1.7        pk /*
     36   1.7        pk  * Support for compressed bootfiles  (only read)
     37   1.7        pk  *
     38   1.7        pk  * - replaces open(), close(), read(), lseek().
     39   1.7        pk  * - original libsa open(), close(), read(), lseek() are called
     40   1.7        pk  *   as oopen(), oclose(), oread() resp. olseek().
     41   1.7        pk  * - compression parts stripped from zlib:gzio.c
     42   1.1       cgd  */
     43   1.1       cgd 
     44   1.1       cgd /* gzio.c -- IO on .gz files
     45   1.1       cgd  * Copyright (C) 1995-1996 Jean-loup Gailly.
     46   1.1       cgd  * For conditions of distribution and use, see copyright notice in zlib.h
     47   1.1       cgd  */
     48   1.1       cgd 
     49   1.4  drochner #include "stand.h"
     50   1.4  drochner #ifdef _STANDALONE
     51   1.3  drochner #include <lib/libz/zlib.h>
     52   1.4  drochner #else
     53   1.4  drochner #include <string.h>
     54   1.4  drochner #include <zlib.h>
     55   1.4  drochner #endif
     56   1.1       cgd 
     57   1.1       cgd #define EOF (-1) /* needed by compression code */
     58   1.1       cgd 
     59   1.1       cgd #ifdef SAVE_MEMORY
     60   1.1       cgd #define Z_BUFSIZE 1024
     61   1.1       cgd #else
     62   1.1       cgd #define Z_BUFSIZE 4096
     63   1.1       cgd #endif
     64   1.1       cgd 
     65   1.7        pk static int gz_magic[2] = {0x1f, 0x8b};	/* gzip magic header */
     66   1.1       cgd 
     67   1.1       cgd /* gzip flag byte */
     68   1.7        pk #define ASCII_FLAG	0x01	/* bit 0 set: file probably ascii text */
     69   1.7        pk #define HEAD_CRC	0x02	/* bit 1 set: header CRC present */
     70   1.7        pk #define EXTRA_FIELD	0x04	/* bit 2 set: extra field present */
     71   1.7        pk #define ORIG_NAME	0x08	/* bit 3 set: original file name present */
     72   1.7        pk #define COMMENT		0x10	/* bit 4 set: file comment present */
     73   1.7        pk #define RESERVED	0xE0	/* bits 5..7: reserved */
     74   1.1       cgd 
     75   1.1       cgd static struct sd {
     76   1.7        pk 	z_stream	stream;
     77   1.7        pk 	int		z_err;	/* error code for last stream operation */
     78   1.7        pk 	int		z_eof;	/* set if end of input file */
     79   1.7        pk 	int		fd;
     80   1.7        pk 	unsigned char	*inbuf;	/* input buffer */
     81   1.7        pk 	unsigned long	crc;	/* crc32 of uncompressed data */
     82   1.7        pk 	int		compressed;	/* 1 if input file is a .gz file */
     83   1.1       cgd } *ss[SOPEN_MAX];
     84   1.1       cgd 
     85   1.7        pk static int		get_byte __P((struct sd *));
     86   1.7        pk static unsigned long	getLong __P((struct sd *));
     87   1.7        pk static void		check_header __P((struct sd *));
     88   1.7        pk 
     89   1.7        pk /* XXX - find suitable headerf ile for these: */
     90   1.7        pk void	*zcalloc __P((void *, unsigned int, unsigned int));
     91   1.7        pk void	zcfree __P((void *, void *));
     92   1.7        pk void	zmemcpy __P((unsigned char *, unsigned char *, unsigned int));
     93   1.7        pk 
     94   1.7        pk 
     95   1.1       cgd /*
     96   1.1       cgd  * compression utilities
     97   1.1       cgd  */
     98   1.1       cgd 
     99   1.7        pk void *
    100   1.7        pk zcalloc (opaque, items, size)
    101   1.7        pk 	void *opaque;
    102   1.7        pk 	unsigned items;
    103   1.7        pk 	unsigned size;
    104   1.1       cgd {
    105   1.7        pk 	return(alloc(items * size));
    106   1.1       cgd }
    107   1.1       cgd 
    108   1.7        pk void
    109   1.7        pk zcfree (opaque, ptr)
    110   1.7        pk 	void *opaque;
    111   1.7        pk 	void *ptr;
    112   1.1       cgd {
    113   1.7        pk 	free(ptr, 0); /* XXX works only with modified allocator */
    114   1.1       cgd }
    115   1.1       cgd 
    116   1.7        pk void
    117   1.7        pk zmemcpy(dest, source, len)
    118   1.7        pk 	unsigned char *dest;
    119   1.7        pk 	unsigned char *source;
    120   1.7        pk 	unsigned int len;
    121   1.1       cgd {
    122   1.7        pk 	bcopy(source, dest, len);
    123   1.1       cgd }
    124   1.1       cgd 
    125   1.7        pk static int
    126   1.7        pk get_byte(s)
    127   1.7        pk 	struct sd *s;
    128   1.1       cgd {
    129   1.7        pk 	if (s->z_eof)
    130   1.7        pk 		return (EOF);
    131   1.7        pk 
    132   1.7        pk 	if (s->stream.avail_in == 0) {
    133   1.7        pk 		int got;
    134   1.7        pk 
    135   1.7        pk 		errno = 0;
    136   1.7        pk 		got = oread(s->fd, s->inbuf, Z_BUFSIZE);
    137   1.7        pk 		if (got <= 0) {
    138   1.7        pk 			s->z_eof = 1;
    139   1.7        pk 			if (errno) s->z_err = Z_ERRNO;
    140   1.7        pk 			return EOF;
    141   1.7        pk 		}
    142   1.7        pk 		s->stream.avail_in = got;
    143   1.7        pk 		s->stream.next_in = s->inbuf;
    144   1.7        pk 	}
    145   1.7        pk 	s->stream.avail_in--;
    146   1.7        pk 	return *(s->stream.next_in)++;
    147   1.1       cgd }
    148   1.1       cgd 
    149   1.7        pk static unsigned long
    150   1.7        pk getLong (s)
    151   1.1       cgd     struct sd *s;
    152   1.1       cgd {
    153   1.7        pk 	unsigned long x = (unsigned long)get_byte(s);
    154   1.7        pk 	int c;
    155   1.1       cgd 
    156   1.7        pk 	x += ((unsigned long)get_byte(s)) << 8;
    157   1.7        pk 	x += ((unsigned long)get_byte(s)) << 16;
    158   1.7        pk 	c = get_byte(s);
    159   1.7        pk 	if (c == EOF)
    160   1.7        pk 		s->z_err = Z_DATA_ERROR;
    161   1.7        pk 	x += ((unsigned long)c)<<24;
    162   1.7        pk 	return x;
    163   1.1       cgd }
    164   1.1       cgd 
    165   1.7        pk static void
    166   1.7        pk check_header(s)
    167   1.7        pk 	struct sd *s;
    168   1.1       cgd {
    169   1.7        pk 	int method; /* method byte */
    170   1.7        pk 	int flags;  /* flags byte */
    171   1.7        pk 	unsigned int len;
    172   1.7        pk 	int c;
    173   1.7        pk 
    174   1.7        pk 	/* Check the gzip magic header */
    175   1.7        pk 	for (len = 0; len < 2; len++) {
    176   1.7        pk 		c = get_byte(s);
    177   1.7        pk 		if (c == gz_magic[len])
    178   1.7        pk 			continue;
    179   1.7        pk 		if ((c == EOF) && (len == 0))  {
    180   1.7        pk 			/*
    181   1.7        pk 			 * We must not change s->compressed if we are at EOF;
    182   1.7        pk 			 * we may have come to the end of a gzipped file and be
    183   1.7        pk 			 * check to see if another gzipped file is concatenated
    184   1.7        pk 			 * to this one. If one isn't, we still need to be able
    185   1.7        pk 			 * to lseek on this file as a compressed file.
    186   1.7        pk 			 */
    187   1.7        pk 			return;
    188   1.7        pk 		}
    189   1.7        pk 		s->compressed = 0;
    190   1.7        pk 		if (c != EOF) {
    191   1.7        pk 			s->stream.avail_in++;
    192   1.7        pk 			s->stream.next_in--;
    193   1.7        pk 		}
    194   1.7        pk 		s->z_err = s->stream.avail_in != 0 ? Z_OK : Z_STREAM_END;
    195   1.7        pk 		return;
    196   1.7        pk 	}
    197   1.7        pk 	s->compressed = 1;
    198   1.7        pk 	method = get_byte(s);
    199   1.7        pk 	flags = get_byte(s);
    200   1.7        pk 	if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
    201   1.7        pk 		s->z_err = Z_DATA_ERROR;
    202   1.7        pk 		return;
    203   1.7        pk 	}
    204   1.1       cgd 
    205   1.7        pk 	/* Discard time, xflags and OS code: */
    206   1.7        pk 	for (len = 0; len < 6; len++)
    207   1.7        pk 		(void)get_byte(s);
    208   1.7        pk 
    209   1.7        pk 	if ((flags & EXTRA_FIELD) != 0) {
    210   1.7        pk 		/* skip the extra field */
    211   1.7        pk 		len  =  (unsigned int)get_byte(s);
    212   1.7        pk 		len += ((unsigned int)get_byte(s)) << 8;
    213   1.7        pk 		/* len is garbage if EOF but the loop below will quit anyway */
    214   1.7        pk 		while (len-- != 0 && get_byte(s) != EOF) /*void*/;
    215   1.7        pk 	}
    216   1.7        pk 	if ((flags & ORIG_NAME) != 0) {
    217   1.7        pk 		/* skip the original file name */
    218   1.7        pk 		while ((c = get_byte(s)) != 0 && c != EOF) /*void*/;
    219   1.7        pk 	}
    220   1.7        pk 	if ((flags & COMMENT) != 0) {
    221   1.7        pk 		/* skip the .gz file comment */
    222   1.7        pk 		while ((c = get_byte(s)) != 0 && c != EOF) /*void*/;
    223   1.7        pk 	}
    224   1.7        pk 	if ((flags & HEAD_CRC) != 0) {  /* skip the header crc */
    225   1.7        pk 		for (len = 0; len < 2; len++)
    226   1.7        pk 			(void)get_byte(s);
    227   1.7        pk 	}
    228   1.7        pk 	s->z_err = s->z_eof ? Z_DATA_ERROR : Z_OK;
    229   1.1       cgd }
    230   1.1       cgd 
    231   1.1       cgd /*
    232   1.1       cgd  * new open(), close(), read(), lseek()
    233   1.1       cgd  */
    234   1.1       cgd 
    235   1.1       cgd int
    236   1.1       cgd open(fname, mode)
    237   1.1       cgd 	const char *fname;
    238   1.1       cgd 	int mode;
    239   1.1       cgd {
    240   1.7        pk 	int fd;
    241   1.7        pk 	struct sd *s = 0;
    242   1.1       cgd 
    243   1.7        pk 	if ( ((fd = oopen(fname, mode)) == -1) || (mode != 0) )
    244   1.7        pk 		/* compression only for read */
    245   1.7        pk 		return(fd);
    246   1.7        pk 
    247   1.7        pk 	ss[fd] = s = alloc(sizeof(struct sd));
    248   1.7        pk 	if (s == 0)
    249   1.7        pk 		goto errout;
    250   1.7        pk 	bzero(s, sizeof(struct sd));
    251   1.7        pk 
    252   1.7        pk 	if (inflateInit2(&(s->stream), -15) != Z_OK)
    253   1.7        pk 		goto errout;
    254   1.7        pk 
    255   1.7        pk 	s->stream.next_in  = s->inbuf = (unsigned char*)alloc(Z_BUFSIZE);
    256   1.7        pk 	if (s->inbuf == 0) {
    257   1.7        pk 		inflateEnd(&(s->stream));
    258   1.7        pk 		goto errout;
    259   1.7        pk 	}
    260   1.7        pk 
    261   1.7        pk 	s->fd = fd;
    262   1.7        pk 	check_header(s); /* skip the .gz header */
    263   1.7        pk 	return(fd);
    264   1.1       cgd 
    265   1.1       cgd errout:
    266   1.7        pk 	if (s != 0)
    267   1.7        pk 		free(s, sizeof(struct sd));
    268   1.7        pk 	oclose(fd);
    269   1.7        pk 	return (-1);
    270   1.1       cgd }
    271   1.1       cgd 
    272   1.1       cgd int
    273   1.1       cgd close(fd)
    274   1.1       cgd 	int fd;
    275   1.1       cgd {
    276   1.2   thorpej 	struct open_file *f;
    277   1.7        pk 	struct sd *s;
    278   1.2   thorpej 
    279   1.9       cgd #if !defined(LIBSA_NO_FD_CHECKING)
    280   1.2   thorpej 	if ((unsigned)fd >= SOPEN_MAX) {
    281   1.2   thorpej 		errno = EBADF;
    282   1.2   thorpej 		return (-1);
    283   1.2   thorpej 	}
    284   1.9       cgd #endif
    285   1.2   thorpej 	f = &files[fd];
    286   1.2   thorpej 
    287   1.7        pk 	if ((f->f_flags & F_READ) == 0)
    288   1.2   thorpej 		return(oclose(fd));
    289   1.1       cgd 
    290   1.1       cgd 	s = ss[fd];
    291   1.1       cgd 
    292   1.1       cgd 	inflateEnd(&(s->stream));
    293   1.1       cgd 
    294   1.1       cgd 	free(s->inbuf, Z_BUFSIZE);
    295   1.1       cgd 	free(s, sizeof(struct sd));
    296   1.1       cgd 
    297   1.7        pk 	return (oclose(fd));
    298   1.1       cgd }
    299   1.1       cgd 
    300   1.1       cgd ssize_t
    301   1.1       cgd read(fd, buf, len)
    302   1.1       cgd 	int fd;
    303   1.1       cgd 	void *buf;
    304   1.1       cgd 	size_t len;
    305   1.1       cgd {
    306   1.7        pk 	struct sd *s;
    307   1.7        pk 	unsigned char *start = buf; /* starting point for crc computation */
    308   1.1       cgd 
    309   1.7        pk 	s = ss[fd];
    310   1.1       cgd 
    311   1.7        pk 	if (s->z_err == Z_DATA_ERROR || s->z_err == Z_ERRNO)
    312   1.7        pk 		return (-1);
    313   1.7        pk 	if (s->z_err == Z_STREAM_END)
    314   1.7        pk 		return (0);  /* EOF */
    315   1.1       cgd 
    316   1.7        pk 	s->stream.next_out = buf;
    317   1.7        pk 	s->stream.avail_out = len;
    318   1.7        pk 
    319   1.7        pk 	while (s->stream.avail_out != 0) {
    320   1.7        pk 
    321   1.7        pk 		if (s->compressed == 0) {
    322   1.7        pk 			/* Copy first the lookahead bytes: */
    323   1.7        pk 			unsigned int n = s->stream.avail_in;
    324   1.7        pk 			if (n > s->stream.avail_out)
    325   1.7        pk 				n = s->stream.avail_out;
    326   1.7        pk 			if (n > 0) {
    327   1.7        pk 				zmemcpy(s->stream.next_out,
    328   1.7        pk 					s->stream.next_in, n);
    329   1.7        pk 				s->stream.next_out  += n;
    330   1.7        pk 				s->stream.next_in   += n;
    331   1.7        pk 				s->stream.avail_out -= n;
    332   1.7        pk 				s->stream.avail_in  -= n;
    333   1.7        pk 			}
    334   1.7        pk 			if (s->stream.avail_out > 0) {
    335   1.7        pk 				int got;
    336   1.7        pk 				got = oread(s->fd, s->stream.next_out,
    337   1.7        pk 					    s->stream.avail_out);
    338   1.7        pk 				if (got == -1)
    339   1.7        pk 					return (got);
    340   1.7        pk 				s->stream.avail_out -= got;
    341   1.7        pk 			}
    342   1.7        pk 			return (int)(len - s->stream.avail_out);
    343   1.7        pk 		}
    344   1.7        pk 
    345   1.7        pk 		if (s->stream.avail_in == 0 && !s->z_eof) {
    346   1.7        pk 			int got;
    347   1.7        pk 			errno = 0;
    348   1.7        pk 			got = oread(fd, s->inbuf, Z_BUFSIZE);
    349   1.7        pk 			if (got <= 0) {
    350   1.7        pk 				s->z_eof = 1;
    351   1.7        pk 				if (errno) {
    352   1.7        pk 					s->z_err = Z_ERRNO;
    353   1.7        pk 					break;
    354   1.7        pk 				}
    355   1.7        pk 			}
    356   1.7        pk 			s->stream.avail_in = got;
    357   1.7        pk 			s->stream.next_in = s->inbuf;
    358   1.1       cgd 		}
    359   1.1       cgd 
    360   1.7        pk 		s->z_err = inflate(&(s->stream), Z_NO_FLUSH);
    361   1.7        pk 
    362   1.7        pk 		if (s->z_err == Z_STREAM_END) {
    363   1.7        pk 			/* Check CRC and original size */
    364   1.7        pk 			s->crc = crc32(s->crc, start, (unsigned int)
    365   1.7        pk 					(s->stream.next_out - start));
    366   1.7        pk 			start = s->stream.next_out;
    367   1.7        pk 
    368   1.7        pk 			if (getLong(s) != s->crc ||
    369   1.7        pk 			    getLong(s) != s->stream.total_out) {
    370   1.7        pk 
    371   1.7        pk 				s->z_err = Z_DATA_ERROR;
    372   1.7        pk 			} else {
    373   1.7        pk 				/* Check for concatenated .gz files: */
    374   1.7        pk 				check_header(s);
    375   1.7        pk 				if (s->z_err == Z_OK) {
    376   1.7        pk 					inflateReset(&(s->stream));
    377   1.7        pk 					s->crc = crc32(0L, Z_NULL, 0);
    378   1.7        pk 				}
    379   1.7        pk 			}
    380   1.1       cgd 		}
    381   1.7        pk 		if (s->z_err != Z_OK || s->z_eof)
    382   1.7        pk 			break;
    383   1.7        pk 	}
    384   1.1       cgd 
    385   1.7        pk 	s->crc = crc32(s->crc, start,
    386   1.7        pk 		       (unsigned int)(s->stream.next_out - start));
    387   1.7        pk 
    388   1.7        pk 	return (int)(len - s->stream.avail_out);
    389   1.1       cgd }
    390   1.1       cgd 
    391   1.1       cgd off_t
    392   1.1       cgd lseek(fd, offset, where)
    393   1.1       cgd 	int fd;
    394   1.1       cgd 	off_t offset;
    395   1.1       cgd 	int where;
    396   1.1       cgd {
    397   1.7        pk 	struct open_file *f;
    398   1.7        pk 	struct sd *s;
    399   1.1       cgd 
    400   1.9       cgd #if !defined(LIBSA_NO_FD_CHECKING)
    401   1.7        pk 	if ((unsigned)fd >= SOPEN_MAX) {
    402   1.1       cgd 		errno = EBADF;
    403   1.1       cgd 		return (-1);
    404   1.7        pk 	}
    405   1.9       cgd #endif
    406   1.7        pk 	f = &files[fd];;
    407   1.1       cgd 
    408   1.8  drochner 	if ((f->f_flags & F_READ) == 0)
    409   1.1       cgd 		return(olseek(fd, offset, where));
    410   1.1       cgd 
    411   1.7        pk 	s = ss[fd];
    412   1.1       cgd 
    413   1.7        pk 	if(s->compressed == 0) {
    414   1.1       cgd 		off_t res = olseek(fd, offset, where);
    415   1.7        pk 		if (res != (off_t)-1) {
    416   1.7        pk 			/* make sure the lookahead buffer is invalid */
    417   1.7        pk 			s->stream.avail_in = 0;
    418   1.1       cgd 		}
    419   1.7        pk 		return (res);
    420   1.7        pk 	}
    421   1.1       cgd 
    422   1.7        pk 	switch(where) {
    423   1.7        pk 	case SEEK_CUR:
    424   1.1       cgd 		    offset += s->stream.total_out;
    425   1.7        pk 	case SEEK_SET:
    426   1.7        pk 		/* if seek backwards, simply start from the beginning */
    427   1.7        pk 		if (offset < s->stream.total_out) {
    428   1.1       cgd 			off_t res;
    429   1.1       cgd 			void *sav_inbuf;
    430   1.1       cgd 
    431   1.1       cgd 			res = olseek(fd, 0, SEEK_SET);
    432   1.1       cgd 			if(res == (off_t)-1)
    433   1.1       cgd 			    return(res);
    434   1.1       cgd 			/* ??? perhaps fallback to close / open */
    435   1.1       cgd 
    436   1.1       cgd 			inflateEnd(&(s->stream));
    437   1.1       cgd 
    438   1.1       cgd 			sav_inbuf = s->inbuf; /* don't allocate again */
    439   1.1       cgd 			bzero(s, sizeof(struct sd)); /* this resets total_out to 0! */
    440   1.1       cgd 
    441   1.1       cgd 			inflateInit2(&(s->stream), -15);
    442   1.1       cgd 			s->stream.next_in = s->inbuf = sav_inbuf;
    443   1.1       cgd 
    444   1.1       cgd 			s->fd = fd;
    445   1.1       cgd 			check_header(s); /* skip the .gz header */
    446   1.7        pk 		}
    447   1.1       cgd 
    448   1.1       cgd 		    /* to seek forwards, throw away data */
    449   1.7        pk 		if (offset > s->stream.total_out) {
    450   1.1       cgd 			off_t toskip = offset - s->stream.total_out;
    451   1.1       cgd 
    452   1.7        pk 			while (toskip > 0) {
    453   1.1       cgd #define DUMMYBUFSIZE 256
    454   1.7        pk 				char dummybuf[DUMMYBUFSIZE];
    455   1.7        pk 				off_t len = toskip;
    456   1.7        pk 				if (len > DUMMYBUFSIZE) len = DUMMYBUFSIZE;
    457   1.7        pk 				if (read(fd, dummybuf, len) != len) {
    458   1.7        pk 					errno = EOFFSET;
    459   1.7        pk 					return ((off_t)-1);
    460   1.7        pk 				}
    461   1.7        pk 				toskip -= len;
    462   1.1       cgd 			}
    463   1.7        pk 		}
    464   1.1       cgd #ifdef DEBUG
    465   1.7        pk 		if (offset != s->stream.total_out)
    466   1.1       cgd 			panic("lseek compressed");
    467   1.1       cgd #endif
    468   1.7        pk 		return (offset);
    469   1.7        pk 	case SEEK_END:
    470   1.7        pk 		errno = EOFFSET;
    471   1.7        pk 		break;
    472   1.7        pk 	default:
    473   1.7        pk 		errno = EINVAL;
    474   1.7        pk 	}
    475   1.7        pk 
    476   1.7        pk 	return((off_t)-1);
    477   1.1       cgd }
    478