/* Copyright (C) 1997-1999  Canada-France-Hawaii Telescope Corp.         */
/* This program is distributed WITHOUT any warranty, and is under the    */
/* terms of the GNU General Public License, see the file COPYING         */
/*****************************************************************************
 *
 * missing_protos.h - ANSI prototypes for systems that lack complete ANSI
 *                    system header files (especially SunOS 4.x).  This file
 *                    should be included with `#include <missing_protos.h>'
 *                    from "cfht/cfht.h" so that it does not show up in
 *                    the dependencies generated by "gcc -MM".  Proper ANSI
 *                    systems should not need anything from this file anyway,
 *                    and thus will not be tempted to re-compile everything
 *                    which depends on this file every time we need to add
 *                    a new prototype for the SunOS machines.
 * $Id: missing_protos.h,v 1.3 2009-01-22 20:43:24 eugene Exp $
 * $Locker:  $
 *
 * $Log: not supported by cvs2svn $
 * Revision 1.2  2007/04/18 19:21:46  eugene
 * dropping non-standard includes
 *
 * Revision 1.1.1.1  2004/11/24 04:39:33  eugene
 * importing elixir components
 *
 * Revision 1.1.1.1  2001/07/25 02:59:23  eugene
 * import Ohana
 *
 * Revision 1.11  2000/02/10 13:52:23  isani
 * Added a few more prototypes.
 * Changed to new way of doing SELECT() call.
 *
 * Revision 1.10  1999/07/30 22:14:51  thomas
 * HP added openlog/syslog in 10.X, if it out there
 *
 * Revision 1.9  1999/07/13 21:27:28  thomas
 * Added WCOREDUMP for SunOS
 *
 * Revision 1.8  1999/07/13 00:17:24  thomas
 * Fix 1.7, Sidik's model was not sufficient, plus GNU rcs would not let me
 * cancel it ???
 *
 * Revision 1.7  1999/07/03 04:10:58  thomas
 * Changed select for 10.20
 *
 * Revision 1.6  98/07/10  10:38:35  10:38:35  thomas (Jim Thomas)
 * Added perror, strerror, memset, drand48 to SunOS prototypes
 * 
 * Revision 1.5  97/12/18  21:28:43  21:28:43  thomas (Jim Thomas)
 * Put floatingpoint.h back in, added strtol, changed __STDC__ to __GNUC__
 * 
 * Revision 1.4  97/12/18  02:38:20  02:38:20  isani (Sidik Isani)
 * Added redefinition of CFHT_SIG_{DFL,IGN} for SunOS
 * 
 * Revision 1.3  1997/12/05 20:49:44  thomas
 * Added definition of const if not ANSI C
 *
 * Revision 1.2  97/12/05  20:20:44  20:20:44  jcc (Jean-Charles Cuillandre)
 * Added include of resource.h
 * 
 * Revision 1.1  1997/11/23 11:29:04  isani
 * Initial revision
 *
 ****************************************************************************/

#ifndef _INCLUDED_missing_protos
#define _INCLUDED_missing_protos 1

/*
 * Make.Common defines *one* of the following:
 *             SUNOS, SOLARIS, HPUX, LINUX, VXWORKS, or CYGWIN32
 * We will use these here, but for projects where Make.Include is used
 * instead of Make.Common, check for some other predefined symbols like
 * __sun__ to try to figure out the system type.
 */

#if defined(SunOS) && !defined(SUNOS)
#define SUNOS
#endif

#if (defined(Linux) || defined(linux)) && !defined(LINUX)
#define LINUX
#endif

/*
 * First, make sure SUNOS didn't get defined by accident for a Solaris box.
 * We use SOLARIS instead, because they are really different OS's.
 */

#if defined(SUNOS) && defined(__svr4__)
#undef SUNOS
#ifndef SOLARIS
#define SOLARIS
#endif
#endif

#if !defined(SUNOS) && !defined(SOLARIS) && !defined(HPUX) && !defined(LINUX) && !defined(CYGWIN32) && !defined(VXWORKS)
/*
 * If Make.Common isn't being used ...
 */
#if defined(__sun__) || defined(sun)
#ifndef sun
#define sun
#endif
#ifdef __svr4__
#define SOLARIS
#else
#define SUNOS
#endif
#else
#if defined(__hpux__) || defined(hpux)
#ifndef hpux
#define hpux
#endif
#define HPUX
#else
error: Unknown system type!
error: This software has not been tested on this platform.
error: (comment out this block to compile anyway).
#endif /* __hpux__ */
#endif /* __sun__ */
#endif /* !SUNOS && !SOLARIS && !HPUX ... */

#ifdef __cplusplus
extern "C" {
#endif

/* "const" has been added to a bunch of definitions, but that is ANSI :-( */
#ifndef __STDC__
#define const
#endif

/*
 * Here are the hacks for the old suns, so we don't have to include them
 * in each source file.  Solaris 2.x does not need any of this stuff...
 */

#ifdef SUNOS
#define mktime timelocal
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <sys/resource.h>
#ifndef WCOREDUMP
#define WCOREDUMP(n) 0
#endif
#include <malloc.h>
#include <unistd.h>
#ifdef __GNUC__
#include <float.h>             /* for DBL_MIN and DBL_MAX */
#else
/* XXX RHL claims values.h is not needed
 * #include <values.h> */
#ifndef DBL_MIN
#define DBL_MIN MINDOUBLE
#define DBL_MAX MAXDOUBLE
#endif
#endif /* !__GNUC__ */
#ifdef __GNUC__
void    perror(const char *s);
char	*strerror(int);
int     ioctl(int, int, ...);
int     select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
/* bzero is not ANSI, but the FD_ macros for select need it, so we need a
 * proto here to prevent warnings.  Use memset() in your own code instead!
 */
void    bzero(char*, int);
void*   memset(void*, int, size_t);
int     socket(int, int, int);
int     bind(int,  struct sockaddr*, int);
int     listen(int, int);
int     connect(int, struct sockaddr*, int);
int     accept(int, struct sockaddr*, int*);
int     shutdown(int, int);
int     getsockname(int,struct sockaddr*,int*);
int     getpeername(int,struct sockaddr*,int*);
int     setsockopt(int,int,int,const void*,int);
int     socketpair(int,int,int,int [2]);
int     getrlimit(int,struct rlimit*);
int     setrlimit(int,const struct rlimit*);
int     gettimeofday(struct timeval *tp, struct timezone *tzp);
int     rename(const char*, const char*);
int     symlink(const char*, const char*);
int     readlink(const char*, char*, int);
int     lstat(const char*, struct stat*);
int     openlog(const char*, int, int);
int     syslog(int, const char*, ...);
int     getitimer(int, struct itimerval*);
int     setitimer(int, const struct itimerval*, struct itimerval*);
int	fchmod(int, int);
int	getdtablesize(void);
int	semop(int, struct sembuf*, unsigned int);
key_t	ftok(const char *, int);
int	semget(key_t, int, int);
int	lockf(int, int, off_t);
int	ftruncate(int, off_t);
/* %%% The protos for CFHT_SIG_DFL et al are defined in terms of
 *     SIG_DFL et al defined in signal.h, but unfortunately these
 *     are not properly prototyped either :-(  Overriding them here
 *     is kind of dangerous, and should be checked carefully.
 */
#undef  CFHT_SIG_DFL
#undef  CFHT_SIG_IGN
#define CFHT_SIG_DFL ((PFV)(0))
#define CFHT_SIG_IGN ((PFV)(1))
#else  /* not __GNUC__ */
#include <floatingpoint.h>
void perror(void);
char *strerror(void);
void *memset(void);
double drand48(void);
long strtol(void);
#endif /* __GNUC__ */
#endif /* SUNOS */

/*
 * Here are the hacks that are also needed on the newer Solaris 2.x machines.
 */
#if defined(SUNOS) || defined(SOLARIS)
#include <unistd.h>
#ifdef __STDC__
int	gethostname(char*, int);
int     seteuid(uid_t euid);
int     setegid(gid_t egid);
int	setreuid(uid_t, uid_t);
int	setregid(gid_t, gid_t);
char*   crypt(const char*, const char*);
#endif
extern char** environ;
#endif

/*
 * HPUX has some quirks too.
 */
#ifdef HPUX
#if defined(OSVersion) && (OSVersion < 10)
/*
 * Make.Common defines HACK_SELECT directly and doesn't use this.
 * See #if/not HACK_SELECT below also.
 */
#define HACK_SELECT
#endif

/* HP 10.20 seems not to define socklen_t */

#define socklen_t int

/* See comments above under SUNOS */
#undef  CFHT_SIG_DFL
#undef  CFHT_SIG_IGN
#define CFHT_SIG_DFL ((PFV)(0))
#define CFHT_SIG_IGN ((PFV)(1))

#define seteuid(euid) setresuid(-1,(euid),-1)
#define setegid(egid) setresgid(-1,(egid),-1)
#ifdef __STDC__
/* HP-UX 9 needed these.  Shouldn't hurt under 10.20 as long as they match. */
void openlog(const char *, int, int);
void syslog(int, const char *, ...);
#endif
#else /* not HP */
#ifdef __STDC__
/* only HP provides a prealloc function */
int	prealloc(int fildes, unsigned size);
#endif
#endif

/*
 * CYGWIN32 is still in beta, so probably much of this stuff
 * will need to be removed once this compiler stabilizes.
 */
#ifdef CYGWIN32
#include <sys/types.h>
#include <sys/time.h>
#include <sys/stat.h>
#define seteuid(x) (0)
#define setegid(x) (0)
#define setuid(x)  (0)
#define setgid(x)  (0)
int readlink(const char*, char*, int);
int select(int,fd_set*,fd_set*,fd_set*,struct timeval*);
int lstat(const char*, struct stat*);
int gettimeofday(struct timeval*, struct timezone*);
const char* crypt(const char*, const char*);
#endif

/*
 * Before version 10, HP defines fd_set, but doesn't use it in the prototype
 * for select().  Also the count is size_t (which is right, why did ANSI
 * lose that one?  I guess because C does not really support types :-( ).
 * So do select() like this to avoid warnings on HP
 *
 *   Status = SELECT(n, read, write, error, &timestruct);
 */
#ifdef HACK_SELECT
#define SELECT(n, read, write, error, tp)        \
        select((size_t) (n), (int *) (read),     \
               (int *) (write), (int *) (error), \
	       (tp))
#else
/* Let the compiler check against a real prototype. */
#define SELECT select
#endif

#ifdef __cplusplus
}
#endif
#endif /* !_INCLUDED_missing_protos */
