home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / unix / unixlib_1 / !UnixLib37_src_clib_h_unistd < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-09  |  14.5 KB  |  476 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/clib/h/RCS/unistd,v $
  4.  * $Date: 1996/11/06 22:01:41 $
  5.  * $Revision: 1.5 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: unistd,v $
  10.  * Revision 1.5  1996/11/06 22:01:41  unixlib
  11.  * Yet more changes by NB, PB and SC.
  12.  *
  13.  * Revision 1.4  1996/10/30 21:58:58  unixlib
  14.  * Massive changes made by Nick Burret and Peter Burwood.
  15.  *
  16.  * Revision 1.3  1996/07/21 22:15:12  unixlib
  17.  * CL_0001 Nick Burret
  18.  * Improve memory handling. Remove C++ library incompatibilities.
  19.  * Improve file stat routines.
  20.  *
  21.  * Revision 1.2  1996/05/06 09:01:33  unixlib
  22.  * Updates to sources made by Nick Burrett, Peter Burwood and Simon Callan.
  23.  * Saved for 3.7a release.
  24.  *
  25.  * Revision 1.1  1996/04/19 21:02:57  simon
  26.  * Initial revision
  27.  *
  28.  ***************************************************************************/
  29.  
  30. /* POSIX Standard 2.10: Symbolic Constants <unistd.h>.  */
  31.  
  32. #ifndef __UNISTD_H
  33. #define __UNISTD_H
  34.  
  35. #ifndef __UNIXLIB_TYPES_H
  36. #include <unixlib/types.h>
  37. #endif
  38.  
  39. #ifdef __cplusplus
  40. extern "C" {
  41. #endif
  42.  
  43. /* These may be used to determine what facilities are present at compile time.
  44.    Their values can be obtained at run time from sysconf.  */
  45.  
  46. /* POSIX Standard approved as IEEE Std 1003.1 as of August, 1988.  */
  47. #define    _POSIX_VERSION    199009L
  48.  
  49. #define    _POSIX2_C_VERSION    199912L    /* Invalid until 1003.2 is done.  */
  50.  
  51. /* If defined, the implementation supports the
  52.    C Language Bindings Option.  */
  53. #define    _POSIX2_C_BIND    1
  54.  
  55. /* If defined, the implementation supports the
  56.    C Language Development Utilities Option.  */
  57. #define    _POSIX2_C_DEV    1
  58.  
  59. /* If defined, the implementation supports the
  60.    Software Development Utilities Option.  */
  61. #define    _POSIX2_SW_DEV    1
  62.  
  63. /* Standard file descriptors.  */
  64. #define    STDIN_FILENO    0    /* Standard input.  */
  65. #define    STDOUT_FILENO    1    /* Standard output.  */
  66. #define    STDERR_FILENO    2    /* Standard error output.  */
  67.  
  68. #ifndef __STDDEF_H
  69. #include <stddef.h>
  70. #endif
  71.  
  72. /* Values for the second argument to access.  */
  73.  
  74. /* Test for existence. */
  75. #ifndef F_OK
  76. #define F_OK    0
  77. #endif
  78. /* Test for execute permission.  */
  79. #ifndef X_OK
  80. #define X_OK    1
  81. #endif
  82. /* Test for write permission.  */
  83. #ifndef W_OK
  84. #define W_OK    2
  85. #endif
  86. /* Test for read permission.  */
  87. #ifndef R_OK
  88. #define R_OK    4
  89. #endif
  90.  
  91. /* Test for access to name.  */
  92. extern int access (const char *name, int type);
  93.  
  94. /* Values for the WHENCE argument to lseek.  */
  95. #ifndef    __STDIO_H        /* <stdio.h> has the same definitions.  */
  96. #define    SEEK_SET    0    /* Seek from beginning of file.  */
  97. #define    SEEK_CUR    1    /* Seek from current position.  */
  98. #define    SEEK_END    2    /* Seek from end of file.  */
  99. #endif
  100.  
  101. /* Move fd's file position to offset bytes from the:
  102.    beginning of the file (if SEEK_SET),
  103.    the current position (if SEEK_CUR),
  104.    or the end of the file (SEEK_END).
  105.    Return the new file position.  */
  106. extern __off_t lseek (int fd, __off_t offset, int whence);
  107.  
  108. /* Close the file descriptor fd.  */
  109. extern int close (int fd);
  110.  
  111. /* Read nbytes into buf from fd.  */
  112. extern __ssize_t read (int fd, void *buf, size_t nbytes);
  113.  
  114. /* Write n bytes of buf to fd.  */
  115. extern __ssize_t write (int fd, void *buf, size_t n);
  116.  
  117. /* Create a one way communication channel (pipe). */
  118. extern int pipe (int pipedes[2]);
  119.  
  120. /* Schedule an alarm.  */
  121. extern unsigned int alarm (unsigned int seconds);
  122.  
  123. /* Make the process sleep for 'seconds' seconds.  */
  124. extern unsigned int sleep (unsigned int seconds);
  125.  
  126. /* Suspend the process until a signal arrives.  */
  127. extern int pause (void);
  128.  
  129. /* Change the owner and group of file.  */
  130. extern int chown (const char *file, __uid_t owner, __gid_t group);
  131.  
  132. /* Change the process's working directory to path.  */
  133. extern int chdir (const char *path);
  134.  
  135. /* Get the pathname of the current working directory.  */
  136. extern char *getcwd (char *buf, size_t size);
  137.  
  138. /* The BSD version of getcwd. This function calls getcwd but does
  139.    not provide any buffer size checking.  */
  140. extern char *getwd (char *buf);
  141.  
  142. /* Duplicate FD, returning a new file descriptor on the same file.  */
  143. extern int dup (int fd);
  144.  
  145. /* Duplicate fd to fd2, closing fd2 and making it open on the same file.  */
  146. extern int dup2 (int fd, int fd2);
  147.  
  148. /* NULL-terminated array of "NAME=VALUE" environment variables.  */
  149. extern char **environ;
  150.  
  151. /* Replace the current process, executing path with args argv and
  152.    environment envp.  */
  153. extern int execve (const char *path, char **argv, char **envp);
  154.  
  155. /* Execute PATH with arguments ARGV and environment from `environ'.  */
  156. extern int execv (const char *path, char **argv);
  157. /* Execute PATH with all arguments after PATH until a NULL pointer,
  158.    and the argument after that for environment.  */
  159. extern int execle (const char *, const char *arg, ...);
  160. /* Execute PATH with all arguments after PATH until
  161.    a NULL pointer and environment from `environ'.  */
  162. extern int execl (const char *path, const char *arg, ...);
  163. /* Execute FILE, searching in the `PATH' environment variable if it contains
  164.    no slashes, with arguments ARGV and environment from `environ'.  */
  165. extern int execvp (const char *file, char **argv);
  166. /* Execute FILE, searching in the `PATH' environment variable if
  167.    it contains no slashes, with all arguments after FILE until a
  168.    NULL pointer and environment from `environ'.  */
  169. extern int execlp (const char *file, const char *arg, ...);
  170.  
  171. /* Terminate program execution with the low-order 8 bits of status.  */
  172. extern void _exit (int status);
  173.  
  174. /* Values for the NAME argument to `pathconf' and `fpathconf'.  */
  175. enum
  176.   {
  177.     _PC_LINK_MAX,
  178.     _PC_MAX_CANON,
  179.     _PC_MAX_INPUT,
  180.     _PC_NAME_MAX,
  181.     _PC_PATH_MAX,
  182.     _PC_PIPE_BUF,
  183.     _PC_CHOWN_RESTRICTED,
  184.     _PC_NO_TRUNC,
  185.     _PC_VDISABLE
  186.   };
  187.  
  188. /* Get file-specific configuration information about PATH.  */
  189. extern long int pathconf (const char *path, int name);
  190.  
  191. /* Get file-specific configuration about descriptor FD.  */
  192. extern long int fpathconf (int fd, int name);
  193.  
  194. /* Values for the argument to `sysconf'.  */
  195. enum
  196.   {
  197.     _SC_ARG_MAX,
  198.     _SC_CHILD_MAX,
  199.     _SC_CLK_TCK,
  200.     _SC_NGROUPS_MAX,
  201.     _SC_OPEN_MAX,
  202.     _SC_STREAM_MAX,
  203.     _SC_TZNAME_MAX,
  204.     _SC_JOB_CONTROL,
  205.     _SC_SAVED_IDS,
  206.     _SC_VERSION,
  207.     _SC_PAGESIZE,
  208.  
  209.     /* Values for the argument to `sysconf' corresponding to
  210.        _POSIX2_* symbols.  */
  211.     _SC_BC_BASE_MAX,
  212.     _SC_BC_DIM_MAX,
  213.     _SC_BC_SCALE_MAX,
  214.     _SC_BC_STRING_MAX,
  215.     _SC_COLL_WEIGHTS_MAX,
  216.     _SC_EQUIV_CLASS_MAX,
  217.     _SC_EXPR_NEST_MAX,
  218.     _SC_LINE_MAX,
  219.     _SC_RE_DUP_MAX,
  220.  
  221.     _SC_2_VERSION,
  222.     _SC_2_C_BIND,
  223.     _SC_2_C_DEV,
  224.     _SC_2_FORT_DEV,
  225.     _SC_2_FORT_RUN,
  226.     _SC_2_SW_DEV,
  227.     _SC_2_LOCALEDEF
  228.   };
  229.  
  230. /* Get the value of the system variable NAME.  */
  231. extern long int sysconf (int name);
  232.  
  233.  
  234. /* Get the process id of the calling process.  */
  235. extern __pid_t getpid (void);
  236. /* Get the process id of the calling process's parent.  */
  237. extern __pid_t getppid(void);
  238. /* Get the process group id of the calling process.  */
  239. extern __pid_t getpgrp(void);
  240. /* Set the process group id of the process matching pid to pgid.  */
  241. extern int setpgrp (__pid_t pid, __pid_t pgid);
  242. extern int setpgid (__pid_t pid, __pid_t pgid);
  243.  
  244. #if 0
  245. /* Create a new session with the calling process as its leader.  */
  246. extern __pid_t setsid (void);
  247. #endif
  248.  
  249. /* Get the real user id of the calling process.  */
  250. extern __uid_t getuid (void);
  251. /* Get the effective user id of the calling process.  */
  252. extern __uid_t geteuid (void);
  253. /* Get the real group id of the calling process.  */
  254. extern __gid_t getgid (void);
  255. /* Get the effective group id of the calling process.  */
  256. extern __gid_t getegid (void);
  257.  
  258. #if 0
  259. /* Return the number of supplementary groups the calling process is in.  */
  260. extern int getgroups (int size, __gid_t list[]);
  261. #endif
  262.  
  263. /* Set the user id of the calling process to uid.  */
  264. extern int setuid (__uid_t uid);
  265. /* Set the effective user id of the calling process to uid (from BSD).  */
  266. extern int seteuid (__uid_t uid);
  267. #if 0
  268. /* Combination of setuid and seteuid (from BSD).  */
  269. extern int setreuid (__uid_t ruid, __uid_t euid);
  270. #endif
  271.  
  272. /* Set the group id of the calling process to uid.  */
  273. extern int setgid (__gid_t gid);
  274. /* Set the effective group id of the calling process to uid (from BSD).  */
  275. extern int setegid (__gid_t gid);
  276. #if 0
  277. /* Combination of setgid and setegid (from BSD).  */
  278. extern int setregid (__gid_t rgid, __gid_t egid);
  279. #endif
  280.  
  281. /* Clone the calling process, creating an exact copy.  */
  282. #define fork() vfork()    /* WARNING */
  283. /* Clone the calling process, but without copying the whole address
  284.    space (from BSD).  */
  285. extern __pid_t vfork (void);
  286.  
  287. /* Return the pathname of the terminal fd is open on.  */
  288. extern char *ttyname (int fd);
  289.  
  290. /* Return 1 if fd is a valid descriptor associated with a terminal.  */
  291. extern int isatty (int fd);
  292.  
  293. /* Make a link to from named to.  */
  294. extern int link (const char *from, const char *to);
  295.  
  296. /* Remove the line name.  */
  297. extern int unlink (char *name);
  298.  
  299. /* Remove the directory path.  */
  300. extern int rmdir (const char *path);
  301.  
  302. /* Return the login name of the user.  */
  303. extern char *getlogin (void);
  304.  
  305. #if 0
  306. /* Set the foreground process group ID of FD set PGRP_ID.  */
  307. extern int tcsetpgrp (int fd, __pid_t pgrp_id);
  308.  
  309.  
  310. /* Set the login name returned by `getlogin'.  */
  311. extern int setlogin (const char *name);
  312.  
  313. /* Invoke system call number 'sysno', passing it the remaining args.  */
  314. extern int syscall (int sysno, ...);
  315. #endif
  316.  
  317. #ifndef F_LOCK
  318. /* `lockf' is a simpler interface to the locking facilities of `fcntl'.
  319.    LEN is always relative to the current file position.
  320.    The CMD argument is one of the following.  */
  321.  
  322. #define F_ULOCK 0       /* Unlock a previously locked region.  */
  323. #define F_LOCK  1       /* Lock a region for exclusive use.  */
  324. #define F_TLOCK 2       /* Test and lock a region for exclusive use.  */
  325. #define F_TEST  3       /* Test a region for other processes locks.  */
  326.  
  327. extern int lockf (int fd, int cmd, __off_t len);
  328. #endif /* Use misc and F_LOCK not already defined.  */
  329.  
  330. /* the 2nd parameter to __uname() is the subdirectory creation flag */
  331.  
  332. extern    char    *__uname(char *, int); /* UNIX -> RiscOS filename conversion */
  333. extern    int    __uname_control;
  334.  
  335. #define __UNAME_NO_PROCESS 0x01
  336. #define __UNAME_LONG_TRUNC 0x02
  337. #define __UNAME_DROP_VOWEL 0x04
  338.  
  339. /* This bit map controls how uname processes filenames
  340.  * default value is 6 (__UNAME_DROP_VOWEL | __UNAME_LONG_TRUNC)
  341.  * 0 : 1 => No processing done at all
  342.  * 1 : 0 => Truncate each path element at 10 chars, 1 => max length is 55 chars
  343.        (for the longfiles module)
  344.  * 2 : 1 => If path element is too long, drop vowels before truncating
  345.  */
  346.  
  347. extern int *__uname_dont_pack_ptr;
  348.  
  349. /* BSD extensions.  */
  350.  
  351. extern int brk (void *);
  352. extern void *sbrk (int);
  353.  
  354. /* Put the name of the current host in no more than len bytes of name.  */
  355. extern int gethostname (char *name, size_t len);
  356.  
  357. /* Make all changes done to all files actually appear on disk.  */
  358. extern int sync (void);
  359.  
  360. /* Make all changes done to FD actually appear on disk.  */
  361. extern int fsync (int fd);
  362.  
  363. #if 0
  364. /* Truncate FILE to LENGTH bytes.  */
  365. extern int truncate (const char *file, __off_t length);
  366.  
  367. /* Truncate the file FD is open on to LENGTH bytes.  */
  368. extern int ftruncate (int fd, __off_t length);
  369. #endif
  370.  
  371. /* Set the name of the current host to name, which is len bytes long.  */
  372. extern int sethostname (const char *name, size_t len);
  373.  
  374. /* Return the number of bytes in a page.  This is the system's page size,
  375.    which is not necessarily the same as the hardware page size.  */
  376. extern size_t getpagesize (void);
  377.  
  378. /* Return the maximum number of file descriptors
  379.    the current process could possibly have.  */
  380. extern int getdtablesize (void);
  381.  
  382. #if 0
  383.  
  384. /* Return the current machine's Internet number.  */
  385. extern long int gethostid (void);
  386.  
  387. /* Set the current machine's Internet number to ID.
  388.    This call is restricted to the super-user.  */
  389. extern int sethostid (long int id);
  390.  
  391.  
  392. /* Revoke access permissions to all processes currently communicating
  393.    with the control terminal, and then send a SIGHUP signal to the process
  394.    group of the control terminal.  */
  395. extern int vhangup (void);
  396.  
  397.  
  398. /* Turn accounting on if NAME is an existing file.  The system will then write
  399.    a record for each process as it terminates, to this file.  If NAME is NULL,
  400.    turn accounting off.  This call is restricted to the super-user.  */
  401. extern int acct (const char *name);
  402.  
  403. /* Make PATH be the root directory (the starting point for absolute paths).
  404.    This call is restricted to the super-user.  */
  405. extern int chroot (const char *path);
  406.  
  407. /* Make the block special device PATH available to the system for swapping.
  408.    This call is restricted to the super-user.  */
  409. extern int swapon (const char *path);
  410.  
  411. /* Reboot or halt the system.  */
  412. extern int reboot (int howto);
  413.  
  414.  
  415. /* Successive calls return the shells listed in `/etc/shells'.  */
  416. extern char *getusershell (void);
  417. extern void endusershell (void); /* Discard cached info.  */
  418. extern void setusershell (void); /* Rewind and re-read the file.  */
  419.  
  420.  
  421. /* Prompt with PROMPT and read a string from the terminal without echoing.
  422.    Uses /dev/tty if possible; otherwise stderr and stdin.  */
  423. extern char *getpass (const char *prompt);
  424. #endif
  425.  
  426. /* POSIX 2 extensions.  */
  427.  
  428.  
  429. /* Values for the NAME argument to `confstr'.  */
  430. enum
  431.   {
  432.     _CS_PATH            /* The default search path.  */
  433.   };
  434.  
  435. /* Get the value of the string-valued system variable NAME.  */
  436. extern size_t confstr (int name, char *buf, size_t len);
  437.  
  438. #if 0
  439. /* Process the arguments in ARGV (ARGC of them, minus
  440.    the program name) for options given in OPTS.
  441.  
  442.    If `opterr' is zero, no messages are generated
  443.    for invalid options; it defaults to 1.
  444.    `optind' is the current index into ARGV.
  445.    `optarg' is the argument corresponding to the current option.
  446.    Return the option character from OPTS just read.
  447.    Return -1 when there are no more options.
  448.    For unrecognized options, or options missing arguments,
  449.    `optopt' is set to the option letter, and '?' is returned.
  450.  
  451.    The OPTS string is a list of characters which are recognized option
  452.    letters, optionally followed by colons, specifying that that letter
  453.    takes an argument, to be placed in `optarg'.
  454.  
  455.    If a letter in OPTS is followed by two colons, its argument is optional.
  456.    This behavior is specific to the GNU `getopt'.
  457.  
  458.    The argument `--' causes premature termination of argument scanning,
  459.    explicitly telling `getopt' that there are no more options.
  460.  
  461.    If OPTS begins with `--', then non-option arguments
  462.    are treated as arguments to the option '\0'.
  463.    This behavior is specific to the GNU `getopt'.  */
  464. extern int getopt (int argc, const char *argv, const char *opts);
  465. extern int opterr;
  466. extern int optind;
  467. extern int optopt;
  468. extern char *optarg;
  469. #endif
  470.  
  471. #ifdef __cplusplus
  472.     }
  473. #endif
  474.  
  475. #endif
  476.