1// Package glib was automatically generated by github.com/bnema/puregotk DO NOT EDIT
2package glib
3
4import (
5 "structs"
6 "unsafe"
7
8 "github.com/ebitengine/purego"
9
10 "github.com/bnema/puregotk/pkg/core"
11)
12
13// A type corresponding to the appropriate struct type for the stat()
14// system call, depending on the platform and/or compiler being used.
15//
16// See g_stat() for more information.
17type StatBuf struct {
18 _ structs.HostLayout
19}
20
21func (x *StatBuf) GoPointer() uintptr {
22 return uintptr(unsafe.Pointer(x))
23}
24
25var xAccess func(string, int) int
26
27// A wrapper for the POSIX access() function. This function is used to
28// test a pathname for one or several of read, write or execute
29// permissions, or just existence.
30//
31// On Windows, the file protection mechanism is not at all POSIX-like,
32// and the underlying function in the C library only checks the
33// FAT-style READONLY attribute, and does not look at the ACL of a
34// file at all. This function is this in practise almost useless on
35// Windows. Software that needs to handle file permissions on Windows
36// more exactly should use the Win32 API.
37//
38// See your C library manual for more details about access().
39func Access(FilenameVar string, ModeVar int) int {
40
41 cret := xAccess(FilenameVar, ModeVar)
42
43 return cret
44}
45
46var xChdir func(string) int
47
48// A wrapper for the POSIX chdir() function. The function changes the
49// current directory of the process to @path.
50//
51// See your C library manual for more details about chdir().
52func Chdir(PathVar string) int {
53
54 cret := xChdir(PathVar)
55
56 return cret
57}
58
59var xChmod func(string, int) int
60
61// A wrapper for the POSIX chmod() function. The chmod() function is
62// used to set the permissions of a file system object.
63//
64// On Windows the file protection mechanism is not at all POSIX-like,
65// and the underlying chmod() function in the C library just sets or
66// clears the FAT-style READONLY attribute. It does not touch any
67// ACL. Software that needs to manage file permissions on Windows
68// exactly should use the Win32 API.
69//
70// See your C library manual for more details about chmod().
71func Chmod(FilenameVar string, ModeVar int) int {
72
73 cret := xChmod(FilenameVar, ModeVar)
74
75 return cret
76}
77
78var xClose func(int, **Error) bool
79
80// This wraps the close() call. In case of error, %errno will be
81// preserved, but the error will also be stored as a #GError in @error.
82// In case of success, %errno is undefined.
83//
84// Besides using #GError, there is another major reason to prefer this
85// function over the call provided by the system; on Unix, it will
86// attempt to correctly handle %EINTR, which has platform-specific
87// semantics.
88//
89// It is a bug to call this function with an invalid file descriptor.
90//
91// On POSIX platforms since GLib 2.76, this function is async-signal safe
92// if (and only if) @error is %NULL and @fd is a valid open file descriptor.
93// This makes it safe to call from a signal handler or a #GSpawnChildSetupFunc
94// under those conditions.
95// See [`signal(7)`](man:signal(7)) and
96// [`signal-safety(7)`](man:signal-safety(7)) for more details.
97func Close(FdVar int) (bool, error) {
98 var cerr *Error
99
100 cret := xClose(FdVar, &cerr)
101
102 if cerr == nil {
103 return cret, nil
104 }
105 return cret, cerr
106
107}
108
109var xCreat func(string, int) int
110
111// A wrapper for the POSIX creat() function. The creat() function is
112// used to convert a pathname into a file descriptor, creating a file
113// if necessary.
114//
115// On POSIX systems file descriptors are implemented by the operating
116// system. On Windows, it's the C library that implements creat() and
117// file descriptors. The actual Windows API for opening files is
118// different, see MSDN documentation for CreateFile(). The Win32 API
119// uses file handles, which are more randomish integers, not small
120// integers like file descriptors.
121//
122// Because file descriptors are specific to the C library on Windows,
123// the file descriptor returned by this function makes sense only to
124// functions in the same C library. Thus if the GLib-using code uses a
125// different C library than GLib does, the file descriptor returned by
126// this function cannot be passed to C library functions like write()
127// or read().
128//
129// See your C library manual for more details about creat().
130func Creat(FilenameVar string, ModeVar int) int {
131
132 cret := xCreat(FilenameVar, ModeVar)
133
134 return cret
135}
136
137var xFopen func(string, string) uintptr
138
139// A wrapper for the stdio `fopen()` function. The `fopen()` function
140// opens a file and associates a new stream with it.
141//
142// Because file descriptors are specific to the C library on Windows,
143// and a file descriptor is part of the `FILE` struct, the `FILE*` returned
144// by this function makes sense only to functions in the same C library.
145// Thus if the GLib-using code uses a different C library than GLib does,
146// the FILE* returned by this function cannot be passed to C library
147// functions like `fprintf()` or `fread()`.
148//
149// See your C library manual for more details about `fopen()`.
150//
151// As `close()` and `fclose()` are part of the C library, this implies that it is
152// currently impossible to close a file if the application C library and the C library
153// used by GLib are different. Convenience functions like g_file_set_contents_full()
154// avoid this problem.
155//
156// Since GLib 2.86, the `e` option is supported in @mode on all platforms. On
157// Unix platforms it will set `O_CLOEXEC` on the opened file descriptor. On
158// Windows platforms it will be converted to the
159// [`N` modifier](https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/fopen-wfopen?view=msvc-170).
160// It is recommended to set `e` unconditionally, unless you know the returned
161// file should be shared between this process and a new fork.
162func Fopen(FilenameVar string, ModeVar string) uintptr {
163
164 cret := xFopen(FilenameVar, ModeVar)
165
166 return cret
167}
168
169var xFreopen func(string, string, uintptr) uintptr
170
171// A wrapper for the POSIX freopen() function. The freopen() function
172// opens a file and associates it with an existing stream.
173//
174// See your C library manual for more details about freopen().
175//
176// Since GLib 2.86, the `e` option is supported in @mode on all platforms. See
177// the documentation for [func@GLib.fopen] for more details.
178func Freopen(FilenameVar string, ModeVar string, StreamVar uintptr) uintptr {
179
180 cret := xFreopen(FilenameVar, ModeVar, StreamVar)
181
182 return cret
183}
184
185var xFsync func(int) int
186
187// A wrapper for the POSIX `fsync()` function. On Windows, `_commit()` will be
188// used. On macOS, `fcntl(F_FULLFSYNC)` will be used.
189// The `fsync()` function is used to synchronize a file's in-core
190// state with that of the disk.
191//
192// This wrapper will handle retrying on `EINTR`.
193//
194// See the C library manual for more details about fsync().
195func Fsync(FdVar int) int {
196
197 cret := xFsync(FdVar)
198
199 return cret
200}
201
202var xLstat func(string, *StatBuf) int
203
204// A wrapper for the POSIX lstat() function. The lstat() function is
205// like stat() except that in the case of symbolic links, it returns
206// information about the symbolic link itself and not the file that it
207// refers to. If the system does not support symbolic links g_lstat()
208// is identical to g_stat().
209//
210// See your C library manual for more details about lstat().
211func Lstat(FilenameVar string, BufVar *StatBuf) int {
212
213 cret := xLstat(FilenameVar, BufVar)
214
215 return cret
216}
217
218var xMkdir func(string, int) int
219
220// A wrapper for the POSIX mkdir() function. The mkdir() function
221// attempts to create a directory with the given name and permissions.
222// The mode argument is ignored on Windows.
223//
224// See your C library manual for more details about mkdir().
225func Mkdir(FilenameVar string, ModeVar int) int {
226
227 cret := xMkdir(FilenameVar, ModeVar)
228
229 return cret
230}
231
232var xOpen func(string, int, int) int
233
234// A wrapper for the POSIX open() function. The open() function is
235// used to convert a pathname into a file descriptor.
236//
237// On POSIX systems file descriptors are implemented by the operating
238// system. On Windows, it's the C library that implements open() and
239// file descriptors. The actual Win32 API for opening files is quite
240// different, see MSDN documentation for CreateFile(). The Win32 API
241// uses file handles, which are more randomish integers, not small
242// integers like file descriptors.
243//
244// Because file descriptors are specific to the C library on Windows,
245// the file descriptor returned by this function makes sense only to
246// functions in the same C library. Thus if the GLib-using code uses a
247// different C library than GLib does, the file descriptor returned by
248// this function cannot be passed to C library functions like write()
249// or read().
250//
251// See your C library manual for more details about open().
252func Open(FilenameVar string, FlagsVar int, ModeVar int) int {
253
254 cret := xOpen(FilenameVar, FlagsVar, ModeVar)
255
256 return cret
257}
258
259var xRemove func(string) int
260
261// A wrapper for the POSIX remove() function. The remove() function
262// deletes a name from the filesystem.
263//
264// See your C library manual for more details about how remove() works
265// on your system. On Unix, remove() removes also directories, as it
266// calls unlink() for files and rmdir() for directories. On Windows,
267// although remove() in the C library only works for files, this
268// function tries first remove() and then if that fails rmdir(), and
269// thus works for both files and directories. Note however, that on
270// Windows, it is in general not possible to remove a file that is
271// open to some process, or mapped into memory.
272//
273// If this function fails on Windows you can't infer too much from the
274// errno value. rmdir() is tried regardless of what caused remove() to
275// fail. Any errno value set by remove() will be overwritten by that
276// set by rmdir().
277func Remove(FilenameVar string) int {
278
279 cret := xRemove(FilenameVar)
280
281 return cret
282}
283
284var xRename func(string, string) int
285
286// A wrapper for the POSIX rename() function. The rename() function
287// renames a file, moving it between directories if required.
288//
289// See your C library manual for more details about how rename() works
290// on your system. It is not possible in general on Windows to rename
291// a file that is open to some process.
292func Rename(OldfilenameVar string, NewfilenameVar string) int {
293
294 cret := xRename(OldfilenameVar, NewfilenameVar)
295
296 return cret
297}
298
299var xRmdir func(string) int
300
301// A wrapper for the POSIX rmdir() function. The rmdir() function
302// deletes a directory from the filesystem.
303//
304// See your C library manual for more details about how rmdir() works
305// on your system.
306func Rmdir(FilenameVar string) int {
307
308 cret := xRmdir(FilenameVar)
309
310 return cret
311}
312
313var xStat func(string, *StatBuf) int
314
315// A wrapper for the POSIX stat() function. The stat() function
316// returns information about a file. On Windows the stat() function in
317// the C library checks only the FAT-style READONLY attribute and does
318// not look at the ACL at all. Thus on Windows the protection bits in
319// the @st_mode field are a fabrication of little use.
320//
321// On Windows the Microsoft C libraries have several variants of the
322// stat struct and stat() function with names like _stat(), _stat32(),
323// _stat32i64() and _stat64i32(). The one used here is for 32-bit code
324// the one with 32-bit size and time fields, specifically called _stat32().
325//
326// In Microsoft's compiler, by default struct stat means one with
327// 64-bit time fields while in MinGW struct stat is the legacy one
328// with 32-bit fields. To hopefully clear up this messs, the gstdio.h
329// header defines a type #GStatBuf which is the appropriate struct type
330// depending on the platform and/or compiler being used. On POSIX it
331// is just struct stat, but note that even on POSIX platforms, stat()
332// might be a macro.
333//
334// See your C library manual for more details about stat().
335func Stat(FilenameVar string, BufVar *StatBuf) int {
336
337 cret := xStat(FilenameVar, BufVar)
338
339 return cret
340}
341
342var xUnlink func(string) int
343
344// A wrapper for the POSIX unlink() function. The unlink() function
345// deletes a name from the filesystem. If this was the last link to the
346// file and no processes have it opened, the diskspace occupied by the
347// file is freed.
348//
349// See your C library manual for more details about unlink(). Note
350// that on Windows, it is in general not possible to delete files that
351// are open to some process, or mapped into memory.
352func Unlink(FilenameVar string) int {
353
354 cret := xUnlink(FilenameVar)
355
356 return cret
357}
358
359var xUtime func(string, uintptr) int
360
361// A wrapper for the POSIX utime() function. The utime() function
362// sets the access and modification timestamps of a file.
363//
364// See your C library manual for more details about how utime() works
365// on your system.
366func Utime(FilenameVar string, UtbVar uintptr) int {
367
368 cret := xUtime(FilenameVar, UtbVar)
369
370 return cret
371}
372
373func init() {
374 core.SetPackageName("GLIB", "glib-2.0")
375 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
376 var libs []uintptr
377 for _, libPath := range core.GetPaths("GLIB") {
378 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
379 if err != nil {
380 panic(err)
381 }
382 libs = append(libs, lib)
383 }
384
385 core.PuregoSafeRegister(&xAccess, libs, "g_access")
386 core.PuregoSafeRegister(&xChdir, libs, "g_chdir")
387 core.PuregoSafeRegister(&xChmod, libs, "g_chmod")
388 core.PuregoSafeRegister(&xClose, libs, "g_close")
389 core.PuregoSafeRegister(&xCreat, libs, "g_creat")
390 core.PuregoSafeRegister(&xFopen, libs, "g_fopen")
391 core.PuregoSafeRegister(&xFreopen, libs, "g_freopen")
392 core.PuregoSafeRegister(&xFsync, libs, "g_fsync")
393 core.PuregoSafeRegister(&xLstat, libs, "g_lstat")
394 core.PuregoSafeRegister(&xMkdir, libs, "g_mkdir")
395 core.PuregoSafeRegister(&xOpen, libs, "g_open")
396 core.PuregoSafeRegister(&xRemove, libs, "g_remove")
397 core.PuregoSafeRegister(&xRename, libs, "g_rename")
398 core.PuregoSafeRegister(&xRmdir, libs, "g_rmdir")
399 core.PuregoSafeRegister(&xStat, libs, "g_stat")
400 core.PuregoSafeRegister(&xUnlink, libs, "g_unlink")
401 core.PuregoSafeRegister(&xUtime, libs, "g_utime")
402
403}