⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glib-file-utilities.html

📁 glid编写实例
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<td>Input/output error; usually used for physical read    or write errors. i.e. the disk or other physical device hardware    is returning errors.</td></tr><tr><td><span class="term"><code class="literal">G_FILE_ERROR_PERM</code></span></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><span class="term"><code class="literal">G_FILE_ERROR_NOSYS</code></span></td><td>Function not implemented; this indicates that the    system is missing some functionality.</td></tr><tr><td><span class="term"><code class="literal">G_FILE_ERROR_FAILED</code></span></td><td>Does not correspond to a UNIX error code; this  is the standard "failed for unspecified reason" error code present in   all <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> error code enumerations. Returned if no specific  code applies.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3052767"></a><h3><a name="G-FILE-ERROR:CAPS"></a>G_FILE_ERROR</h3><a class="indexterm" name="id3052778"></a><pre class="programlisting">#define G_FILE_ERROR g_file_error_quark ()</pre><p>Error domain for file operations. Errors in this domain willbe from the <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> enumeration. See <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> for information on error domains.</p></div><hr><div class="refsect2" lang="en"><a name="id3052811"></a><h3><a name="GFileTest"></a>enum GFileTest</h3><a class="indexterm" name="id3052822"></a><pre class="programlisting">typedef enum{  G_FILE_TEST_IS_REGULAR    = 1 &lt;&lt; 0,  G_FILE_TEST_IS_SYMLINK    = 1 &lt;&lt; 1,  G_FILE_TEST_IS_DIR        = 1 &lt;&lt; 2,  G_FILE_TEST_IS_EXECUTABLE = 1 &lt;&lt; 3,  G_FILE_TEST_EXISTS        = 1 &lt;&lt; 4} GFileTest;</pre><p>A test to perform on a file using <a href="glib-File-Utilities.html#g-file-test"><code class="function">g_file_test()</code></a>.</p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><span class="term"><code class="literal">G_FILE_TEST_IS_REGULAR</code></span></td><td><code class="literal">TRUE</code> if the file is a regular file (not a symlink or directory)</td></tr><tr><td><span class="term"><code class="literal">G_FILE_TEST_IS_SYMLINK</code></span></td><td><code class="literal">TRUE</code> if the file is a symlink.</td></tr><tr><td><span class="term"><code class="literal">G_FILE_TEST_IS_DIR</code></span></td><td><code class="literal">TRUE</code> if the file is a directory.</td></tr><tr><td><span class="term"><code class="literal">G_FILE_TEST_IS_EXECUTABLE</code></span></td><td><code class="literal">TRUE</code> if the file is executable.</td></tr><tr><td><span class="term"><code class="literal">G_FILE_TEST_EXISTS</code></span></td><td><code class="literal">TRUE</code> if the file exists. It may or may not be a regular file.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3052956"></a><h3><a name="g-file-error-from-errno"></a>g_file_error_from_errno ()</h3><a class="indexterm" name="id3052967"></a><pre class="programlisting"><a href="glib-File-Utilities.html#GFileError">GFileError</a>  g_file_error_from_errno         (<a href="glib-Basic-Types.html#gint">gint</a> err_no);</pre><p>Gets a <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> constant based on the passed-in <em class="parameter"><code>errno</code></em>.For example, if you pass in <code class="literal">EEXIST</code> this function returns<span class="type">G_FILE_ERROR_EXIST</span>. Unlike <em class="parameter"><code>errno</code></em> values, you can portablyassume that all <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> values will exist.</p><p>Normally a <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> value goes into a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> returnedfrom a function that manipulates files. So you would use<a href="glib-File-Utilities.html#g-file-error-from-errno"><code class="function">g_file_error_from_errno()</code></a> when constructing a <a href="glib-Error-Reporting.html#GError"><span class="type">GError</span></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>err_no</code></em>&#160;:</span></td><td> an "errno" value</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> corresponding to the given <em class="parameter"><code>errno</code></em></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3053127"></a><h3><a name="g-file-get-contents"></a>g_file_get_contents ()</h3><a class="indexterm" name="id3053138"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_file_get_contents             (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **contents,                                             <a href="glib-Basic-Types.html#gsize">gsize</a> *length,                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Reads an entire file into allocated memory, with good errorchecking. </p><p>If the call was successful, it returns <code class="literal">TRUE</code> and sets <em class="parameter"><code>contents</code></em> to the file contents and <em class="parameter"><code>length</code></em> to the length of the file contents in bytes. The string stored in <em class="parameter"><code>contents</code></em> will be nul-terminated, so for text files you can pass <code class="literal">NULL</code> for the <em class="parameter"><code>length</code></em> argument. If the call was not successful, it returns <code class="literal">FALSE</code> and sets <em class="parameter"><code>error</code></em>. The error domain is <a href="glib-File-Utilities.html#G-FILE-ERROR:CAPS"><span class="type">G_FILE_ERROR</span></a>. Possible error  codes are those in the <a href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> enumeration. In the error case, <em class="parameter"><code>contents</code></em> is set to <code class="literal">NULL</code> and <em class="parameter"><code>length</code></em> is set to zero.</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>&#160;:</span></td><td> name of a file to read contents from, in the GLib file name encoding</td></tr><tr><td><span class="term"><em class="parameter"><code>contents</code></em>&#160;:</span></td><td> location to store an allocated string</td></tr><tr><td><span class="term"><em class="parameter"><code>length</code></em>&#160;:</span></td><td> location to store length in bytes of the contents, or <code class="literal">NULL</code></td></tr><tr><td><span class="term"><em class="parameter"><code>error</code></em>&#160;:</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></td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> <code class="literal">TRUE</code> on success, <code class="literal">FALSE</code> if an error occurred</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3053388"></a><h3><a name="g-file-test"></a>g_file_test ()</h3><a class="indexterm" name="id3053398"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gboolean">gboolean</a>    g_file_test                     (const <a href="glib-Basic-Types.html#gchar">gchar</a> *filename,                                             <a href="glib-File-Utilities.html#GFileTest">GFileTest</a> test);</pre><p>Returns <code class="literal">TRUE</code> if any of the tests in the bitfield <em class="parameter"><code>test</code></em> are<code class="literal">TRUE</code>. For example, <code class="literal">(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)</code> will return <code class="literal">TRUE</code> if the file exists; the check whether it's a directory doesn't matter since the existence test is <code class="literal">TRUE</code>. With the current set of available tests, there's no pointpassing in more than one test at a time.</p><p>Apart from <code class="literal">G_FILE_TEST_IS_SYMLINK</code> all tests follow symbolic links,so for a symbolic link to a regular file <a href="glib-File-Utilities.html#g-file-test"><code class="function">g_file_test()</code></a> will return<code class="literal">TRUE</code> for both <code class="literal">G_FILE_TEST_IS_SYMLINK</code> and <code class="literal">G_FILE_TEST_IS_REGULAR</code>.</p><p>Note, that for a dangling symbolic link <a href="glib-File-Utilities.html#g-file-test"><code class="function">g_file_test()</code></a> will return<code class="literal">TRUE</code> for <code class="literal">G_FILE_TEST_IS_SYMLINK</code> and <code class="literal">FALSE</code> for all other flags.</p><p>You should never use <a href="glib-File-Utilities.html#g-file-test"><code class="function">g_file_test()</code></a> to test whether it is safeto perform an operation, because there is always the possibilityof the condition changing before you actually perform the operation.For example, you might think you could use <code class="literal">G_FILE_TEST_IS_SYMLINK</code>to know whether it is is safe to write to a file without beingtricked into writing into a different location. It doesn't work!</p><p></p><div class="informalexample"><pre class="programlisting">/* DON'T DO THIS */ if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK)) {   fd = g_open (filename, O_WRONLY);   /* write to fd */ }</pre></div><p></p><p>Another thing to note is that <code class="literal">G_FILE_TEST_EXISTS</code> and<code class="literal">G_FILE_TEST_IS_EXECUTABLE</code> are implemented using the <code class="function">access()</code>system call. This usually doesn't matter, but if your programis setuid or setgid it means that these tests will give youthe answer for the real user ID and group ID, rather than theeffective user ID and group ID.</p><p>On Windows, there are no symlinks, so testing for<code class="literal">G_FILE_TEST_IS_SYMLINK</code> will always return <code class="literal">FALSE</code>. Testing for<code class="literal">G_FILE_TEST_IS_EXECUTABLE</code> will just check that the file exists andits name indicates that it is executable, checking for well-knownextensions and those listed in the <code class="literal">PATHEXT</code> environment variable.</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>&#160;:</span></td><td> a filename to test in the GLib file name encoding</td></tr><tr><td><span class="term"><em class="parameter"><code>test</code></em>&#160;:</span></td><td> bitfield of <a href="glib-File-Utilities.html#GFileTest"><span class="type">GFileTest</span></a> flags</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> whether a test was <code class="literal">TRUE</code></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3053712"></a><h3><a name="g-mkstemp"></a>g_mkstemp ()</h3><a class="indexterm" name="id3053723"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a>        g_mkstemp                       (<a href="glib-Basic-Types.html#gchar">gchar</a> *tmpl);</pre><p>Opens a temporary file. See the <code class="function">mkstemp()</code> documentationon most UNIX-like systems. This is a portability wrapper, which simply calls <code class="function">mkstemp()</code> on systems that have it, and implements it in GLib otherwise.</p><p>The parameter is a string that should match the rules for<code class="function">mkstemp()</code>, i.e. end in "XXXXXX". The X string will be modified to form the name of a file that didn't exist.The string should be in the GLib file name encoding. Most importantly, on Windows it should be in 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>tmpl</code></em>&#160;:</span></td><td> template filename</td></tr><tr><td><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></td><td> A file handle (as from <code class="function">open()</code>) to the fileopened for reading and writing. The file is opened in binary modeon platforms where there is a difference. The file handle should beclosed with <code class="function">close()</code>. In case of errors, -1 is returned.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3053850"></a><h3><a name="g-file-open-tmp"></a>g_file_open_tmp ()</h3><a class="indexterm" name="id3053860"></a><pre class="programlisting"><a href="glib-Basic-Types.html#gint">gint</a>        g_file_open_tmp                 (const <a href="glib-Basic-Types.html#gchar">gchar</a> *tmpl,                                             <a href="glib-Basic-Types.html#gchar">gchar</a> **name_used,                                             <a href="glib-Error-Reporting.html#GError">GError</a> **error);</pre><p>Opens a file for writing in the preferred directory for temporaryfiles (as returned by <a href="glib-Miscellaneous-Utility-Functions.html#g-get-tmp-dir"><code class="function">g_get_tmp_dir()</code></a>). </p><p><em class="parameter"><code>tmpl</code></em> should be a string in the GLib file name encoding ending withsix 'X' characters, as the parameter to <a href="glib-File-Utilities.html#g-mkstemp"><code class="function">g_mkstemp()</code></a> (or <code class="function">mkstemp()</code>).However, unlike these functions, the template should only be abasename, no directory components are allowed. If template is<code class="literal">NULL</code>, a default template is used.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -