#ifndef _UNISTD_H
#define _UNISTD_H

/*
 *  The <unistd.h> header defines constants, macros and functions that
 *  are specific to the Unix/Posix system call interfaces.
 *
 *  AMENDMENT HISTORY
 *  ~~~~~~~~~~~~~~~~~
 *  17 Jun 94   DJW   - Added sync() call to those listed.
 *
 *  20 Jun 94   DJW   - Values used by access() mode changed so that zero
 *                      is not a valid setting any more.
 *
 *  21 Aug 94   DJW   - Added 'const' keyword to definitions of chown(),
 *                      link() and rmdir().
 *
 *  03 Sep 94   DJW   - Added name hiding definitions for routines that are
 *                      called internally within libraries.
 *
 *  08 Aug 95   DJW   - Changed values associated with F_OK, etc so that F_OK
 *                      is zero which is a common Unix assumption.  Note that
 *                      POSIX states that symbolic names should be used.
 *                      Change made at request of Johnathan Hudson
 *
 *  20 Sep 95   DJW   - Changed return type of alarm() to be signed to allow
 *                      for fact that QDOS implementation can return an error.
 */

#ifndef _SYS_TYPES_H
#include <sys/types.h>
#endif

/* Values used by access().  POSIX Table 2-6. */
#define F_OK               0    /* test if file exists */
#define X_OK               1    /* test if file is executable */
#define W_OK               2    /* test if file is writable */
#define R_OK               4    /* test if file is readable */

/* Values used for whence in lseek(fd, offset, whence).  POSIX Table 2-7. */
#ifndef SEEK_SET
#define SEEK_SET	0		/* seek from beginning */
#define SEEK_CUR	1		/* seek from here */
#define SEEK_END	2		/* seek from end */
#endif

/* This value is required by POSIX Table 2-8. */
#define _POSIX_VERSION 198808L	/* which standard is being conformed to */

/* These three definitions are required by POSIX Sec. 8.2.1.2. */
#define STDIN_FILENO       0    /* file descriptor for stdin */
#define STDOUT_FILENO      1    /* file descriptor for stdout */
#define STDERR_FILENO      2    /* file descriptor for stderr */

/* NULL must be defined in <unistd.h> according to POSIX Sec. 2.8.1. */
#ifndef NULL
#define NULL    ((void *)0)
#endif

/* The following relate to configurable system variables. POSIX Table 4-2. */
#define _SC_ARG_MAX         1
#define _SC_CHILD_MAX       2
#define _SC_CLOCKS_PER_SEC  3
#define _SC_NGROUPS_MAX     4
#define _SC_OPEN_MAX        5
#define _SC_JOB_CONTROL     6
#define _SC_SAVED_IDS       7
#define _SC_VERSION         8

/* The following relate to configurable pathname variables. POSIX Table 5-2. */
#define _PC_LINK_MAX        1   /* link count */
#define _PC_MAX_CANON       2   /* size of the canonical input queue */
#define _PC_MAX_INPUT       3   /* type-ahead buffer size */
#define _PC_NAME_MAX        4   /* file name size */
#define _PC_PATH_MAX        5   /* pathname size */
#define _PC_PIPE_BUF        6   /* pipe size */
#define _PC_NO_TRUNC        7   /* treatment of long name components */
#define _PC_VDISABLE        8   /* tty disable */
#define _PC_CHOWN_RESTRICTED 9  /* chown restricted or not */

/* POSIX defines several options that may be implemented or not, at the
 * implementer's whim.  This implementer has made the following choices:
 *
 * _POSIX_JOB_CONTROL    not defined:   no job control
 * _POSIX_SAVED_IDS      not defined:   no saved uid/gid
 * _POSIX_NO_TRUNC       not defined:   long path names are truncated
 * _POSIX_CHOWN_RESTRICTED  defined:    you can't give away files
 * _POSIX_VDISABLE      defined:        tty functions can be disabled
 */
#define _POSIX_CHOWN_RESTRICTED
#define _POSIX_VDISABLE '\t'	/* can't set any control char to tab */


/*
 * Function Prototypes.
 */
#ifdef __STDC__
#define _P_(params) params
#else
#define _P_(params)
#endif

#define environ _environ        /* name hiding for ANSI compatibility */
extern char **environ;          /* environment pointer */

/*  Name hiding definitions */
#define chdir   _Chdir
#define close   _Close
#define dup2    _Dup2
#define read    _Read
#define unlink  _Unlink
#define write   _Write
/*  Prototypes */
void     _exit      _P_((int));
int      access     _P_((char *, int));
/*
 *  The return type of alarm() is normally unsigned.  However in
 *  the QDOS implementation it can also return an error code, so
 *  we have changed it to signed.  It is not anticipated that this
 *  will cause any serious problems!
 */
int      alarm      _P_((unsigned int));
int      chdir      _P_((char *));
int      chown      _P_((const char *, uid_t, gid_t));
int      close      _P_((int));
char *   ctermid    _P_((char *));
char *   cuserid    _P_((char *));
int      dup        _P_((int));
int      dup2       _P_((int, int));
int      execl      _P_((const char *, int *, const char *, ...));
int      execlp     _P_((const char *, int *, const char *, ...));
int      execv      _P_((const char *, int *, char * const * ));
int      execvp     _P_((const char *, int *, char * const * ));
pid_t    forkl      _P_((const char *, int *, const char *, ...));
pid_t    forklp     _P_((const char *, int *, const char *, ...));
pid_t    forkv      _P_((const char *, int *, char * const *));
pid_t    forkvp     _P_((const char *, int *, char * const *));
long     fpathconf  _P_((int, int));
int      fsync      _P_((int));
int      ftruncate  _P_((int, off_t));
char *   getcwd     _P_((char *, int));
gid_t    getegid    _P_((void));
uid_t    geteuid    _P_((void));
gid_t    getgid     _P_((void));
int      getgroups  _P_((int, gid_t));
char *   getlogin   _P_((void));
pid_t    getpgrp    _P_((void));
pid_t    getpid     _P_((void));
pid_t    getppid    _P_((void));
uid_t    getuid     _P_((void));
int      isatty     _P_((int));
int      link       _P_((const char *, const char *));
off_t    lseek      _P_((int, off_t, int));
long     pathconf   _P_((const char *, int));
int      pause      _P_((void));
int      pipe       _P_((int *));
int      read       _P_((int, void *, unsigned int));
int      rmdir      _P_((const char *));
int      seteuid    _P_((int));
int      setgid     _P_((int));
int      setpgid    _P_((pid_t, pid_t));
pid_t    setsid     _P_((void));
int      setuid     _P_((int));
unsigned sleep      _P_((unsigned int));
int      stime      _P_((const time_t *));
void     sync       _P_((void));
long     sysconf    _P_((int));
int      truncate   _P_((char *, off_t));
char *   ttyname    _P_((int));
int      unlink     _P_((const char *));
int      write      _P_((int, void *, unsigned int));

/**
 *
 * Level 1 memory allocation services
 *      (UNIX compatible )
 *
**/
void *   sbrk   _P_((int));
void *   lsbrk  _P_((long));
/* void  rbrk   _P_((void)); */

/*
 *  The following routines are included in this header file for
 *  documentation.  They are standard Unix routines that are not 
 *  (at least yet!) implemented in the QDOS libraries.
 */
char *   brk        _P_((char *));
char *   mktemp     _P_((char *));
pid_t    tcgetpgrp  _P_((int));
int      tcsetpgrp  _P_((int, pid_t));

/**
 *
 *  The following routines are specific to the QDOS
 *  implementation of Unix style file descriptors.
 *  (For those available for use see QdosC68_DOC for details)
 *
**/
extern int  (*_f_onexit) _P_((int));  /* Vector that can be set by user */


#ifdef __LIBRARY__
/*************************************************************************
 *
 *                          C A U T I O N
 *                          ~~~~~~~~~~~~~
 *
 *  The remainder of this header contains definitions that are internal
 *  to the way that the C68 libraries have been implemented on QDOS/SMS.
 *  These definitions should not be used by any user program as they are
 *  subject to change without notice.
 *
 *************************************************************************/

#endif /* __LIBRARY__ */
         
#undef _P_

#endif /* _UNISTD_H */

