From: noer AT cygnus DOT com (Geoffrey Noer) Subject: Re: include files 20 May 1998 20:18:36 -0700 Message-ID: <199805210300.UAA02748.cygnus.cygwin32.developers@skaro.cygnus.com> References: Content-Type: text To: newsham AT lava DOT net (Tim Newsham) Cc: cygwin32-developers AT cygnus DOT com Tim Newsham wrote: > > I went over the includes and made some minor additions and some > notes on more major changes. Here they are. Following are my comments. > General notes: > > - There is both an asm and a machine subdirectory for what seems > to be the same purpose -- machine/arch dependant definitions. > Probably should merge these two into a single directory (I noticed > there are only i386 definitions here, aren't there other cygwin > ports?) This is part of the problem of having the include files be divided between newlib and winsup the way they are. Newlib uses "machine/arch", winsup has an asm directory. i386 is the only architecture that's supported at present. It would be cleaner to have those headers in asm/i386 or move them into newlib as you suggest. > - should probably include (and possibly > pull in machine specific defines from {machine,asm}/param.h). It now includes sys/types.h. I moved it to newlib/libc/sys/cygwin32/sys where it belongs. > - has all sorts of cruft in it that is not relevant > to cygwin. Is it necessary to share these includes with other > systems, or can the cruft be taken out? Without all the cruft, > this file can be quite simple. types.h is a generic include from newlib and *does* have to have the support for other systems. > - Windows32/Sockets.h does not have all of the winsock definitions > that are defined. For example the setsockopt options are missing. > Here are some missing defines: > > +/* socket options for {set,get}sockopt() */ > +#define SO_DEBUG 0x0001 > +#define SO_ACCEPTCONN 0x0002 > +#define SO_REUSEADDR 0x0004 > +#define SO_KEEPALIVE 0x0008 > +#define SO_DONTROUTE 0x0010 > +#define SO_BROADCAST 0x0020 > +#define SO_USELOOPBACK 0x0040 > +#define SO_LINGER 0x0080 > +#define SO_OOBINLINE 0x0100 > + > +#define SO_DONTLINGER (u_int)(~SO_LINGER) > + > +#define SO_SNDBUF 0x1001 > +#define SO_RCVBUF 0x1002 > +#define SO_SNDLOWAT 0x1003 /* unsup */ > +#define SO_RCVLOWAT 0x1004 /* unsup */ > +#define SO_SNDTIMEO 0x1005 /* unsup */ > +#define SO_RCVTIMEO 0x1006 /* unsup */ > +#define SO_ERROR 0x1007 > +#define SO_TYPE 0x1008 These are all defined in my copy of winsup/include/Windows32/Sockets.h... > - several machine-dependant types are not defined, probably should > go in {asm,machine}/types.h and be included by sys/types.h. These > are (possibly not all necessary): > > +typedef unsigned long vm_offset_t; > +typedef unsigned long vm_size_t; > + > +#define __BIT_TYPES_DEFINED__ > +typedef char int8_t; > +typedef unsigned char u_int8_t; > +typedef short int16_t; > +typedef unsigned short u_int16_t; > +typedef int int32_t; > +typedef unsinged int u_int32_t; > +typedef long long int64_t; > +typedef unsigned long long u_int64_t; > + > +typedef int32_t register_t; newlib/libc/include/sys/types.h already has MS-specific defines, so I'm going to add these there (for now, at least). > - some common sys/cdefs.h macros are missing: > > +#define __P(x) x > +#define __CONCAT(x,y) x ## y > +#define __STRING(x) #x > + > +/* XXX __{const,volatile,etc..} ? */ I added __P(x), __CONCAT(x,y), __STRING(x), and __DOTS to winsup/include/sys/cdefs.h. > - sys/param.h does not define NULL, does not define a cygwin version, > does not define NOFILE_MAX. It doesn't include as > is often done (why? dunno). It doesn't define several common macros. > It does define some endian things which should probably be in a > {asm,machine}/endian.h file and included from instead > (with included by ) > +#include > +#include > + > +#define CYGWIN 199804 > +#define CYGWINb_19 1 > + > +#ifndef NULL > +#define NULL 0 > +#endif > [...] > +#define NOFILE_MAX NOFILE > [...] > +#include > + > +/* bitmap macros */ > +#define setbit(a,i) ((a)[(i)/NBBY] |= 1 << ((i) % NBBY)) > +#define clrbit(a,i) ((a)[(i)/NBBY] ^= ~(1 << ((i) % NBBY))) > +#define isset(a,i) ((a)[(i)/NBBY] & (1 << ((i) % NBBY))) > +#define isclr(a,i) (((a)[(i)/NBBY] & (1 << ((i) % NBBY))) == 0) > + > +#ifndef howmany > +#define howmany(x,y) (((x) + ((y) - 1)) / (y)) > +#endif > +#define roundup(x,y) ((((x) + ((y) - 1)) / (y)) * (y)) > +#define powerof2(x) ((((x) - 1) & (x)) == 0) > + > +#define MIN(a,b) (((a) < (b)) ? (a) : (b)) > +#define MAX(a,b) (((a) > (b)) ? (a) : (b)) 1) I added the NULL definition. 2) Is it really a good idea to add a CYGWIN/CYGWINb_19 define? Cygwin versions are currently in winsup/version.h. I like having these defined in the winsup directory somewhere... 3) isn't included in param.h in either Linux or Solaris. 4) NOFILE_MAX isn't defined in any Linux or Solaris include files. Is it really needed? 5) Under Linux, MIN and MAX are defined in compat.h. Solaris defines them in sys/sysmacros.h. Where should we put them? 6) Under Solaris, bitmap macros are defined in fs/ufs_fs.h. Under Linux, they're only to be found in the g++ headers. Do we want them defined under Cygwin32? 7) Solaris defines howmany in sysmacros.h and select.h. Linux defines it in sys/param.h and sys/types.h. Where should we put them? 8) Solaris defines roundup in sysmacros.h. Linux defines it in sys/param.h and sys/types.h. Where should we put them? 9) Solaris doesn't define powerof2. Neither does Linux. Sounds like we don't really need it for Cygwin32 unless it's a common MS define. > - sys/time.h does not define the POSIX timespec structure or operations > on it, and does not define the CLOCK_{RELTIME,VIRTUAL,PROF} constants. Linux doesn't seem to define the CLOCK_ constants or the timespec structure. Solaris does. Do we want them? > It is also missing some common timeval macros: > > +/* timeval operations */ > +#define timerclear(tvp) (tvp)->tv_sec = 0; (tvp)->tv_usec = 0 > +#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec) > +#define timercmp(tvp, uvp, cmp) \ > + (((tvp)->tv_sec == (uvp)->tv_sec) ? \ > + ((tvp)->tv_usec cmp (uvp)->tv_usec) : \ > + ((tvp)->tv_sec cmp (uvp->tv_sec)) > +#define timeradd(tvp, uvp, vvp) \ > + do { \ > + (vvp)->tv_sec = (tvp)->tv_sec + (uvp)->tv_sec; \ > + (vvp)->tv_usec = (tvp)->tv_usec + (uvp)->tv_usec; \ > + if((vvp)->tv_usec >= 1000000) { \ > + (vvp)->tv_sec ++; \ > + (vvp)->tv_usec -= 1000000; \ > + } \ > + } while(0) > +#define timersub(tvp, uvp, vvp) \ > + do { > + (vvp)->tv_sec = (tvp)->tv_sec - (uvp)->tv_sec; \ > + (vvp)->tv_usec = (tvp)->tv_usec - (uvp)->tv_usec; \ > + if((vvp)->tv_usec < 0) { \ > + (vvp)->tv_sec --; \ > + (vvp)->tv_usec += 1000000; \ > + } \ > + } while(0) Linux and Solaris don't define timeradd or timersub in time.h. They do define the others. Are timeradd and timersub worth adding? > - sys/types is missing the "unchar" and "ulong" definitions in > the System V compatibility section. It also does not have > U_quad_t,quad_t and quaddr_t definitions: > > +typedef unsigned char unchar; /* System V compatibility */ > +typedef unsigned long ulong; /* System V compatibility */ I'll look into adding these. > +/* XXX these were outside of !POSIX in BSD - is this right? */ > +typedef u_int64_t u_quad_t; > +typedef int64_t quad_t; > +typedef quad_t * quaddr_t; These aren't defined by Solaris or Linux. Probably should leave them out? > This is just a start, but it makes a big difference. After these few > changes most software I compile will compile clean except for some network > definitions (which I will attack next). I await feedback. :-) -- Geoffrey Noer noer AT cygnus DOT com