Re(cap): Which Unix?
Lyle McElhaney
lmc at denelcor.UUCP
Mon Apr 29 14:10:38 AEST 1985
> What I'm proposing is for ALL UN*X systems to have a single
> (additional) include file: /usr/include/unix.h, which would
> contain something like:
>
> #define V6 0
> #define PWB 1
> #define V7 2
> #define SYS3 3
> #define 32V 4
> #define BSD2_8 5
> #define BSD4_1 6
> #define SYS5 7
> #define BSD2_9 8
> #define BSD4_2 9
> #define ULTRIX 10
> #define P1003 11 /* /usr/group standard */
> ...
>
> #define UNIX BSD4_2
It would be nice if all Unicies had the same user interface, but hardware
considerations and sheer inertia guarantee that the problem will be with
us a while longer yet. Dave Yost published a piece in this forum stating
the above solution won't work, and presenting the solution he uses to make
the E (Rand, INed) editor work in different environments. Without further
ado, take it, Dave....
Subject: #defines for portable code
From: day at kovacs.UUCP (David Yost)
Date: Thu, 2-Aug-84 01:02:57 MDT
I have been developing and porting the Rand Editor to
different machines and systems for five years now.
(If you are interested in the significant recent
developments, mail or call 213-650-1089.)
#defined names that tell you the version of the
system, such as SYS5_2 or V7 are not the solution.
Among other problems, there are too many hacked
kernels out there, and many of the hacks are needed,
so you want your program to know they are there.
A large, sophisticated piece of software needs to
know things about the machine, the compiler, the
library functions, and the system calls. My solution
to the porting issues has been to use two include
files: "c_env.h" for the machine and the compiler,
and "localenv.h" for the library and the kernel.
Most of what follows should be pretty obvious, but
the Regx stuff needs explanation. Briefly, since the
compiler assigns registers in the order that it
encounters the declarations, if you just declare lots
of registers in case the machine has enough, you can
lose big on machines with fewer registers than the
number you declared. Instead, I declare them Reg1,
Reg2, ... in the order of importance, and the c_env
#define's take care of the rest.
=== c_env.h
/*
* C Environment.
* Information about the machine and the compiler.
*
* VAX 4.1bsd & 4.2bsd
*/
/*
* In the #define's that follow, define the first n to 'register'
* and the rest to nothing, where 'n' is the number of registers
* supported by your compiler.
*/
#define Reg1 register
#define Reg2 register
#define Reg3 register
#define Reg4 register
#define Reg5 register
#define Reg6 register
#define Reg7
#define Reg8
#define Reg9
#define Reg10
#define Reg11
#define Reg12
#define CHARMASK 0xFF
#define CHARNBITS 8
#define MAXCHAR 0x7F
#define SHORTMASK 0xFFFF
#define SHORTNBITS 16
#define MAXSHORT 0x7FFF
#define LONGMASK 0xFFFFFFFF
#define LONGNBITS 32
#define MAXLONG 0x7FFFFFFF
#define INTMASK 0xFFFFFFFF
#define INTNBITS 32
#define MAXINT 0x7FFFFFFF
#define BIGADDR /* text address space > 64K */
/* fine ADDR64K /* text and data share 64K of memory (no split I&D */
#define INT4 /* sizeof (int) == 4 */
/* fine INT2 /* sizeof (int) == 2 */
#define PTR4 /* sizeof (char *) == 4 */
/* fine PTR2 /* sizeof (char *) == 2 */
/* unsigned types supported by the compiler: */
#define UNSCHAR /* unsigned char */
#define UNSSHORT /* unsigned short */
#define UNSLONG /* unsigned long */
/* fine NOSIGNEDCHAR /* there is no signed char type */
#define STRUCTASSIGN /* Compiler does struct assignments */
#define UNIONS_IN_REGISTERS /* compiler allows unions in registers */
/* fine void int /* Fake the new 'void' type to an int */
/* Byte order: */
#define SHORT_10 /* pdp11, vax, 16000, 8086, 8080, ... */
#define LONG_3210 /* vax, 16000, 8086, 8080, ... */
/* fine LONG_0123 /* ibm, perkin-elmer, 68000, pyramid, ... */
/* fine LONG_1032 /* pdp11 */
=== localenv.h
/*
* System Environment
* Information about the system call interface and the C library.
*
* 4.2bsd - vax & pyramid so far
*/
/* fine index strchr /* */
/* fine rindex strrchr /* */
/* fine NOIOCTL_H /* there is no ioctl.h */
/* fine RDNDELAY /* read call has NDELAY capability */
#define EMPTY /* can implement empty(fd) subroutine call */
#define LINKS /* file system has links */
#define CANFORK /* system has fork() */
#define VFORK /* system has vfork() */
#define ABORT_SIG SIGILL /* which signal does abort() use */
#define SIGARG /* signal catch routine has sig num as arg */
#define SIG_INCL <signal.h>
#define SGTT_INCL <sgtty.h>
#define TTYNAME /* use ttyname function */
/* define TTYN /* use ttyn function */
#define SHORTUID /* uid is a short, not a char (v7+) */
#define ENVIRON /* getenv() is implemented */
#define VAX_MONITOR /* use monitor() routine for vax */
#define SIGNALS /* system has signals */
#define SYMLINKS /* 4.2 symbolic links */
#define NDIR /* 4.2 dirrectory routines */
#define SYSMKDIR /* use mkdir(name, mode) system call */
#define SYSRMDIR /* use rmdir(name) system call */
#define SYSFCHOWN /* use fchown(fd, ...) system call */
#define SYSFCHMOD /* use fchmod(fd, ...) system call */
#define CLR_SUID_ON_WRITE /* modifying a file clrs suid and sgid bits */
#define SYSSELECT /* system has berkeley select system call */
#define WAIT_UNION /* include <sys/wait.h> */
#ifdef WAIT_UNION
#define WAITARG union wait
#else WAIT_UNION
#define WAITARG int
#endif WAIT_UNION
/* fine MALLOC0OK /* has NULL return arena corruption fix */
=== end
--
Lyle McElhaney
{hao, stcvax, brl-bmd, nbires, csu-cs} !denelcor!lmc
More information about the Comp.unix.wizards
mailing list