unistd.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*
  2. * Copyright (c) 2000, 2001, 2002, 2003, 2004, 2005, 2008, 2009
  3. * The President and Fellows of Harvard College.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 3. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. */
  29. #ifndef _UNISTD_H_
  30. #define _UNISTD_H_
  31. #include <sys/types.h>
  32. /*
  33. * Get the various constants (flags, codes, etc.) for calls from
  34. * kernel includes. This way user-level code doesn't need to know
  35. * about the kern/ headers.
  36. */
  37. #include <kern/fcntl.h>
  38. #include <kern/ioctl.h>
  39. #include <kern/reboot.h>
  40. #include <kern/seek.h>
  41. #include <kern/time.h>
  42. #include <kern/unistd.h>
  43. #include <kern/wait.h>
  44. /*
  45. * Prototypes for OS/161 system calls.
  46. *
  47. * Note that the following system calls are prototyped in other
  48. * header files, as follows:
  49. *
  50. * stat: sys/stat.h
  51. * fstat: sys/stat.h
  52. * lstat: sys/stat.h
  53. * mkdir: sys/stat.h
  54. *
  55. * If this were standard Unix, more prototypes would go in other
  56. * header files as well, as follows:
  57. *
  58. * waitpid: sys/wait.h
  59. * open: fcntl.h or sys/fcntl.h
  60. * reboot: sys/reboot.h
  61. * ioctl: sys/ioctl.h
  62. * remove: stdio.h
  63. * rename: stdio.h
  64. * time: time.h
  65. *
  66. * Also note that the prototypes for open() and mkdir() contain, for
  67. * compatibility with Unix, an extra argument that is not meaningful
  68. * in OS/161. This is the "mode" (file permissions) for a newly created
  69. * object. (With open, if no file is created, this is ignored, and the
  70. * call prototype is gimmicked so it doesn't have to be passed either.)
  71. *
  72. * You should ignore these arguments in the OS/161 kernel unless you're
  73. * implementing security and file permissions.
  74. *
  75. * If you are implementing security and file permissions and using a
  76. * model different from Unix so that you need different arguments to
  77. * these calls, you may make appropriate changes, or define new syscalls
  78. * with different names and take the old ones out, or whatever.
  79. *
  80. * As a general rule of thumb, however, while you can make as many new
  81. * syscalls of your own as you like, you shouldn't change the
  82. * definitions of the ones that are already here. They've been written
  83. * to be pretty much compatible with Unix, and the teaching staff has
  84. * test code that expects them to behave in particular ways.
  85. *
  86. * Of course, if you want to redesign the user/kernel API and make a
  87. * lot of work for yourself, feel free, just contact the teaching
  88. * staff beforehand. :-)
  89. *
  90. * The categories (required/recommended/optional) are guesses - check
  91. * the text of the various assignments for an authoritative list.
  92. */
  93. /*
  94. * NOTE NOTE NOTE NOTE NOTE
  95. *
  96. * This file is *not* shared with the kernel, even though in a sense
  97. * the kernel needs to know about these prototypes. This is because,
  98. * due to error handling concerns, the in-kernel versions of these
  99. * functions will usually have slightly different signatures.
  100. */
  101. #ifdef __GNUC__
  102. /* GCC gets into a snit if _exit isn't declared to not return */
  103. #define __DEAD __attribute__((__noreturn__))
  104. #else
  105. #define __DEAD
  106. #endif
  107. /* Required. */
  108. __DEAD void _exit(int code);
  109. int execv(const char *prog, char *const *args);
  110. pid_t fork(void);
  111. int waitpid(pid_t pid, int *returncode, int flags);
  112. /*
  113. * Open actually takes either two or three args: the optional third
  114. * arg is the file mode used for creation. Unless you're implementing
  115. * security and permissions, you can ignore it.
  116. */
  117. int open(const char *filename, int flags, ...);
  118. int read(int filehandle, void *buf, size_t size);
  119. int write(int filehandle, const void *buf, size_t size);
  120. int close(int filehandle);
  121. int reboot(int code);
  122. int sync(void);
  123. /* mkdir - see sys/stat.h */
  124. int rmdir(const char *dirname);
  125. /* Recommended. */
  126. int getpid(void);
  127. int ioctl(int filehandle, int code, void *buf);
  128. off_t lseek(int filehandle, off_t pos, int code);
  129. int fsync(int filehandle);
  130. int ftruncate(int filehandle, off_t size);
  131. int remove(const char *filename);
  132. int rename(const char *oldfile, const char *newfile);
  133. int link(const char *oldfile, const char *newfile);
  134. /* fstat - see sys/stat.h */
  135. int chdir(const char *path);
  136. /* Optional. */
  137. void *sbrk(int change);
  138. int getdirentry(int filehandle, char *buf, size_t buflen);
  139. int symlink(const char *target, const char *linkname);
  140. int readlink(const char *path, char *buf, size_t buflen);
  141. int dup2(int filehandle, int newhandle);
  142. int pipe(int filehandles[2]);
  143. time_t __time(time_t *seconds, unsigned long *nanoseconds);
  144. int __getcwd(char *buf, size_t buflen);
  145. /* stat - see sys/stat.h */
  146. /* lstat - see sys/stat.h */
  147. /*
  148. * These are not themselves system calls, but wrapper routines in libc.
  149. */
  150. char *getcwd(char *buf, size_t buflen); /* calls __getcwd */
  151. time_t time(time_t *seconds); /* calls __time */
  152. #endif /* _UNISTD_H_ */