/
ColdC/Functions/
ColdC/Structure/
<head><title>ColdC: Function/Method Reference: fopen()</title></head>

<body>

<h1 align=center><a href="/ColdC/">ColdC</a>: <a href="/ColdC/Functions/">Function/Method Reference</a>: fopen()</h1>

<hr>

<p>
<font size=+1><i>LIST</i> <b>fopen</b>(<i>STRING <b>filename</b>[, STRING <b>mode</b>]</i>)</font>

<p>This function is used to open a file on the current object.  It is
called with one or two arguments.  The first argument is the name of 
the file to open.  If the driver was compiled with the
<tt>RESTRICTIVE_FILES</tt> option, the filename will have restrictions
(see the section on <a href="/ColdC/files.html">Files</a> for more information).
If <tt>RESTRICTIVE_FILES</tt> was compiled, all files will have the
<i>root</i> directory prepended to them (this directory is defined
by a command line argument to <a href="/Genesis/"><i>genesis</i></a>.
If it was not compiled, but the file does not begin with a slash
("/"), the <i>root</i> directory will still be prepended.

<p>The second argument is the mode for the file.  If the mode begins with
"&lt;" or nothing, the file is opened for reading.  If the mode begins with
"&gt;", the file is truncated to zero length or created for writing.  If the
mode begins with "&gt;&gt;", the file is opend for appending.  If the second
argument is not specified, the mode of file defaults to "&lt;".

<p>You can also place a "+" before "&gt;" or "&lt;" to specify read and
write access to the file.  Ending a mode with a "-" sets it as a binary
file, meaning that input and output to the file is through buffers, rather
than ColdC strings.

<p>If successful, the return value of fopen() is stat information in the
format returned by <a href="fstat.html"><code>fstat()</code></a>.

<p>Examples:

<blockquote><pre>
stat = fopen("log", ">>");
stat = fopen("/usr/home/test.info", "+>-");
</pre></blockquote>

<p><hr size=4><p align=center><i>Last Modified on Mar 2 1996</i>
<br><i>Copyright &copy; 1995, 1996, Brandon Gillespie</i>
</body>