Subject: Re: zlib #ifdef in headers
To: None <gwr@netbsd.org, tron@netbsd.org, tech-userlevel@netbsd.org>
From: None <itojun@iijlab.net>
List: tech-userlevel
Date: 08/31/2000 19:48:37
> i'm thinking of removing unnecessary #ifdef crufts from those headers,
> or disabling them by wrapping those with #ifdef __NetBSD__ (or
> #ifndef __NetBSD__).
for example, like this (with #if 0/1 - ugly, i should do it better).
itojun
Index: deflate.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/deflate.h,v
retrieving revision 1.6
diff -c -r1.6 deflate.h
*** deflate.h 1999/07/03 12:30:53 1.6
--- deflate.h 2000/08/31 10:46:41
***************
*** 235,241 ****
uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
! #ifdef DEBUG
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
--- 235,241 ----
uInt matches; /* number of string matches in current block */
int last_eob_len; /* bit length of EOB code for last block */
! #if 0 /*def DEBUG*/
ulg compressed_len; /* total bit length of compressed file mod 2^32 */
ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
#endif
***************
*** 283,292 ****
* used.
*/
! #ifndef DEBUG
/* Inline versions of _tr_tally for speed: */
! #if defined(GEN_TREES_H) || !defined(STDC)
extern uch _length_code[];
extern uch _dist_code[];
#else
--- 283,292 ----
* used.
*/
! #if 1 /*ndef DEBUG*/
/* Inline versions of _tr_tally for speed: */
! #if 0 /*defined(GEN_TREES_H) || !defined(STDC)*/
extern uch _length_code[];
extern uch _dist_code[];
#else
Index: zconf.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/zconf.h,v
retrieving revision 1.8
diff -c -r1.8 zconf.h
*** zconf.h 1999/10/26 03:42:58 1.8
--- zconf.h 2000/08/31 10:46:41
***************
*** 23,29 ****
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
! #ifdef Z_PREFIX
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
--- 23,29 ----
* If you *really* need a unique prefix for all types and library functions,
* compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
*/
! #if 0 /*def Z_PREFIX*/
# define deflateInit_ z_deflateInit_
# define deflate z_deflate
# define deflateEnd z_deflateEnd
***************
*** 59,82 ****
--- 59,87 ----
# define voidp z_voidp
#endif
+ #if 0
#ifndef __32BIT__
/* Don't be alarmed; this just means we have at least 32-bits */
# define __32BIT__
#endif
+ #endif
/*
* Compile with -DMAXSEG_64K if the alloc function cannot allocate more
* than 64k bytes at a time (needed on systems with 16-bit int).
*/
+ #if 0
#if defined(MSDOS) && !defined(__32BIT__)
# define MAXSEG_64K
#endif
+ #endif
#if 0
/* XXX: Are there machines where we should define this? m68k? */
# define UNALIGNED_OK
#endif
+ #if 0
#if (defined(__STDC__) || defined(__cplusplus)) && !defined(STDC)
/* XXX: Look out - this is used in zutil.h and elsewhere... */
# define STDC
***************
*** 86,124 ****
# define STDC
# endif
#endif
#ifndef STDC
# ifndef const
# define const
# endif
#endif
/* Some Mac compilers merge all .h files incorrectly: */
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
/* Old Borland C incorrectly complains about missing returns: */
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
/* Maximum value for memLevel in deflateInit2 */
#ifndef MAX_MEM_LEVEL
! # ifdef MAXSEG_64K
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
! #ifndef MAX_WBITS
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
--- 91,142 ----
# define STDC
# endif
#endif
+ #else
+ # define STDC
+ #endif
+ #if 0
#ifndef STDC
# ifndef const
# define const
# endif
#endif
+ #endif
/* Some Mac compilers merge all .h files incorrectly: */
+ #if 0
#if defined(__MWERKS__) || defined(applec) ||defined(THINK_C) ||defined(__SC__)
# define NO_DUMMY_DECL
#endif
+ #endif
/* Old Borland C incorrectly complains about missing returns: */
+ #if 0
#if defined(__BORLANDC__) && (__BORLANDC__ < 0x500)
# define NEED_DUMMY_RETURN
#endif
+ #endif
/* Maximum value for memLevel in deflateInit2 */
+ #if 0
#ifndef MAX_MEM_LEVEL
! # if 0 /*def MAXSEG_64K*/
# define MAX_MEM_LEVEL 8
# else
# define MAX_MEM_LEVEL 9
# endif
#endif
+ #else
+ # define MAX_MEM_LEVEL 9
+ #endif
/* Maximum value for windowBits in deflateInit2 and inflateInit2.
* WARNING: reducing MAX_WBITS makes minigzip unable to extract .gz files
* created by gzip. (Files created by minigzip can still be extracted by
* gzip.)
*/
! #if 1 /*ndef MAX_WBITS*/
# define MAX_WBITS 15 /* 32K LZ77 window */
#endif
***************
*** 137,142 ****
--- 155,161 ----
/* Type declarations */
+ #if 0
#ifndef OF /* function prototypes */
# ifdef STDC
# define OF(args) args
***************
*** 144,149 ****
--- 163,171 ----
# define OF(args) ()
# endif
#endif
+ #else
+ # define OF __P
+ #endif
/* The following definitions for FAR are needed only for MSDOS mixed
* model programming (small or medium model with some far allocations).
***************
*** 151,156 ****
--- 173,179 ----
* to define NO_MEMCPY in zutil.h. If you don't need the mixed model,
* just define FAR to be empty.
*/
+ #if 0
#if (defined(M_I86SM) || defined(M_I86MM)) && !defined(__32BIT__)
/* MSC small or medium model */
# define SMALL_MEDIUM
***************
*** 166,174 ****
# define FAR _far
# endif
#endif
/* Compile with -DZLIB_DLL for Windows DLL support */
! #if defined(ZLIB_DLL)
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
--- 189,198 ----
# define FAR _far
# endif
#endif
+ #endif
/* Compile with -DZLIB_DLL for Windows DLL support */
! #if 0 /*defined(ZLIB_DLL)*/
# if defined(_WINDOWS) || defined(WINDOWS)
# ifdef FAR
# undef FAR
***************
*** 195,201 ****
# endif
#endif
! #if defined (__BEOS__)
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
--- 219,225 ----
# endif
#endif
! #if 0 /*defined (__BEOS__)*/
# if defined (ZLIB_DLL)
# define ZEXTERN extern __declspec(dllexport)
# else
***************
*** 203,229 ****
# endif
#endif
! #ifndef ZEXPORT
# define ZEXPORT
#endif
! #ifndef ZEXPORTVA
# define ZEXPORTVA
#endif
! #ifndef ZEXTERN
# define ZEXTERN extern
#endif
! #ifndef FAR
# define FAR
#endif
! #if !defined(MACOS) && !defined(TARGET_OS_MAC)
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
! #ifdef SMALL_MEDIUM
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
--- 227,253 ----
# endif
#endif
! #if 1 /*ndef ZEXPORT*/
# define ZEXPORT
#endif
! #if 1 /*ndef ZEXPORTVA*/
# define ZEXPORTVA
#endif
! #if 1 /*ndef ZEXTERN*/
# define ZEXTERN extern
#endif
! #if 1 /*ndef FAR*/ /*XXX*/
# define FAR
#endif
! #if 1 /*!defined(MACOS) && !defined(TARGET_OS_MAC)*/
typedef unsigned char Byte; /* 8 bits */
#endif
typedef unsigned int uInt; /* 16 bits or more */
typedef unsigned long uLong; /* 32 bits or more */
! #if 0 /*def SMALL_MEDIUM*/
/* Borland C/C++ and some old MSC versions ignore FAR inside typedef */
# define Bytef Byte FAR
#else
***************
*** 234,240 ****
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
! #ifdef STDC
typedef void FAR *voidpf;
typedef void *voidp;
#else
--- 258,264 ----
typedef uInt FAR uIntf;
typedef uLong FAR uLongf;
! #if 1 /*def STDC*/
typedef void FAR *voidpf;
typedef void *voidp;
#else
***************
*** 247,263 ****
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
! #ifndef SEEK_SET
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
! #ifndef z_off_t
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
! #if defined(__MVS__)
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
--- 271,287 ----
# include <unistd.h> /* for SEEK_* and off_t */
# define z_off_t off_t
#endif
! #if 0 /*ndef SEEK_SET*/
# define SEEK_SET 0 /* Seek from beginning of file. */
# define SEEK_CUR 1 /* Seek from current position. */
# define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
#endif
! #if 0 /*ndef z_off_t*/
# define z_off_t long
#endif
/* MVS linker does not support external names larger than 8 bytes */
! #if 0 /*defined(__MVS__)*/
# pragma map(deflateInit_,"DEIN")
# pragma map(deflateInit2_,"DEIN2")
# pragma map(deflateEnd,"DEEND")
Index: zlib.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/zlib.h,v
retrieving revision 1.9
diff -c -r1.9 zlib.h
*** zlib.h 1999/10/26 22:16:48 1.9
--- zlib.h 2000/08/31 10:46:42
***************
*** 906,912 ****
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
! #if !defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
--- 906,912 ----
inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
! #if 0 /*!defined(_Z_UTIL_H) && !defined(NO_DUMMY_DECL)*/
struct internal_state {int dummy;}; /* hack for buggy compilers */
#endif
Index: zutil.h
===================================================================
RCS file: /cvsroot/basesrc/lib/libz/zutil.h,v
retrieving revision 1.9
diff -c -r1.9 zutil.h
*** zutil.h 1999/11/13 21:35:49 1.9
--- zutil.h 2000/08/31 10:46:42
***************
*** 23,41 ****
# include <lib/libkern/libkern.h>
#else
! #ifdef STDC
# include <stddef.h>
# include <string.h>
# include <stdlib.h>
#endif
! #ifdef NO_ERRNO_H
extern int errno;
#else
# include <errno.h>
#endif
#endif /* __NetBSD__ && _STANDALONE */
! #ifndef local
# define local static
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
--- 23,41 ----
# include <lib/libkern/libkern.h>
#else
! #if 1 /*def STDC*/
# include <stddef.h>
# include <string.h>
# include <stdlib.h>
#endif
! #if 0 /*def NO_ERRNO_H*/
extern int errno;
#else
# include <errno.h>
#endif
#endif /* __NetBSD__ && _STANDALONE */
! #if 1 /*ndef local*/
# define local static
#endif
/* compile with -Dlocal if your debugger can't find static symbols */
***************
*** 57,68 ****
/* common constants */
! #ifndef DEF_WBITS
# define DEF_WBITS MAX_WBITS
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
! #if MAX_MEM_LEVEL >= 8
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
--- 57,68 ----
/* common constants */
! #if 1 /*ndef DEF_WBITS*/
# define DEF_WBITS MAX_WBITS
#endif
/* default windowBits for decompression. MAX_WBITS is for compression only */
! #if 1 /*MAX_MEM_LEVEL >= 8*/
# define DEF_MEM_LEVEL 8
#else
# define DEF_MEM_LEVEL MAX_MEM_LEVEL
***************
*** 82,88 ****
/* target dependencies */
! #ifdef MSDOS
# define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
--- 82,88 ----
/* target dependencies */
! #if 0 /*def MSDOS*/
# define OS_CODE 0x00
# if defined(__TURBOC__) || defined(__BORLANDC__)
# if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
***************
*** 97,125 ****
# endif
#endif
! #ifdef OS2
# define OS_CODE 0x06
#endif
! #ifdef WIN32 /* Window 95 & Windows NT */
# define OS_CODE 0x0b
#endif
! #if defined(VAXC) || defined(VMS)
# define OS_CODE 0x02
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
! #ifdef AMIGA
# define OS_CODE 0x01
#endif
! #if defined(ATARI) || defined(atarist)
# define OS_CODE 0x05
#endif
! #if defined(MACOS) || defined(TARGET_OS_MAC)
# define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
--- 97,125 ----
# endif
#endif
! #if 0 /*def OS2*/
# define OS_CODE 0x06
#endif
! #if 0 /*def WIN32*/ /* Window 95 & Windows NT */
# define OS_CODE 0x0b
#endif
! #if 0 /*defined(VAXC) || defined(VMS)*/
# define OS_CODE 0x02
# define F_OPEN(name, mode) \
fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
#endif
! #if 0 /*def AMIGA*/
# define OS_CODE 0x01
#endif
! #if 0 /*defined(ATARI) || defined(atarist)*/
# define OS_CODE 0x05
#endif
! #if 0 /*defined(MACOS) || defined(TARGET_OS_MAC)*/
# define OS_CODE 0x07
# if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
# include <unix.h> /* for fdopen */
***************
*** 130,186 ****
# endif
#endif
! #ifdef __50SERIES /* Prime/PRIMOS */
# define OS_CODE 0x0F
#endif
! #ifdef TOPS20
# define OS_CODE 0x0a
#endif
! #if defined(_BEOS_) || defined(RISCOS)
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif
! #if (defined(_MSC_VER) && (_MSC_VER > 600))
# define fdopen(fd,type) _fdopen(fd,type)
#endif
/* Common defaults */
! #ifndef OS_CODE
# define OS_CODE 0x03 /* assume Unix */
#endif
! #ifndef F_OPEN
# define F_OPEN(name, mode) fopen((name), (mode))
#endif
/* functions */
! #ifdef HAVE_STRERROR
extern char *strerror OF((int));
# define zstrerror(errnum) strerror(errnum)
#else
# define zstrerror(errnum) ""
#endif
! #if defined(pyr)
# define NO_MEMCPY
#endif
! #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
/* Use our own functions for small and medium model with MSC <= 5.0.
* You may have to use the same strategy for Borland C (untested).
* The __SC__ check is for Symantec.
*/
# define NO_MEMCPY
#endif
! #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
# define HAVE_MEMCPY
#endif
#ifdef HAVE_MEMCPY
! # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
# define zmemcpy _fmemcpy
# define zmemcmp _fmemcmp
# define zmemzero(dest, len) _fmemset(dest, 0, len)
--- 130,186 ----
# endif
#endif
! #if 0 /*def __50SERIES*/ /* Prime/PRIMOS */
# define OS_CODE 0x0F
#endif
! #if 0 /*def TOPS20*/
# define OS_CODE 0x0a
#endif
! #if 0 /*defined(_BEOS_) || defined(RISCOS)*/
# define fdopen(fd,mode) NULL /* No fdopen() */
#endif
! #if 0 /*(defined(_MSC_VER) && (_MSC_VER > 600))*/
# define fdopen(fd,type) _fdopen(fd,type)
#endif
/* Common defaults */
! #if 1 /*ndef OS_CODE*/
# define OS_CODE 0x03 /* assume Unix */
#endif
! #if 1 /*ndef F_OPEN*/
# define F_OPEN(name, mode) fopen((name), (mode))
#endif
/* functions */
! #if 1 /*def HAVE_STRERROR*/
extern char *strerror OF((int));
# define zstrerror(errnum) strerror(errnum)
#else
# define zstrerror(errnum) ""
#endif
! #if 0 /*defined(pyr)*/
# define NO_MEMCPY
#endif
! #if 0 /*defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)*/
/* Use our own functions for small and medium model with MSC <= 5.0.
* You may have to use the same strategy for Borland C (untested).
* The __SC__ check is for Symantec.
*/
# define NO_MEMCPY
#endif
! #if 1 /*defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)*/
# define HAVE_MEMCPY
#endif
#ifdef HAVE_MEMCPY
! # if 0 /*def SMALL_MEDIUM*/ /* MSDOS small or medium model */
# define zmemcpy _fmemcpy
# define zmemcmp _fmemcmp
# define zmemzero(dest, len) _fmemset(dest, 0, len)
***************
*** 196,202 ****
#endif
/* Diagnostic functions */
! #if defined(DEBUG) && !defined(_KERNEL) && !defined(_STANDALONE)
# include <stdio.h>
extern int z_verbose;
extern void z_error OF((char *m));
--- 196,202 ----
#endif
/* Diagnostic functions */
! #if 0 /*defined(DEBUG) && !defined(_KERNEL) && !defined(_STANDALONE)*/
# include <stdio.h>
extern int z_verbose;
extern void z_error OF((char *m));