open.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <html>
  2. <head>
  3. <title>open</title>
  4. <body bgcolor=#ffffff>
  5. <h2 align=center>open</h2>
  6. <h4 align=center>OS/161 Reference Manual</h4>
  7. <h3>Name</h3>
  8. open - open a file
  9. <h3>Library</h3>
  10. Standard C Library (libc, -lc)
  11. <h3>Synopsis</h3>
  12. #include &lt;unistd.h&gt;<br>
  13. <br>
  14. int<br>
  15. open(const char *<em>filename</em>, int <em>flags</em>);<br>
  16. int<br>
  17. open(const char *<em>filename</em>, int <em>flags</em>, int <em>mode</em>);<br>
  18. <h3>Description</h3>
  19. open opens the file, device, or other kernel object named by the
  20. pathname <em>filename</em>. The <em>flags</em> argument specifies how
  21. to open the file. The optional <em>mode</em> argument is only
  22. meaningful in Unix (or if you choose to implement Unix-style security
  23. later on) and can be ignored.
  24. <p>
  25. The flags argument should consist of one of
  26. <blockquote><table width=90%>
  27. <tr><td>O_RDONLY</td> <td>Open for reading only.</td></tr>
  28. <tr><td>O_WRONLY</td> <td>Open for writing only.</td></tr>
  29. <tr><td>O_RDWR</td> <td>Open for reading and writing.</td></tr>
  30. </table></blockquote>
  31. It may also have any of the following flags OR'd in:
  32. <blockquote><table width=90%>
  33. <tr><td>O_CREAT</td> <td>Create the file if it doesn't exist.</td></tr>
  34. <tr><td>O_EXCL</td> <td>Fail if the file already exists.</td></tr>
  35. <tr><td>O_TRUNC</td> <td>Truncate the file to length 0 upon open.</td></tr>
  36. <tr><td>O_APPEND</td> <td>Open the file in append mode.</td></tr>
  37. </table></blockquote>
  38. O_EXCL is only meaningful if O_CREAT is also used.
  39. <p>
  40. O_APPEND causes all writes to the file to occur at the end of file, no
  41. matter what gets written to the file by whoever else. (This
  42. functionality may be optional; consult your course's assignments.)
  43. <p>
  44. open returns a file handle suitable for passing to
  45. <A HREF=read.html>read</A>,
  46. <A HREF=write.html>write</A>,
  47. <A HREF=close.html>close</A>,
  48. etc. This file handle must be greater than or equal to zero. Note
  49. that file handles 0 (STDIN_FILENO), 1 (STDOUT_FILENO), and 2
  50. (STDERR_FILENO) are used in special ways and are typically assumed by
  51. user-level code to always be open.
  52. <h3>Return Values</h3>
  53. On success, open returns a nonnegative file handle. On error, -1 is
  54. returned, and <A HREF=errno.html>errno</A> is set according to the error
  55. encountered.
  56. <h3>Errors</h3>
  57. The following error codes should be returned under the conditions
  58. given. Other error codes may be returned for other errors not
  59. mentioned here.
  60. <blockquote><table width=90%>
  61. <td width=10%>&nbsp;</td><td>&nbsp;</td></tr>
  62. <tr><td>ENODEV</td> <td>The device prefix of <em>filename</em> did
  63. not exist.</td></tr>
  64. <tr><td>ENOTDIR</td> <td>A non-final component of <em>filename</em>
  65. was not a directory.</td></tr>
  66. <tr><td>ENOENT</td> <td>A non-final component of <em>filename</em>
  67. did not exist.</td></tr>
  68. <tr><td>ENOENT</td> <td>The named file does not exist, and O_CREAT
  69. was not specified.</td></tr>
  70. <tr><td>EEXIST</td> <td>The named file exists, and O_EXCL was
  71. specified.</td></tr>
  72. <tr><td>EISDIR</td> <td>The named object is a directory, and it
  73. was to be opened for writing.</td></tr>
  74. <tr><td>EMFILE</td> <td>The process's file table was full, or a
  75. process-specific limit on open files
  76. was reached.</td></tr>
  77. <tr><td>ENFILE</td> <td>The system file table is full, if such a
  78. thing exists, or a system-wide limit
  79. on open files was reached.</td></tr>
  80. <tr><td>ENXIO</td> <td>The named object is a block device with no
  81. mounted filesystem.</td></tr>
  82. <tr><td>ENOSPC</td> <td>The file was to be created, and the
  83. filesystem involved is full.</td></tr>
  84. <tr><td>EINVAL</td> <td><em>flags</em> contained invalid values.</td></tr>
  85. <tr><td>EIO</td> <td>A hard I/O error occurred.</td></tr>
  86. <tr><td>EFAULT</td> <td><em>filename</em> was an invalid pointer.</td></tr>
  87. </table></blockquote>
  88. </body>
  89. </html>