📄 glib-file-utilities.html
字号:
</p><p>Note that in contrast to <a href="glib-File-Utilities.html#g-mkstemp"><code class="function">g_mkstemp()</code></a> (and <code class="function">mkstemp()</code>) <em class="parameter"><code>tmpl</code></em> is not modified, and might thus be a read-only literal string.</p><p>The actual name used is returned in <em class="parameter"><code>name_used</code></em> if non-<code class="literal">NULL</code>. Thisstring should be freed with <a href="glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a> when not needed any longer.The returned name is in the GLib file name encoding.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>tmpl</code></em> :</span></td><td> Template for file name, as in <a href="glib-File-Utilities.html#g-mkstemp"><code class="function">g_mkstemp()</code></a>, basename only</td></tr><tr><td><span class="term"><em class="parameter"><code>name_used</code></em> :</span></td><td> location to store actual name used</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A file handle (as from <code class="function">open()</code>) to the file opened for reading and writing. The file is opened in binary mode on platforms where there is a difference. The file handle should beclosed with <code class="function">close()</code>. In case of errors, -1 is returned and <em class="parameter"><code>error</code></em> will be set.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3054122"></a><h3><a name="g-file-read-link"></a>g_file_read_link ()</h3><a class="indexterm" name="id3054133"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gchar">gchar</a>* g_file_read_link (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Reads the contents of the symbolic link <em class="parameter"><code>filename</code></em> like the POSIX<code class="function">readlink()</code> function. The returned string is in the encoding usedfor filenames. Use <a href="glib-Character-Set-Conversion.html#g-filename-to-utf8"><code class="function">g_filename_to_utf8()</code></a> to convert it to UTF-8.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>filename</code></em> :</span></td><td> the symbolic link</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> A newly allocated string with the contents of the symbolic link, or <code class="literal">NULL</code> if an error occurred.</td></tr></tbody></table></div><p>Since 2.4</p></div><hr><div class="refsect2" lang="en"><a name="id3054265"></a><h3><a name="GDir"></a>GDir</h3><a class="indexterm" name="id3054276"></a><pre class="programlisting">typedef struct _GDir GDir;</pre><p>An opaque structure representing an opened directory.</p></div><hr><div class="refsect2" lang="en"><a name="id3054292"></a><h3><a name="g-dir-open"></a>g_dir_open ()</h3><a class="indexterm" name="id3054302"></a><pre class="programlisting"><a href="glib-File-Utilities.html#GDir">GDir</a>* g_dir_open (const <a href="glib-Basic-Types.html#gchar">gchar</a> *path, <a href="glib-Basic-Types.html#guint">guint</a> flags, <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Opens a directory for reading. The names of the files in thedirectory can then be retrieved using <a href="glib-File-Utilities.html#g-dir-read-name"><code class="function">g_dir_read_name()</code></a>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>path</code></em> :</span></td><td> the path to the directory you are interested in. On Unix in the on-disk encoding. On Windows in UTF-8</td></tr><tr><td><span class="term"><em class="parameter"><code>flags</code></em> :</span></td><td> Currently must be set to 0. Reserved for future use.</td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em> :</span></td><td> return location for a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <code class="literal">NULL</code>. If non-<code class="literal">NULL</code>, an error will be set if and only if g_dir_open_fails.</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a newly allocated <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a> on success, <code class="literal">NULL</code> on failure. If non-<code class="literal">NULL</code>, you must free the result with <a href="glib-File-Utilities.html#g-dir-close"><code class="function">g_dir_close()</code></a> when you are finished with it.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3054473"></a><h3><a name="g-dir-read-name"></a>g_dir_read_name ()</h3><a class="indexterm" name="id3054483"></a><pre class="programlisting">const <a href="glib-Basic-Types.html#gchar">gchar</a>* g_dir_read_name (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);</pre><p>Retrieves the name of the next entry in the directory. The '.' and'..' entries are omitted. On Windows, the returned name is inUTF-8. On Unix, it is in the on-disk encoding.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>dir</code></em> :</span></td><td> a <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a>* created by <a href="glib-File-Utilities.html#g-dir-open"><code class="function">g_dir_open()</code></a></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> The entry's name or <code class="literal">NULL</code> if there are no more entries. The return value is owned by GLib and must not be modified or freed.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3054573"></a><h3><a name="g-dir-rewind"></a>g_dir_rewind ()</h3><a class="indexterm" name="id3054584"></a><pre class="programlisting">void g_dir_rewind (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);</pre><p>Resets the given directory. The next call to <a href="glib-File-Utilities.html#g-dir-read-name"><code class="function">g_dir_read_name()</code></a>will return the first entry again.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>dir</code></em> :</span></td><td> a <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a>* created by <a href="glib-File-Utilities.html#g-dir-open"><code class="function">g_dir_open()</code></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3054663"></a><h3><a name="g-dir-close"></a>g_dir_close ()</h3><a class="indexterm" name="id3054673"></a><pre class="programlisting">void g_dir_close (<a href="glib-File-Utilities.html#GDir">GDir</a> *dir);</pre><p>Closes the directory and deallocates all related resources.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>dir</code></em> :</span></td><td> a <a href="glib-File-Utilities.html#GDir"><span class="type">GDir</span></a>* created by <a href="glib-File-Utilities.html#g-dir-open"><code class="function">g_dir_open()</code></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3054741"></a><h3><a name="g-open"></a>g_open ()</h3><a class="indexterm" name="id3054751"></a><pre class="programlisting">int g_open (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename, int flags, int mode);</pre><p>A wrapper for the POSIX <code class="function">open()</code> function. The <code class="function">open()</code> function isused to convert a pathname into a file descriptor. Note that onPOSIX systems file descriptors are implemented by the operatingsystem. On Windows, it's the C library that implements <code class="function">open()</code> andfile descriptors. The actual Windows API for opening files issomething different.</p><p>See the C library manual for more details about <code class="function">open()</code>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>filename</code></em> :</span></td><td> a pathname in the GLib file name encoding</td></tr><tr><td><span class="term"><em class="parameter"><code>flags</code></em> :</span></td><td> as in <code class="function">open()</code></td></tr><tr><td><span class="term"><em class="parameter"><code>mode</code></em> :</span></td><td> as in <code class="function">open()</code></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> a new file descriptor, or -1 if an error occurred. Thereturn value can be used exactly like the return value from <code class="function">open()</code>.</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3054939"></a><h3><a name="g-rename"></a>g_rename ()</h3><a class="indexterm" name="id3054950"></a><pre class="programlisting">int g_rename (const <a href="glib-Basic-Types.html#gchar">gchar</a> *oldfilename, const <a href="glib-Basic-Types.html#gchar">gchar</a> *newfilename);</pre><p>A wrapper for the POSIX <code class="function">rename()</code> function. The <code class="function">rename()</code> function renames a file, moving it between directories if required.</p><p>See your C library manual for more details about how <code class="function">rename()</code> workson your system. Note in particular that on Windows, it is ingeneral not possible to rename a file if a file with the new namealready exists. Also it is not possible in general to rename anopen file.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>oldfilename</code></em> :</span></td><td> a pathname in the GLib file name encoding</td></tr><tr><td><span class="term"><em class="parameter"><code>newfilename</code></em> :</span></td><td> a pathname in the GLib file name encoding</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></td><td> 0 if the renaming succeeded, -1 if an error occurred</td></tr></tbody></table></div><p>Since 2.6</p></div><hr><div class="refsect2" lang="en"><a name="id3055078"></a><h3><a name="g-mkdir"></a>g_mkdir ()</h3><a class="indexterm" name="id3055089"></a><pre class="programlisting">int g_mkdir (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename, int mode);</pre><p>A wrapper for the POSIX <code class="function">mkdir()</code> function. The <code class="function">mkdir()</code> function attempts to create a directory with the given name and permissions.</p><p>See the C library manual for more details about <code class="function">mkdir()</code>.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><em class="parameter"><code>filename</code></em> :</span></td><td> a pathname in the GLib file name encoding
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -