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

📄 glib-file-utilities.html

📁 最新gtk中文资料集
💻 HTML
📖 第 1 页 / 共 5 页
字号:
<td> an "errno" value</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> <a class="link" 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="id3109826"></a><h3><a name="g-file-get-contents"></a>g_file_get_contents ()</h3><a class="indexterm" name="id3109836"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            g_file_get_contents                 (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);</pre><p>Reads an entire file into allocated memory, with good errorchecking. </p><p>If the call was successful, it returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> 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 <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> for the <em class="parameter"><code>length</code></em> argument. If the call was not successful, it returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> and sets <em class="parameter"><code>error</code></em>. The error domain is <a class="link" 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 class="link" 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 <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> 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><p><span class="term"><em class="parameter"><code>filename</code></em>&#160;:</span></p></td><td> name of a file to read contents from, in the GLib file name encoding</td></tr><tr><td><p><span class="term"><em class="parameter"><code>contents</code></em>&#160;:</span></p></td><td> location to store an allocated string</td></tr><tr><td><p><span class="term"><em class="parameter"><code>length</code></em>&#160;:</span></p></td><td> location to store length in bytes of the contents, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></p></td><td> return location for a <a class="link" href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error occurred</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3110082"></a><h3><a name="g-file-set-contents"></a>g_file_set_contents ()</h3><a class="indexterm" name="id3110094"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            g_file_set_contents                 (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);</pre><p>Writes all of <em class="parameter"><code>contents</code></em> to a file named <em class="parameter"><code>filename</code></em>, with good error checking.If a file called <em class="parameter"><code>filename</code></em> already exists it will be overwritten.</p><p>This write is atomic in the sense that it is first written to a temporaryfile which is then renamed to the final name. Notes:</p><div class="itemizedlist"><ul type="disc"><li>   On Unix, if <em class="parameter"><code>filename</code></em> already exists hard links to <em class="parameter"><code>filename</code></em> will break.   Also since the file is recreated, existing permissions, access control   lists, metadata etc. may be lost. If <em class="parameter"><code>filename</code></em> is a symbolic link,   the link itself will be replaced, not the linked file.</li><li>  On Windows renaming a file will not remove an existing file with the  new name, so on Windows there is a race condition between the existing  file being removed and the temporary file being renamed.</li><li>  On Windows there is no way to remove a file that is open to some  process, or mapped into memory. Thus, this function will fail if  <em class="parameter"><code>filename</code></em> already exists and is open.</li></ul></div><p></p><p>If the call was sucessful, it returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. If the call was not successful,it returns <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> and sets <em class="parameter"><code>error</code></em>. The error domain is <a class="link" 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 class="link" href="glib-File-Utilities.html#GFileError"><span class="type">GFileError</span></a> enumeration.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>filename</code></em>&#160;:</span></p></td><td> name of a file to write <em class="parameter"><code>contents</code></em> to, in the GLib file name  encoding</td></tr><tr><td><p><span class="term"><em class="parameter"><code>contents</code></em>&#160;:</span></p></td><td> string to write to the file</td></tr><tr><td><p><span class="term"><em class="parameter"><code>length</code></em>&#160;:</span></p></td><td> length of <em class="parameter"><code>contents</code></em>, or -1 if <em class="parameter"><code>contents</code></em> is a nul-terminated string</td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em>&#160;:</span></p></td><td> return location for a <a class="link" href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a>, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error occurred</td></tr></tbody></table></div><p class="since">Since  2.8</p></div><hr><div class="refsect2" lang="en"><a name="id3110368"></a><h3><a name="g-file-test"></a>g_file_test ()</h3><a class="indexterm" name="id3110378"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a>            g_file_test                         (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);</pre><p>Returns <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if any of the tests in the bitfield <em class="parameter"><code>test</code></em> are<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. For example, <code class="literal">(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)</code> will return <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if the file exists; the check whether it's a directory doesn't matter since the existence test is <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. With the current set of available tests, there's no pointpassing in more than one test at a time.</p><p>Apart from <a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-SYMLINK:CAPS"><code class="literal">G_FILE_TEST_IS_SYMLINK</code></a> all tests follow symbolic links,so for a symbolic link to a regular file <a class="link" href="glib-File-Utilities.html#g-file-test"><code class="function">g_file_test()</code></a> will return<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for both <a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-SYMLINK:CAPS"><code class="literal">G_FILE_TEST_IS_SYMLINK</code></a> and <a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-REGULAR:CAPS"><code class="literal">G_FILE_TEST_IS_REGULAR</code></a>.</p><p>Note, that for a dangling symbolic link <a class="link" href="glib-File-Utilities.html#g-file-test"><code class="function">g_file_test()</code></a> will return<a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> for <a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-SYMLINK:CAPS"><code class="literal">G_FILE_TEST_IS_SYMLINK</code></a> and <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> for all other flags.</p><p>You should never use <a class="link" 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 <a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-SYMLINK:CAPS"><code class="literal">G_FILE_TEST_IS_SYMLINK</code></a>to know whether it is safe to write to a file without beingtricked into writing into a different location. It doesn't work!</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 <a class="link" href="glib-File-Utilities.html#G-FILE-TEST-EXISTS:CAPS"><code class="literal">G_FILE_TEST_EXISTS</code></a> and<a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-EXECUTABLE:CAPS"><code class="literal">G_FILE_TEST_IS_EXECUTABLE</code></a> 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<a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-SYMLINK:CAPS"><code class="literal">G_FILE_TEST_IS_SYMLINK</code></a> will always return <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a>. Testing for<a class="link" href="glib-File-Utilities.html#G-FILE-TEST-IS-EXECUTABLE:CAPS"><code class="literal">G_FILE_TEST_IS_EXECUTABLE</code></a> 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><p><span class="term"><em class="parameter"><code>filename</code></em>&#160;:</span></p></td><td> a filename to test in the GLib file name encoding</td></tr><tr><td><p><span class="term"><em class="parameter"><code>test</code></em>&#160;:</span></p></td><td> bitfield of <a class="link" href="glib-File-Utilities.html#GFileTest"><span class="type">GFileTest</span></a> flags</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span>&#160;:</span></p></td><td> whether a test was <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a></td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3110730"></a><h3><a name="g-mkstemp"></a>g_mkstemp ()</h3><a class="indexterm" name="id3110741"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gint">gint</a>                g_mkstemp                           (<a class="link" 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. </p><p>The parameter is a string that should follow the rules for<code class="function">mkstemp()</code> templates, i.e. contain the string "XXXXXX". <a class="link" href="glib-File-Utilities.html#g-mkstemp"><code class="function">g_mkstemp()</code></a> is slightly more flexible than <code class="function">mkstemp()</code>in that the sequence does not have to occur at the very end of the 

⌨️ 快捷键说明

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