?? glib-file-utilities.html
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=US-ASCII"><title>File Utilities</title><meta name="generator" content="DocBook XSL Stylesheets V1.73.2"><link rel="start" href="index.html" title="GLib Reference Manual"><link rel="up" href="glib-utilities.html" title="GLib Utilities"><link rel="prev" href="glib-Spawning-Processes.html" title="Spawning Processes"><link rel="next" href="glib-URI-Functions.html" title="URI Functions"><meta name="generator" content="GTK-Doc V1.9 (XML mode)"><link rel="stylesheet" href="style.css" type="text/css"><link rel="chapter" href="glib.html" title="GLib Overview"><link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals"><link rel="chapter" href="glib-core.html" title="GLib Core Application Support"><link rel="chapter" href="glib-utilities.html" title="GLib Utilities"><link rel="chapter" href="glib-data-types.html" title="GLib Data Types"><link rel="chapter" href="tools.html" title="GLib Tools"><link rel="index" href="ix01.html" title="Index"><link rel="index" href="ix02.html" title="Index of deprecated symbols"><link rel="index" href="ix03.html" title="Index of new symbols in 2.2"><link rel="index" href="ix04.html" title="Index of new symbols in 2.4"><link rel="index" href="ix05.html" title="Index of new symbols in 2.6"><link rel="index" href="ix06.html" title="Index of new symbols in 2.8"><link rel="index" href="ix07.html" title="Index of new symbols in 2.10"><link rel="index" href="ix08.html" title="Index of new symbols in 2.12"><link rel="index" href="ix09.html" title="Index of new symbols in 2.14"><link rel="index" href="ix10.html" title="Index of new symbols in 2.16"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle"><td><a accesskey="p" href="glib-Spawning-Processes.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td><td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td><td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td><th width="100%" align="center">GLib Reference Manual</th><td><a accesskey="n" href="glib-URI-Functions.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td></tr><tr><td colspan="5" class="shortcuts"><nobr><a href="#id3107017" class="shortcut">Top</a>  |  <a href="#id2807972" class="shortcut">Description</a></nobr></td></tr></table><div class="refentry" lang="en"><a name="glib-File-Utilities"></a><div class="titlepage"></div><div class="refnamediv"><table width="100%"><tr><td valign="top"><h2><a name="id3107017"></a><span class="refentrytitle">File Utilities</span></h2><p>File Utilities — various file-related functions</p></td><td valign="top" align="right"></td></tr></table></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">#include <glib.h>#include <glib/gstdio.h>enum <a class="link" href="glib-File-Utilities.html#GFileError">GFileError</a>;#define <a class="link" href="glib-File-Utilities.html#G-FILE-ERROR:CAPS">G_FILE_ERROR</a>enum <a class="link" href="glib-File-Utilities.html#GFileTest">GFileTest</a>;<a class="link" href="glib-File-Utilities.html#GFileError">GFileError</a> <a class="link" href="glib-File-Utilities.html#g-file-error-from-errno">g_file_error_from_errno</a> (<a class="link" href="glib-Basic-Types.html#gint">gint</a> err_no);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-File-Utilities.html#g-file-get-contents">g_file_get_contents</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **contents, <a class="link" href="glib-Basic-Types.html#gsize">gsize</a> *length, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-File-Utilities.html#g-file-set-contents">g_file_set_contents</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *contents, <a class="link" href="glib-Basic-Types.html#gssize">gssize</a> length, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> <a class="link" href="glib-File-Utilities.html#g-file-test">g_file_test</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, <a class="link" href="glib-File-Utilities.html#GFileTest">GFileTest</a> test);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-File-Utilities.html#g-mkstemp">g_mkstemp</a> (<a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *tmpl);<a class="link" href="glib-Basic-Types.html#gint">gint</a> <a class="link" href="glib-File-Utilities.html#g-file-open-tmp">g_file_open_tmp</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *tmpl, <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **name_used, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-File-Utilities.html#g-file-read-link">g_file_read_link</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);int <a class="link" href="glib-File-Utilities.html#g-mkdir-with-parents">g_mkdir_with_parents</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *pathname, int mode); <a class="link" href="glib-File-Utilities.html#GDir">GDir</a>;<a class="link" href="glib-File-Utilities.html#GDir">GDir</a>* <a class="link" href="glib-File-Utilities.html#g-dir-open">g_dir_open</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *path, <a class="link" href="glib-Basic-Types.html#guint">guint</a> flags, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-File-Utilities.html#g-dir-read-name">g_dir_read_name</a> (<a class="link" href="glib-File-Utilities.html#GDir">GDir</a> *dir);void <a class="link" href="glib-File-Utilities.html#g-dir-rewind">g_dir_rewind</a> (<a class="link" href="glib-File-Utilities.html#GDir">GDir</a> *dir);void <a class="link" href="glib-File-Utilities.html#g-dir-close">g_dir_close</a> (<a class="link" href="glib-File-Utilities.html#GDir">GDir</a> *dir); <a class="link" href="glib-File-Utilities.html#GMappedFile">GMappedFile</a>;<a class="link" href="glib-File-Utilities.html#GMappedFile">GMappedFile</a>* <a class="link" href="glib-File-Utilities.html#g-mapped-file-new">g_mapped_file_new</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, <a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> writable, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error);void <a class="link" href="glib-File-Utilities.html#g-mapped-file-free">g_mapped_file_free</a> (<a class="link" href="glib-File-Utilities.html#GMappedFile">GMappedFile</a> *file);<a class="link" href="glib-Basic-Types.html#gsize">gsize</a> <a class="link" href="glib-File-Utilities.html#g-mapped-file-get-length">g_mapped_file_get_length</a> (<a class="link" href="glib-File-Utilities.html#GMappedFile">GMappedFile</a> *file);<a class="link" href="glib-Basic-Types.html#gchar">gchar</a>* <a class="link" href="glib-File-Utilities.html#g-mapped-file-get-contents">g_mapped_file_get_contents</a> (<a class="link" href="glib-File-Utilities.html#GMappedFile">GMappedFile</a> *file);int <a class="link" href="glib-File-Utilities.html#g-open">g_open</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, int flags, int mode);int <a class="link" href="glib-File-Utilities.html#g-rename">g_rename</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *oldfilename, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *newfilename);int <a class="link" href="glib-File-Utilities.html#g-mkdir">g_mkdir</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, int mode);int <a class="link" href="glib-File-Utilities.html#g-stat">g_stat</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, struct stat *buf);int <a class="link" href="glib-File-Utilities.html#g-lstat">g_lstat</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, struct stat *buf);int <a class="link" href="glib-File-Utilities.html#g-unlink">g_unlink</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename);int <a class="link" href="glib-File-Utilities.html#g-remove">g_remove</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename);int <a class="link" href="glib-File-Utilities.html#g-rmdir">g_rmdir</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename);FILE* <a class="link" href="glib-File-Utilities.html#g-fopen">g_fopen</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *mode);FILE* <a class="link" href="glib-File-Utilities.html#g-freopen">g_freopen</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *mode, FILE *stream);int <a class="link" href="glib-File-Utilities.html#g-chmod">g_chmod</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, int mode);int <a class="link" href="glib-File-Utilities.html#g-access">g_access</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, int mode);int <a class="link" href="glib-File-Utilities.html#g-creat">g_creat</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *filename, int mode);int <a class="link" href="glib-File-Utilities.html#g-chdir">g_chdir</a> (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *path);</pre></div><div class="refsect1" lang="en"><a name="id2807972"></a><h2>Description</h2><p>There is a group of functions which wrap the common POSIX functions dealing with filenames (<a class="link" href="glib-File-Utilities.html#g-open"><code class="function">g_open()</code></a>, <a class="link" href="glib-File-Utilities.html#g-rename"><code class="function">g_rename()</code></a>, <a class="link" href="glib-File-Utilities.html#g-mkdir"><code class="function">g_mkdir()</code></a>, <a class="link" href="glib-File-Utilities.html#g-stat"><code class="function">g_stat()</code></a>, <a class="link" href="glib-File-Utilities.html#g-unlink"><code class="function">g_unlink()</code></a>, <a class="link" href="glib-File-Utilities.html#g-remove"><code class="function">g_remove()</code></a>, <a class="link" href="glib-File-Utilities.html#g-fopen"><code class="function">g_fopen()</code></a>, <a class="link" href="glib-File-Utilities.html#g-freopen"><code class="function">g_freopen()</code></a>). The point of these wrappers is to make it possible to handle file names with any Unicode characters in them on Windows without having to use ifdefs and the wide character API in the application code.</p><p>The pathname argument should be in the GLib file name encoding. OnPOSIX this is the actual on-disk encoding which might correspond tothe locale settings of the process (or the <code class="envar">G_FILENAME_ENCODING</code> environment variable), or not.</p><p>On Windows the GLib file name encoding is UTF-8. Note that theMicrosoft C library does not use UTF-8, but has separate APIs forcurrent system code page and wide characters (UTF-16). The GLibwrappers call the wide character API if present (on modern Windowssystems), otherwise convert to/from the system code page.</p><p>Another group of functions allows to open and read directoriesin the GLib file name encoding. These are <a class="link" href="glib-File-Utilities.html#g-dir-open"><code class="function">g_dir_open()</code></a>, <a class="link" href="glib-File-Utilities.html#g-dir-read-name"><code class="function">g_dir_read_name()</code></a>, <a class="link" href="glib-File-Utilities.html#g-dir-rewind"><code class="function">g_dir_rewind()</code></a>, <a class="link" href="glib-File-Utilities.html#g-dir-close"><code class="function">g_dir_close()</code></a>.</p></div><div class="refsect1" lang="en"><a name="id3108834"></a><h2>Details</h2><div class="refsect2" lang="en"><a name="id3108844"></a><h3><a name="GFileError"></a>enum GFileError</h3><a class="indexterm" name="id3108856"></a><pre class="programlisting">typedef enum{ G_FILE_ERROR_EXIST, G_FILE_ERROR_ISDIR, G_FILE_ERROR_ACCES, G_FILE_ERROR_NAMETOOLONG, G_FILE_ERROR_NOENT, G_FILE_ERROR_NOTDIR, G_FILE_ERROR_NXIO, G_FILE_ERROR_NODEV, G_FILE_ERROR_ROFS, G_FILE_ERROR_TXTBSY, G_FILE_ERROR_FAULT, G_FILE_ERROR_LOOP, G_FILE_ERROR_NOSPC, G_FILE_ERROR_NOMEM, G_FILE_ERROR_MFILE, G_FILE_ERROR_NFILE, G_FILE_ERROR_BADF, G_FILE_ERROR_INVAL, G_FILE_ERROR_PIPE, G_FILE_ERROR_AGAIN, G_FILE_ERROR_INTR, G_FILE_ERROR_IO, G_FILE_ERROR_PERM, G_FILE_ERROR_NOSYS, G_FILE_ERROR_FAILED} GFileError;</pre><p>Values corresponding to <code class="literal">errno</code> codes returned from file operationson UNIX. Unlike <code class="literal">errno</code> codes, <a class="link" href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> values are available on all systems, even Windows. The exact meaning of each code depends on whatsort of file operation you were performing; the UNIX documentationgives more details. The following error code descriptions come from the GNU C Library manual, and are under the copyrightof that manual.</p><p>It's not very portable to make detailed assumptions about exactlywhich errors will be returned from a given operation. Some errorsdon't occur on some systems, etc., sometimes there are subtledifferences in when a system will report a given error, etc.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a name="G-FILE-ERROR-EXIST:CAPS"></a><code class="literal">G_FILE_ERROR_EXIST</code></span></p></td><td>Operation not permitted; only the owner of the file (or other resource) or processes with special privileges can perform the operation.</td></tr><tr><td><p><span class="term"><a name="G-FILE-ERROR-ISDIR:CAPS"></a><code class="literal">G_FILE_ERROR_ISDIR</code></span></p></td><td>File is a directory; you cannot open a directory for writing, or create or remove hard links to it.</td></tr><tr><td><p><span class="term"><a name="G-FILE-ERROR-ACCES:CAPS"></a><code class="literal">G_FILE_ERROR_ACCES</code></span></p></td><td>Permission denied; the file permissions do not allow the attempted operation.</td></tr><tr><td><p><span class="term"><a name="G-FILE-ERROR-NAMETOOLONG:CAPS"></a><code class="literal">G_FILE_ERROR_NAMETOOLONG</code></span></p></td><td>Filename too long.</td></tr><tr><td><p><span class="term"><a name="G-FILE-ERROR-NOENT:CAPS"></a><code class="literal">G_FILE_ERROR_NOENT</code></span></p></td>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -