/* Copyright 1988,1990,1993,1994 by Paul Vixie
* Distribute freely, except: don't remove my name from the source or
* documentation (don't take credit for my work), mark your changes (don't
* get me blamed for your possible bugs), don't alter or remove this
* notice. May be sold if buildable source is provided to buyer. No
* warrantee of any kind, express or implied, is included with this
* software; use at your own risk, responsibility for damages (if any) to
* anyone resulting from the use of this software rests entirely with the
* Send bug reports, bug fixes, enhancements, requests, flames, etc., and
* I'll try to keep a version up to date. I can be reached as follows:
* Paul Vixie <paul@vix.com> uunet!decwrl!vixie!paul
* From Id: compat.c,v 1.6 1994/01/15 20:43:43 vixie Exp
#if !defined(lint) && !defined(LINT)
static char rcsid
[] = "$Header: $";
/* vix 30dec93 [broke this out of misc.c - see RCS log for history]
* vix 15jan87 [added TIOCNOTTY, thanks csg@pyramid]
#ifdef NEED_GETDTABLESIZE
#if defined(NEED_SETSID) && defined(BSD)
/* the code does not depend on any of vfork's
* side-effects; it just uses it as a quick
temp
= malloc(strlen(str
) + 1);
(void) strcpy(temp
, str
);
extern char *sys_errlist
[];
if ((error
<= sys_nerr
) && (error
> 0)) {
return sys_errlist
[error
];
sprintf(buf
, "Unknown error: %d", error
);
while (*left
&& (MkLower(*left
) == MkLower(*right
))) {
return MkLower(*left
) - MkLower(*right
);
newpgrp
= setpgid((pid_t
)0, getpid());
newpgrp
= setpgrp(0, getpid());
if ((fd
= open("/dev/tty", 2)) >= 0)
(void) ioctl(fd
, TIOCNOTTY
, (char*)0);
(void) close(STDIN
); (void) open("/dev/null", 0);
(void) close(STDOUT
); (void) open("/dev/null", 1);
(void) close(STDERR
); (void) open("/dev/null", 2);
#ifdef NEED_GETDTABLESIZE
return sysconf(_SC_OPEN_MAX
);
/* The following flock() emulation snarfed intact *) from the HP-UX
* "BSD to HP-UX porting tricks" maintained by
* system@alchemy.chem.utoronto.ca (System Admin (Mike Peterson))
* from the version "last updated: 11-Jan-1993"
* Snarfage done by Jarkko Hietaniemi <Jarkko.Hietaniemi@hut.fi>
* *) well, almost, had to K&R the function entry, HPUX "cc"
* does not grok ANSI function prototypes */
* This routine performs some file locking like the BSD 'flock'
* on the object described by the int file descriptor 'fd',
* which must already be open.
* The operations that are available are:
* LOCK_SH - get a shared lock.
* LOCK_EX - get an exclusive lock.
* LOCK_NB - don't block (must be ORed with LOCK_SH or LOCK_EX).
* LOCK_UN - release a lock.
* Return value: 0 if lock successful, -1 if failed.
* Note that whether the locks are enforced or advisory is
* controlled by the presence or absence of the SETGID bit on
* Note that there is no difference between shared and exclusive
* locks, since the 'lockf' system call in SYSV doesn't make any
* The file "<sys/file.h>" should be modified to contain the definitions
* of the available operations, which must be added manually (see below
/* this code has been reformatted by vixie */
case LOCK_SH
: /* get a shared lock */
case LOCK_EX
: /* get an exclusive lock */
i
= lockf (fd
, F_LOCK
, 0);
case LOCK_SH
|LOCK_NB
: /* get a non-blocking shared lock */
case LOCK_EX
|LOCK_NB
: /* get a non-blocking exclusive lock */
i
= lockf (fd
, F_TLOCK
, 0);
if ((errno
== EAGAIN
) || (errno
== EACCES
))
case LOCK_UN
: /* unlock */
i
= lockf (fd
, F_ULOCK
, 0);
default: /* can't decipher operation */
setenv(name
, value
, overwrite
)
if (overwrite
&& getenv(name
))
if (!(tmp
= malloc(strlen(name
) + strlen(value
) + 2))) {
sprintf("%s=%s", name
, value
);
return putenv(tmp
); /* intentionally orphan 'tmp' storage */