Subject: Re: /usr/include/zconf.h uses HAVE_UNISTD_H
To: Chris G. Demetriou <cgd@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-userlevel
Date: 10/15/1999 10:40:26
------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <26873.939951613.1@coconut.itojun.org>
Content-Transfer-Encoding: 7bit

>No, but neither an I a shared library wizard.
>grep in /usr/include for __RENAME for examples of other functions
>which have been 'fixed' or 'improved' in backward-compatible manners.
>in a nutshell, something like:
>In the library sources, provide a new gzseek() function with an
>appropriate name (__gzseek_15?!) which takes a z_off_t (now an off_t),
>and have a gzseek() function which takes a long rather than a z_off_t
>(and which just turns around and calls the new function).

	Is it good enough?  "make build" goes fine, and the test program
	compiles as expected.

itojun


------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <26873.939951613.2@coconut.itojun.org>
Content-Transfer-Encoding: 7bit

itojun[turmeric:/tmp] cat hoge.c
#include <zlib.h>

main()
{
	gztell(gzopen("hoge", "r"));
}
itojun[turmeric:/tmp] cc hoge.c -lz
itojun[turmeric:/tmp] nm -n a.out | grep U
         U __gztell15
         U __syscall
         U atexit
         U exit
         U gzopen
itojun[turmeric:/tmp] cc -E hoge.c >moga

(moga contains following lines)

extern  off_t       gzseek  (gzFile file,
                                      off_t  offset, int whence)  
                                      __asm__("__gzseek15"  ) ;
extern  off_t       gztell  (gzFile file)   __asm__("__gztell15"  ) ;


------- =_aaaaaaaaaa0
Content-Type: text/plain; charset="us-ascii"
Content-ID: <26873.939951613.3@coconut.itojun.org>
Content-Transfer-Encoding: 7bit

? gzio_compat.c
Index: Makefile
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/Makefile,v
retrieving revision 1.13
diff -c -r1.13 Makefile
*** Makefile	1999/07/09 07:07:13	1.13
--- Makefile	1999/10/15 01:27:46
***************
*** 6,11 ****
--- 6,12 ----
  SRCS=	adler32.c compress.c crc32.c deflate.c gzio.c infblock.c \
  	infcodes.c inffast.c inflate.c inftrees.c infutil.c trees.c uncompr.c \
  	zutil.c
+ SRCS+=	gzio_compat.c
  
  CPPFLAGS+= -I${.CURDIR}
  
Index: zconf.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/zconf.h,v
retrieving revision 1.7
diff -c -r1.7 zconf.h
*** zconf.h	1999/07/03 12:30:57	1.7
--- zconf.h	1999/10/15 01:27:48
***************
*** 242,248 ****
     typedef Byte     *voidp;
  #endif
  
! #ifdef HAVE_UNISTD_H
  #  include <sys/types.h> /* for off_t */
  #  include <unistd.h>    /* for SEEK_* and off_t */
  #  define z_off_t  off_t
--- 242,248 ----
     typedef Byte     *voidp;
  #endif
  
! #if defined(HAVE_UNISTD_H) || defined(__NetBSD__)
  #  include <sys/types.h> /* for off_t */
  #  include <unistd.h>    /* for SEEK_* and off_t */
  #  define z_off_t  off_t
Index: zlib.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/zlib.h,v
retrieving revision 1.7
diff -c -r1.7 zlib.h
*** zlib.h	1999/07/03 12:30:57	1.7
--- zlib.h	1999/10/15 01:27:51
***************
*** 33,38 ****
--- 33,42 ----
  #ifndef _ZLIB_H
  #define _ZLIB_H
  
+ #ifdef __NetBSD__
+ #include <sys/cdefs.h>
+ #endif
+ 
  #include "zconf.h"
  
  #ifdef __cplusplus
***************
*** 754,763 ****
     the flush parameter is Z_FINISH and all output could be flushed.
       gzflush should be called only when strictly necessary because it can
     degrade compression.
  */
  
  ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
! 				      z_off_t offset, int whence));
  /* 
        Sets the starting position for the next gzread or gzwrite on the
     given compressed file. The offset represents a number of bytes in the
--- 758,778 ----
     the flush parameter is Z_FINISH and all output could be flushed.
       gzflush should be called only when strictly necessary because it can
     degrade compression.
+ 
  */
  
+ /* 
+  * NetBSD note:
+  * "long" gzseek has been there till Oct 1999 (1.5L), which was wrong.
+  */
+ #ifdef __ZLIB_BACKWARD_COMPAT
+ ZEXTERN long ZEXPORT    gzseek OF((gzFile file,
+ 				      long offset, int whence));
+ #else
  ZEXTERN z_off_t ZEXPORT    gzseek OF((gzFile file,
! 				      z_off_t offset, int whence))
! 				      __RENAME(__gzseek15);
! #endif
  /* 
        Sets the starting position for the next gzread or gzwrite on the
     given compressed file. The offset represents a number of bytes in the
***************
*** 781,787 ****
     gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
  */
  
! ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file));
  /*
       Returns the starting position for the next gzread or gzwrite on the
     given compressed file. This position represents a number of bytes in the
--- 796,810 ----
     gzrewind(file) is equivalent to (int)gzseek(file, 0L, SEEK_SET)
  */
  
! /* 
!  * NetBSD note:
!  * "long" gztell has been there till Oct 1999 (1.5L), which was wrong.
!  */
! #ifdef __ZLIB_BACKWARD_COMPAT
! ZEXTERN long ZEXPORT    gztell OF((gzFile file));
! #else
! ZEXTERN z_off_t ZEXPORT    gztell OF((gzFile file)) __RENAME(__gztell15);
! #endif
  /*
       Returns the starting position for the next gzread or gzwrite on the
     given compressed file. This position represents a number of bytes in the
*** /dev/null	Thu Oct 14 14:26:03 1999
--- gzio_compat.c	Thu Oct 14 12:43:37 1999
***************
*** 0 ****
--- 1,23 ----
+ /* $NetBSD$ */
+ 
+ #include <stdio.h>
+ 
+ #define __ZLIB_BACKWARD_COMPAT
+ #include "zutil.h"
+ 
+ extern z_off_t __gzseek15 __P((gzFile, z_off_t, int));
+ extern long __gztell15 __P((gzFile));
+ 
+ long ZEXPORT gzseek (file, offset, whence)
+     gzFile file;
+     long offset;
+     int whence;
+ {
+     return (long)__gzseek15(file, (off_t)offset, whence);
+ }
+ 
+ long ZEXPORT gztell (file)
+     gzFile file;
+ {
+     return (long)__gztell15(file);
+ }

------- =_aaaaaaaaaa0--