From 334719e73a446edcd36c96810521f1694b622cff Mon Sep 17 00:00:00 2001 From: Olaf Seibert Date: Wed, 20 Jan 2016 17:51:31 +0100 Subject: [PATCH] Make it build on MacOS X. I only compile-tested it, I didn't run it. The main effect is to make hardware tape support ~optional, since OSX has no . --- src/cenv.h | 15 +++++++++------ src/dpsup.c | 6 +++--- src/dptm03.c | 28 +++++++++++++++------------- src/osdnet.c | 9 ++++----- src/tapedd.c | 10 ++++++++-- src/vdkfmt.c | 1 - 6 files changed, 39 insertions(+), 30 deletions(-) diff --git a/src/cenv.h b/src/cenv.h index 2b3c5ad..fad04bb 100644 --- a/src/cenv.h +++ b/src/cenv.h @@ -172,22 +172,25 @@ # define CENV_SYS_DECOSF 1 # elif defined(__FreeBSD__) # undef CENV_SYS_FREEBSD -# define CENV_SYS_FREEBSD 1 +# define CENV_SYS_FREEBSD 1 # elif defined(__linux__) # undef CENV_SYS_LINUX # define CENV_SYS_LINUX 1 -# elif defined(__APPLE__) +# elif defined(__APPLE__) && !defined(__MACH__) # undef CENV_SYS_MAC -# define CENV_SYS_MAC 1 +# define CENV_SYS_MAC 1 +# elif defined(__APPLE__) && defined(__MACH__) +# define CENV_SYS_BSD 1 +# define CENV_SYS_XBSD 1 # elif defined(__NetBSD__) # undef CENV_SYS_NETBSD -# define CENV_SYS_NETBSD 1 +# define CENV_SYS_NETBSD 1 # elif defined(__OpenBSD__) # undef CENV_SYS_OPENBSD -# define CENV_SYS_OPENBSD 1 +# define CENV_SYS_OPENBSD 1 # elif defined(__sun) && defined(__SVR4) # undef CENV_SYS_SOLARIS -# define CENV_SYS_SOLARIS 1 +# define CENV_SYS_SOLARIS 1 # elif defined(__COMPILER_KCC__) # undef CENV_SYS_T20 /* Not quite right, but close enough */ # define CENV_SYS_T20 1 diff --git a/src/dpsup.c b/src/dpsup.c index dd84862..2ce6f1f 100644 --- a/src/dpsup.c +++ b/src/dpsup.c @@ -53,11 +53,11 @@ static int decosfcclossage; # include # include # include -# if CENV_SYS_SUN || CENV_SYS_SOLARIS +# if defined(MAXSIG) # define SIGMAX MAXSIG /* Different wording on Sun */ -# elif CENV_SYS_FREEBSD +# elif defined(NSIG) # define SIGMAX NSIG -# elif CENV_SYS_NETBSD || CENV_SYS_LINUX +# elif defined(_NSIG) # define SIGMAX _NSIG # endif #endif /* CENV_SYS_DECOSF || CENV_SYS_SUN || CENV_SYS_SOLARIS || CENV_SYS_XBSD || CENV_SYS_LINUX */ diff --git a/src/dptm03.c b/src/dptm03.c index ebaaddb..14f03da 100644 --- a/src/dptm03.c +++ b/src/dptm03.c @@ -222,7 +222,9 @@ So, algorithm (on DECOSF anyway) should be: # include # include # include -# include +# if HAVE_SYS_MTIO_H +# include +# endif # include # include #endif @@ -1337,7 +1339,7 @@ os_mtmoveinit(register struct devmt *d) d->mta_frms = 0; } -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H /* General-purpose ioctl operation invocation */ int @@ -1358,6 +1360,7 @@ osux_mtop(register struct devmt *d, int op, int cnt, char *name) } return TRUE; } +#endif /* CENV_SYS_UNIX && HAVE_SYS_MTIO_H */ /* Get physical magtape state. * Unfortunately there is no general way to do this. @@ -1529,7 +1532,6 @@ os_mtstate(register struct devmt *d, } return res; } -#endif /* CENV_SYS_UNIX */ /* Called when an unexpected error is hit -- attempts to determine * whether the tape is still there or if it's a real data error. @@ -1610,7 +1612,7 @@ os_mterrchk(register struct devmt *d, } /* OK, should have good state bits now */ } -#else +#elif HAVE_SYS_MTIO_H /* Error may indicate tape is no longer present or drive is gone. Try to distinguish this error from a real data I/O error by performing a NOP. @@ -1637,7 +1639,7 @@ os_mtopen(struct devmt *d, char *path, int mtof) os_mtflaginit(d); /* Clear all state flags */ -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H { int fd; int mode = ((mtof & OS_MTOF_READONLY) ? O_RDONLY : O_RDWR) @@ -1822,7 +1824,7 @@ os_mtweof(struct devmt *d) /* Write a tapemark */ { os_mtmoveinit(d); /* Clear movement flags */ -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H if (!osux_mtop(d, MTWEOF, 1, "MTWEOF")) { syserr(-1, "Tapemark write error"); os_mterrchk(d, -DPTM_WTM); /* Try to recover state from OS */ @@ -1847,7 +1849,7 @@ os_mtunload(struct devmt *d) /* Try to unload tape */ { d->mta_mol = FALSE; /* Say no longer online */ os_mtmoveinit(d); /* Clear movement flags */ -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H lseek(d->d_fd, (long)0, 0); /* Barf - See DECOSF "man mtio" */ /* Do MTUNLOAD. Known to be defined by DECOSF and LINUX; other @@ -1873,7 +1875,7 @@ os_mtrewind(struct devmt *d) /* Rewind tape */ os_mtmoveinit(d); /* Clear movement flags */ d->mta_rew = TRUE; /* Now rewinding */ -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H lseek(d->d_fd, (long)0, 0); /* Barf - See DECOSF "man mtio" */ if (!osux_mtop(d, MTREW, 1, "MTREW")) { syserr(-1, "Tape rewind error"); @@ -1919,7 +1921,7 @@ os_mtrewind(struct devmt *d) /* Rewind tape */ int os_mtspace(struct devmt *d, long unsigned int cnt, int revf) { -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H int op = (revf ? MTBSR : MTFSR); int dir = (revf ? -1 : 1); int prevfileno; @@ -2022,7 +2024,7 @@ os_mtspace(struct devmt *d, long unsigned int cnt, int revf) int os_mtfspace(struct devmt *d, long unsigned int cnt, int revf) { -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H int op = (revf ? MTBSF : MTFSF); int dir = (revf ? -1 : 1); int prevfileno; @@ -2094,7 +2096,7 @@ int os_mtclrerr(struct devmt *d) { /* Do MTCSE. Known to be defined only by DECOSF? */ -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H # if CENV_SYS_SUN || CENV_SYS_SOLARIS || CENV_SYS_BSD || CENV_SYS_LINUX # ifndef MTCSE /* No equiv, try NOP instead */ # define MTCSE MTNOP @@ -2106,7 +2108,7 @@ os_mtclrerr(struct devmt *d) d->mta_err = 0; return TRUE; #else - return FALSE + return FALSE; #endif } @@ -2139,7 +2141,7 @@ struct mtget { void os_mtshow(struct devmt *d, FILE *f) { -#if CENV_SYS_UNIX +#if CENV_SYS_UNIX && HAVE_SYS_MTIO_H struct mtget mt; if (ioctl(d->d_fd, MTIOCGET, (char *)&mt) < 0) { diff --git a/src/osdnet.c b/src/osdnet.c index a649915..e85568e 100644 --- a/src/osdnet.c +++ b/src/osdnet.c @@ -502,6 +502,7 @@ osn_ifnmlookup(char *ifnam, /* Interface name */ } #if CENV_SYS_LINUX + int set_proc_variable(char *template, char *ifname, char *value) { @@ -522,9 +523,9 @@ set_proc_variable(char *template, char *ifname, char *value) } #endif /* CENV_SYS_LINUX */ + /* OSN_ARP_STUFF - stuff emulated-host ARP entry into kernel. -** Note it isn't necessary to specify an interface! -** Also, the code assumes that if an ARP entry already exists in the +** The code assumes that if an ARP entry already exists in the ** kernel for the given IP address, it will be reset to this new ** setting rather than (eg) failing. */ @@ -590,7 +591,7 @@ osn_arp_stuff(char *ifname, unsigned char *ipa, unsigned char *eap, int pubf) if (set_proc_variable("/proc/sys/net/ipv4/ip_forward", "", "1\n")) { dbprintln("Enabled net.ipv4.ip_forward"); } -#endif /* OSN_USE_IPONLY */ +# endif /* OSN_USE_IPONLY */ /* * It seems that if arp_accept=0, then ARP packets that are received * are not only ignored by the kernel, but also not passed to @@ -1459,7 +1460,6 @@ error: * Receives a single packet and returns its size. * Include link-layer headers, but no BPF headers or anything like that. */ -inline ssize_t osn_pfread_pcap(struct pfdata *pfdata, void *buf, size_t nbytes) { @@ -1513,7 +1513,6 @@ tryagain: * Expect a full ethernet frame including link-layer header. * returns the number of bytes written. */ -inline int osn_pfwrite_pcap(struct pfdata *pfdata, const void *buf, size_t nbytes) { diff --git a/src/tapedd.c b/src/tapedd.c index 0a1a547..453748e 100644 --- a/src/tapedd.c +++ b/src/tapedd.c @@ -72,7 +72,9 @@ # include /* Basic Unix syscalls */ # include # include -# include +# if HAVE_SYS_MTIO_H +# include +# endif /* HAVE_SYS_MTIO_H */ # define char8 unsigned char # define O_BSIZE_8 0 # define NULLDEV "/dev/null" @@ -1466,6 +1468,8 @@ int os_mtweof(struct dev *dp) /* Write a tapemark */ acs[1] = dp->d_fd; acs[2] = monsym(".MOCLE"); jsys(MTOPR, acs); +#elif CENV_SYS_UNIX && !HAVE_SYS_MTIO_H + return FALSE; #else struct mtop mtcmd; mtcmd.mt_op = MTWEOF; @@ -1486,6 +1490,8 @@ int os_mtfsr(struct dev *dp) /* Forward Space Record (to inter-record gap)*/ acs[2] = monsym(".MOCLE"); jsys(MTOPR, acs); */ +#elif CENV_SYS_UNIX && !HAVE_SYS_MTIO_H + return FALSE; #else struct mtop mtcmd; mtcmd.mt_op = MTFSR; @@ -1537,7 +1543,7 @@ t20status(register struct dev *d, register FILE *f, int swd, int cnt) void os_mtstatus(struct dev *dp, FILE *f) { #if CENV_SYS_T20 -#elif CENV_SYS_UNIX +#elif CENV_SYS_UNIX && HAVE_SYS_MTIO_H struct mtget mtstatb; if (ioctl(dp->d_fd, MTIOCGET, (char *)&mtstatb) < 0) { diff --git a/src/vdkfmt.c b/src/vdkfmt.c index 3b797f1..ff92e80 100644 --- a/src/vdkfmt.c +++ b/src/vdkfmt.c @@ -52,7 +52,6 @@ # include /* Basic Unix syscalls */ # include # include -# include # define NULLDEV "/dev/null" # define FD_STDIN 0 # define FD_STDOUT 1