Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!hplabs!hpda!hpcuhb!hp-ses!wunder From: wunder@hp-ses.SDE.HP.COM (Walter Underwood) Newsgroups: comp.sys.hp Subject: Re: linking BSD type software on HP-UX Message-ID: <920022@hp-ses.SDE.HP.COM> Date: 27 Mar 89 19:31:59 GMT References: <940@eastman.UUCP> Organization: HP SW Engineering Systems - Palo Alto, CA Lines: 94 In the aufs part, a function called "flock" was required, if we want to use shared volumes using the file server. HP-UX has "lockf", but it is different from "flock". Here is an flock() emulation. flock() handles shared locks plus exclusive locks. This only does exclusive locks. The locking available from fcntl() is equivalent to flock(), so this really should be rewritten to use fcntl(). Someone else suggested replacing bcopy() with memcpy(). This is not always safe. bcopy() handles overlapping strings correctly, memcpy() does not (it may be optimized for speed, using word moves). wunder ----------------- # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Walter Underwood on Mon Mar 27 11:26:10 1989 # # This archive contains: # bsd1.h flock.c # unset LANG echo x - bsd1.h cat >bsd1.h <<'@EOF' /* * Berkeley to HP-UX library functionality mappings * These routines are not supported by HP. * * To use these, also include */ /* signal(2) mapping */ #define SIGCHLD SIGCLD /* Helpful macros with select(2) */ #define NFDBITS (sizeof(int) * NBBY) #define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1 << ((n) % NFDBITS))) #define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1 << ((n) % NFDBITS))) #define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1 << ((n) % NFDBITS))) #define FD_ZERO(p) (memset((char *)(p), 0, sizeof(*(p)))) /* These definitions are in on BSD 4.3 */ /* * Flock call. */ #define LOCK_SH 1 /* shared lock */ #define LOCK_EX 2 /* exclusive lock */ #define LOCK_NB 4 /* don't block when locking */ #define LOCK_UN 8 /* unlock */ @EOF chmod 644 bsd1.h echo x - flock.c cat >flock.c <<'@EOF' #include #include #include "bsd1.h" /* defines normally in */ flock(fd, operation) int fd, operation; { int UN,NB,SH,EX; int newop = 0; UN = LOCK_UN & operation; NB = LOCK_NB & operation; SH = LOCK_SH & operation; EX = LOCK_EX & operation; if (UN) newop = F_ULOCK; else if (NB) newop = F_TLOCK; else if (SH || EX) newop = F_LOCK; else return(-1); /* no operations set */ return(lockf(fd, newop, 0)); } @EOF chmod 644 flock.c exit 0