open.html 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1988-2020 Free Software Foundation, Inc.
  4. Permission is granted to copy, distribute and/or modify this document
  5. under the terms of the GNU Free Documentation License, Version 1.3 or
  6. any later version published by the Free Software Foundation; with the
  7. Invariant Sections being "Free Software" and "Free Software Needs
  8. Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
  9. and with the Back-Cover Texts as in (a) below.
  10. (a) The FSF's Back-Cover Text is: "You are free to copy and modify
  11. this GNU Manual. Buying copies from GNU Press supports the FSF in
  12. developing GNU and promoting software freedom." -->
  13. <!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <title>Debugging with GDB: open</title>
  16. <meta name="description" content="Debugging with GDB: open">
  17. <meta name="keywords" content="Debugging with GDB: open">
  18. <meta name="resource-type" content="document">
  19. <meta name="distribution" content="global">
  20. <meta name="Generator" content="makeinfo">
  21. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  22. <link href="index.html#Top" rel="start" title="Top">
  23. <link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
  24. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  25. <link href="List-of-Supported-Calls.html#List-of-Supported-Calls" rel="up" title="List of Supported Calls">
  26. <link href="close.html#close" rel="next" title="close">
  27. <link href="List-of-Supported-Calls.html#List-of-Supported-Calls" rel="previous" title="List of Supported Calls">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.smallquotation {font-size: smaller}
  32. div.display {margin-left: 3.2em}
  33. div.example {margin-left: 3.2em}
  34. div.indentedblock {margin-left: 3.2em}
  35. div.lisp {margin-left: 3.2em}
  36. div.smalldisplay {margin-left: 3.2em}
  37. div.smallexample {margin-left: 3.2em}
  38. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  39. div.smalllisp {margin-left: 3.2em}
  40. kbd {font-style:oblique}
  41. pre.display {font-family: inherit}
  42. pre.format {font-family: inherit}
  43. pre.menu-comment {font-family: serif}
  44. pre.menu-preformatted {font-family: serif}
  45. pre.smalldisplay {font-family: inherit; font-size: smaller}
  46. pre.smallexample {font-size: smaller}
  47. pre.smallformat {font-family: inherit; font-size: smaller}
  48. pre.smalllisp {font-size: smaller}
  49. span.nocodebreak {white-space:nowrap}
  50. span.nolinebreak {white-space:nowrap}
  51. span.roman {font-family:serif; font-weight:normal}
  52. span.sansserif {font-family:sans-serif; font-weight:normal}
  53. ul.no-bullet {list-style: none}
  54. -->
  55. </style>
  56. </head>
  57. <body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  58. <a name="open"></a>
  59. <div class="header">
  60. <p>
  61. Next: <a href="close.html#close" accesskey="n" rel="next">close</a>, Up: <a href="List-of-Supported-Calls.html#List-of-Supported-Calls" accesskey="u" rel="up">List of Supported Calls</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  62. </div>
  63. <hr>
  64. <a name="open-1"></a>
  65. <h4 class="unnumberedsubsubsec">open</h4>
  66. <a name="index-open_002c-file_002di_002fo-system-call"></a>
  67. <dl compact="compact">
  68. <dt>Synopsis:</dt>
  69. <dd><div class="smallexample">
  70. <pre class="smallexample">int open(const char *pathname, int flags);
  71. int open(const char *pathname, int flags, mode_t mode);
  72. </pre></div>
  73. </dd>
  74. <dt>Request:</dt>
  75. <dd><p>&lsquo;<samp>Fopen,<var>pathptr</var>/<var>len</var>,<var>flags</var>,<var>mode</var></samp>&rsquo;
  76. </p>
  77. <p><var>flags</var> is the bitwise <code>OR</code> of the following values:
  78. </p>
  79. <dl compact="compact">
  80. <dt><code>O_CREAT</code></dt>
  81. <dd><p>If the file does not exist it will be created. The host
  82. rules apply as far as file ownership and time stamps
  83. are concerned.
  84. </p>
  85. </dd>
  86. <dt><code>O_EXCL</code></dt>
  87. <dd><p>When used with <code>O_CREAT</code>, if the file already exists it is
  88. an error and open() fails.
  89. </p>
  90. </dd>
  91. <dt><code>O_TRUNC</code></dt>
  92. <dd><p>If the file already exists and the open mode allows
  93. writing (<code>O_RDWR</code> or <code>O_WRONLY</code> is given) it will be
  94. truncated to zero length.
  95. </p>
  96. </dd>
  97. <dt><code>O_APPEND</code></dt>
  98. <dd><p>The file is opened in append mode.
  99. </p>
  100. </dd>
  101. <dt><code>O_RDONLY</code></dt>
  102. <dd><p>The file is opened for reading only.
  103. </p>
  104. </dd>
  105. <dt><code>O_WRONLY</code></dt>
  106. <dd><p>The file is opened for writing only.
  107. </p>
  108. </dd>
  109. <dt><code>O_RDWR</code></dt>
  110. <dd><p>The file is opened for reading and writing.
  111. </p></dd>
  112. </dl>
  113. <p>Other bits are silently ignored.
  114. </p>
  115. <p><var>mode</var> is the bitwise <code>OR</code> of the following values:
  116. </p>
  117. <dl compact="compact">
  118. <dt><code>S_IRUSR</code></dt>
  119. <dd><p>User has read permission.
  120. </p>
  121. </dd>
  122. <dt><code>S_IWUSR</code></dt>
  123. <dd><p>User has write permission.
  124. </p>
  125. </dd>
  126. <dt><code>S_IRGRP</code></dt>
  127. <dd><p>Group has read permission.
  128. </p>
  129. </dd>
  130. <dt><code>S_IWGRP</code></dt>
  131. <dd><p>Group has write permission.
  132. </p>
  133. </dd>
  134. <dt><code>S_IROTH</code></dt>
  135. <dd><p>Others have read permission.
  136. </p>
  137. </dd>
  138. <dt><code>S_IWOTH</code></dt>
  139. <dd><p>Others have write permission.
  140. </p></dd>
  141. </dl>
  142. <p>Other bits are silently ignored.
  143. </p>
  144. </dd>
  145. <dt>Return value:</dt>
  146. <dd><p><code>open</code> returns the new file descriptor or -1 if an error
  147. occurred.
  148. </p>
  149. </dd>
  150. <dt>Errors:</dt>
  151. <dd>
  152. <dl compact="compact">
  153. <dt><code>EEXIST</code></dt>
  154. <dd><p><var>pathname</var> already exists and <code>O_CREAT</code> and <code>O_EXCL</code> were used.
  155. </p>
  156. </dd>
  157. <dt><code>EISDIR</code></dt>
  158. <dd><p><var>pathname</var> refers to a directory.
  159. </p>
  160. </dd>
  161. <dt><code>EACCES</code></dt>
  162. <dd><p>The requested access is not allowed.
  163. </p>
  164. </dd>
  165. <dt><code>ENAMETOOLONG</code></dt>
  166. <dd><p><var>pathname</var> was too long.
  167. </p>
  168. </dd>
  169. <dt><code>ENOENT</code></dt>
  170. <dd><p>A directory component in <var>pathname</var> does not exist.
  171. </p>
  172. </dd>
  173. <dt><code>ENODEV</code></dt>
  174. <dd><p><var>pathname</var> refers to a device, pipe, named pipe or socket.
  175. </p>
  176. </dd>
  177. <dt><code>EROFS</code></dt>
  178. <dd><p><var>pathname</var> refers to a file on a read-only filesystem and
  179. write access was requested.
  180. </p>
  181. </dd>
  182. <dt><code>EFAULT</code></dt>
  183. <dd><p><var>pathname</var> is an invalid pointer value.
  184. </p>
  185. </dd>
  186. <dt><code>ENOSPC</code></dt>
  187. <dd><p>No space on device to create the file.
  188. </p>
  189. </dd>
  190. <dt><code>EMFILE</code></dt>
  191. <dd><p>The process already has the maximum number of files open.
  192. </p>
  193. </dd>
  194. <dt><code>ENFILE</code></dt>
  195. <dd><p>The limit on the total number of files open on the system
  196. has been reached.
  197. </p>
  198. </dd>
  199. <dt><code>EINTR</code></dt>
  200. <dd><p>The call was interrupted by the user.
  201. </p></dd>
  202. </dl>
  203. </dd>
  204. </dl>
  205. <hr>
  206. <div class="header">
  207. <p>
  208. Next: <a href="close.html#close" accesskey="n" rel="next">close</a>, Up: <a href="List-of-Supported-Calls.html#List-of-Supported-Calls" accesskey="u" rel="up">List of Supported Calls</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
  209. </div>
  210. </body>
  211. </html>