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