1<html lang="en"> 2<head> 3<title>open - Debugging with GDB</title> 4<meta http-equiv="Content-Type" content="text/html"> 5<meta name="description" content="Debugging with GDB"> 6<meta name="generator" content="makeinfo 4.13"> 7<link title="Top" rel="start" href="index.html#Top"> 8<link rel="up" href="List-of-Supported-Calls.html#List-of-Supported-Calls" title="List of Supported Calls"> 9<link rel="next" href="close.html#close" title="close"> 10<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> 11<!-- 12Copyright (C) 1988-2013 Free Software Foundation, Inc. 13 14Permission is granted to copy, distribute and/or modify this document 15under the terms of the GNU Free Documentation License, Version 1.3 or 16any later version published by the Free Software Foundation; with the 17Invariant Sections being ``Free Software'' and ``Free Software Needs 18Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,'' 19and with the Back-Cover Texts as in (a) below. 20 21(a) The FSF's Back-Cover Text is: ``You are free to copy and modify 22this GNU Manual. Buying copies from GNU Press supports the FSF in 23developing GNU and promoting software freedom.'' 24--> 25<meta http-equiv="Content-Style-Type" content="text/css"> 26<style type="text/css"><!-- 27 pre.display { font-family:inherit } 28 pre.format { font-family:inherit } 29 pre.smalldisplay { font-family:inherit; font-size:smaller } 30 pre.smallformat { font-family:inherit; font-size:smaller } 31 pre.smallexample { font-size:smaller } 32 pre.smalllisp { font-size:smaller } 33 span.sc { font-variant:small-caps } 34 span.roman { font-family:serif; font-weight:normal; } 35 span.sansserif { font-family:sans-serif; font-weight:normal; } 36--></style> 37<link rel="stylesheet" type="text/css" href="../cs.css"> 38</head> 39<body> 40<div class="node"> 41<a name="open"></a> 42<p> 43Next: <a rel="next" accesskey="n" href="close.html#close">close</a>, 44Up: <a rel="up" accesskey="u" href="List-of-Supported-Calls.html#List-of-Supported-Calls">List of Supported Calls</a> 45<hr> 46</div> 47 48<h5 class="unnumberedsubsubsec">open</h5> 49 50<p><a name="index-open_002c-file_002di_002fo-system-call-2846"></a> 51 <dl> 52<dt>Synopsis:<dd> 53 <pre class="smallexample"> int open(const char *pathname, int flags); 54 int open(const char *pathname, int flags, mode_t mode); 55</pre> 56 <br><dt>Request:<dd>‘<samp><span class="samp">Fopen,</span><var>pathptr</var><span class="samp">/</span><var>len</var><span class="samp">,</span><var>flags</var><span class="samp">,</span><var>mode</var></samp>’ 57 58 <p class="noindent"><var>flags</var> is the bitwise <code>OR</code> of the following values: 59 60 <dl> 61<dt><code>O_CREAT</code><dd>If the file does not exist it will be created. The host 62rules apply as far as file ownership and time stamps 63are concerned. 64 65 <br><dt><code>O_EXCL</code><dd>When used with <code>O_CREAT</code>, if the file already exists it is 66an error and open() fails. 67 68 <br><dt><code>O_TRUNC</code><dd>If the file already exists and the open mode allows 69writing (<code>O_RDWR</code> or <code>O_WRONLY</code> is given) it will be 70truncated to zero length. 71 72 <br><dt><code>O_APPEND</code><dd>The file is opened in append mode. 73 74 <br><dt><code>O_RDONLY</code><dd>The file is opened for reading only. 75 76 <br><dt><code>O_WRONLY</code><dd>The file is opened for writing only. 77 78 <br><dt><code>O_RDWR</code><dd>The file is opened for reading and writing. 79</dl> 80 81 <p class="noindent">Other bits are silently ignored. 82 83 <p class="noindent"><var>mode</var> is the bitwise <code>OR</code> of the following values: 84 85 <dl> 86<dt><code>S_IRUSR</code><dd>User has read permission. 87 88 <br><dt><code>S_IWUSR</code><dd>User has write permission. 89 90 <br><dt><code>S_IRGRP</code><dd>Group has read permission. 91 92 <br><dt><code>S_IWGRP</code><dd>Group has write permission. 93 94 <br><dt><code>S_IROTH</code><dd>Others have read permission. 95 96 <br><dt><code>S_IWOTH</code><dd>Others have write permission. 97</dl> 98 99 <p class="noindent">Other bits are silently ignored. 100 101 <br><dt>Return value:<dd><code>open</code> returns the new file descriptor or -1 if an error 102occurred. 103 104 <br><dt>Errors:<dd> 105 <dl> 106<dt><code>EEXIST</code><dd><var>pathname</var> already exists and <code>O_CREAT</code> and <code>O_EXCL</code> were used. 107 108 <br><dt><code>EISDIR</code><dd><var>pathname</var> refers to a directory. 109 110 <br><dt><code>EACCES</code><dd>The requested access is not allowed. 111 112 <br><dt><code>ENAMETOOLONG</code><dd><var>pathname</var> was too long. 113 114 <br><dt><code>ENOENT</code><dd>A directory component in <var>pathname</var> does not exist. 115 116 <br><dt><code>ENODEV</code><dd><var>pathname</var> refers to a device, pipe, named pipe or socket. 117 118 <br><dt><code>EROFS</code><dd><var>pathname</var> refers to a file on a read-only filesystem and 119write access was requested. 120 121 <br><dt><code>EFAULT</code><dd><var>pathname</var> is an invalid pointer value. 122 123 <br><dt><code>ENOSPC</code><dd>No space on device to create the file. 124 125 <br><dt><code>EMFILE</code><dd>The process already has the maximum number of files open. 126 127 <br><dt><code>ENFILE</code><dd>The limit on the total number of files open on the system 128has been reached. 129 130 <br><dt><code>EINTR</code><dd>The call was interrupted by the user. 131</dl> 132 133 </dl> 134 135 </body></html> 136 137