~ubuntu-branches/ubuntu/trusty/guile-gnome-platform/trusty-proposed

« back to all changes in this revision

Viewing changes to glib/doc/glib/defuns-fileutils.xml.texi

  • Committer: Bazaar Package Importer
  • Author(s): Andreas Rottmann
  • Date: 2009-03-01 22:51:48 UTC
  • mfrom: (1.1.2 upstream) (3.2.1 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090301225148-5cubt342wiv8jpmf
Tags: 2.16.1-1
* New upstream release.
* Upstream bumped API, hence all package names changed from
  guile-gnome0-* to guile-gnome2-*.
* Standards-Version 3.8.0 (no changes).
* Remove unused guile-gnome2-cairo.install file.
* Added ${misc:Depends} to all packages.
* Do not build-depend on a -1 revision of the g-wrap packages.
* Add a proper "Copyright YEARS AUTHORS" line to debian/copyright.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 
23
23
@end deffn
24
24
 
25
 
@deffn Function g-file-get-contents  (filename@tie{}@code{mchars}) @result{}@tie{} (ret@tie{}@code{bool}) (contents@tie{}@code{mchars}) (length@tie{}@code{size_t})
26
 
Reads an entire file into allocated memory, with good error checking.
27
 
 
28
 
If the call was successful, it returns @samp{@code{#t}} and sets @var{contents}
29
 
to the file contents and @var{length} to the length of the file contents in
30
 
bytes. The string stored in @var{contents} will be nul-terminated, so for text
31
 
files you can pass @samp{@code{#f}} for the @var{length} argument. If the call
32
 
was not successful, it returns @samp{@code{#f}} and sets @var{error}. The error
33
 
domain is @code{<g-file-error>}. Possible error codes are those in the
34
 
@code{<g-file-error>} enumeration. In the error case, @var{contents} is set to
35
 
@samp{@code{#f}} and @var{length} is set to zero.
36
 
 
37
 
@table @var
38
 
@item filename
39
 
name of a file to read contents from, in the GLib file name encoding
40
 
 
41
 
@item contents
42
 
location to store an allocated string
43
 
 
44
 
@item length
45
 
location to store length in bytes of the contents, or @samp{@code{#f}}
46
 
 
47
 
@item error
48
 
return location for a @code{<g-error>}, or @samp{@code{#f}}
49
 
 
50
 
@item ret
51
 
@samp{@code{#t}} on success, @samp{@code{#f}} if an error occurred
52
 
 
53
 
@end table
54
 
 
55
 
@end deffn
56
 
 
57
 
@deffn Function g-file-test  (filename@tie{}@code{mchars}) (test@tie{}@code{<g-file-test>}) @result{}@tie{} (ret@tie{}@code{bool})
58
 
Returns @samp{@code{#t}} if any of the tests in the bitfield @var{test} are
59
 
@samp{@code{#t}}. For example, @samp{(G_FILE_TEST_EXISTS | G_FILE_TEST_IS_DIR)}
60
 
will return @samp{@code{#t}} if the file exists; the check whether it's a
61
 
directory doesn't matter since the existence test is @samp{@code{#t}}. With the
62
 
current set of available tests, there's no point passing in more than one test
63
 
at a time.
64
 
 
65
 
Apart from @samp{G_FILE_TEST_IS_SYMLINK} all tests follow symbolic links, so for
66
 
a symbolic link to a regular file @code{g-file-test} will return
67
 
@samp{@code{#t}} for both @samp{G_FILE_TEST_IS_SYMLINK} and
68
 
@samp{G_FILE_TEST_IS_REGULAR}.
69
 
 
70
 
Note, that for a dangling symbolic link @code{g-file-test} will return
71
 
@samp{@code{#t}} for @samp{G_FILE_TEST_IS_SYMLINK} and @samp{@code{#f}} for all
72
 
other flags.
73
 
 
74
 
You should never use @code{g-file-test} to test whether it is safe to perform an
75
 
operation, because there is always the possibility of the condition changing
76
 
before you actually perform the operation. For example, you might think you
77
 
could use @samp{G_FILE_TEST_IS_SYMLINK} to know whether it is is safe to write
78
 
to a file without being tricked into writing into a different location. It
79
 
doesn't work!
80
 
 
81
 
@example 
82
 
 
83
 
/&#x002A; DON'T DO THIS &#x002A;/
84
 
 if (!g_file_test (filename, G_FILE_TEST_IS_SYMLINK)) @{
85
 
   fd = g_open (filename, O_WRONLY);
86
 
   /&#x002A; write to fd &#x002A;/
87
 
 @}
88
 
@end example
89
 
 
90
 
Another thing to note is that @samp{G_FILE_TEST_EXISTS} and
91
 
@samp{G_FILE_TEST_IS_EXECUTABLE} are implemented using the @code{access} system
92
 
call. This usually doesn't matter, but if your program is setuid or setgid it
93
 
means that these tests will give you the answer for the real user ID and group
94
 
ID, rather than the effective user ID and group ID.
95
 
 
96
 
On Windows, there are no symlinks, so testing for @samp{G_FILE_TEST_IS_SYMLINK}
97
 
will always return @samp{@code{#f}}. Testing for
98
 
@samp{G_FILE_TEST_IS_EXECUTABLE} will just check that the file exists and its
99
 
name indicates that it is executable, checking for well-known extensions and
100
 
those listed in the @samp{PATHEXT} environment variable.
101
 
 
102
 
@table @var
103
 
@item filename
104
 
a filename to test in the GLib file name encoding
105
 
 
106
 
@item test
107
 
bitfield of @code{<g-file-test>} flags
108
 
 
109
 
@item ret
110
 
whether a test was @samp{@code{#t}}
111
 
 
112
 
@end table
113
 
 
114
 
@end deffn
115
 
 
116
 
@deffn Function g-mkstemp  (tmpl@tie{}@code{mchars}) @result{}@tie{} (ret@tie{}@code{int})
117
 
Opens a temporary file. See the @code{mkstemp} documentation on most UNIX-like
118
 
systems.
119
 
 
120
 
The parameter is a string that should follow the rules for @code{mkstemp}
121
 
templates, i.e. contain the string "XXXXXX". @code{g-mkstemp} is slightly more
122
 
flexible than @code{mkstemp} in that the sequence does not have to occur at the
123
 
very end of the template. The X string will be modified to form the name of a
124
 
file that didn't exist. The string should be in the GLib file name encoding.
125
 
Most importantly, on Windows it should be in UTF-8.
126
 
 
127
 
@table @var
128
 
@item tmpl
129
 
template filename
130
 
 
131
 
@item ret
132
 
A file handle (as from @code{open}) to the file opened for reading and writing.
133
 
The file is opened in binary mode on platforms where there is a difference. The
134
 
file handle should be closed with @code{close}. In case of errors, -1 is
135
 
returned.
136
 
 
137
 
@end table
138
 
 
139
 
@end deffn
140
 
 
141
 
@deffn Function g-file-open-tmp  (tmpl@tie{}@code{mchars}) @result{}@tie{} (ret@tie{}@code{int}) (name_used@tie{}@code{mchars})
142
 
Opens a file for writing in the preferred directory for temporary files (as
143
 
returned by @code{g-get-tmp-dir}).
144
 
 
145
 
@var{tmpl} should be a string in the GLib file name encoding containing a
146
 
sequence of six 'X' characters, as the parameter to @code{g-mkstemp}. However,
147
 
unlike these functions, the template should only be a basename, no directory
148
 
components are allowed. If template is @samp{@code{#f}}, a default template is
149
 
used.
150
 
 
151
 
Note that in contrast to @code{g-mkstemp} (and @code{mkstemp}) @var{tmpl} is not
152
 
modified, and might thus be a read-only literal string.
153
 
 
154
 
The actual name used is returned in @var{name-used} if non-@samp{@code{#f}}.
155
 
This string should be freed with @code{g-free} when not needed any longer. The
156
 
returned name is in the GLib file name encoding.
157
 
 
158
 
@table @var
159
 
@item tmpl
160
 
Template for file name, as in @code{g-mkstemp}, basename only, or
161
 
@samp{@code{#f}}, to a default template
162
 
 
163
 
@item name-used
164
 
location to store actual name used
165
 
 
166
 
@item error
167
 
return location for a @code{<g-error>}
168
 
 
169
 
@item ret
170
 
A file handle (as from @code{open}) to the file opened for reading and writing.
171
 
The file is opened in binary mode on platforms where there is a difference. The
172
 
file handle should be closed with @code{close}. In case of errors, -1 is
173
 
returned and @var{error} will be set.
174
 
 
175
 
@end table
176
 
 
177
 
@end deffn
178
 
 
179
 
@deffn Function g-file-read-link  (filename@tie{}@code{mchars}) @result{}@tie{} (ret@tie{}@code{mchars})
180
 
Reads the contents of the symbolic link @var{filename} like the POSIX
181
 
@code{readlink} function. The returned string is in the encoding used for
182
 
filenames. Use @code{g-filename-to-utf8} to convert it to UTF-8.
183
 
 
184
 
@table @var
185
 
@item filename
186
 
the symbolic link
187
 
 
188
 
@item error
189
 
return location for a @code{<g-error>}
190
 
 
191
 
@item ret
192
 
A newly allocated string with the contents of the symbolic link, or
193
 
@samp{@code{#f}} if an error occurred.
194
 
 
195
 
@end table
196
 
 
197
 
Since 2.4
198
 
 
199
 
@end deffn
200
 
 
201
25
 
202
26
@c %end of fragment