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 "github.com/bnema/puregotk/v4/gobject/types"
12)
13
14// The #GMappedFile represents a file mapping created with
15// g_mapped_file_new(). It has only private members and should
16// not be accessed directly.
17type MappedFile struct {
18 _ structs.HostLayout
19}
20
21var xMappedFileGLibType func() types.GType
22
23func MappedFileGLibType() types.GType {
24 return xMappedFileGLibType()
25}
26
27func (x *MappedFile) GoPointer() uintptr {
28 return uintptr(unsafe.Pointer(x))
29}
30
31var xNewMappedFile func(string, bool, **Error) *MappedFile
32
33// Maps a file into memory. On UNIX, this is using the mmap() function.
34//
35// If @writable is %TRUE, the mapped buffer may be modified, otherwise
36// it is an error to modify the mapped buffer. Modifications to the buffer
37// are not visible to other processes mapping the same file, and are not
38// written back to the file.
39//
40// Note that modifications of the underlying file might affect the contents
41// of the #GMappedFile. Therefore, mapping should only be used if the file
42// will not be modified, or if all modifications of the file are done
43// atomically (e.g. using g_file_set_contents()).
44//
45// If @filename is the name of an empty, regular file, the function
46// will successfully return an empty #GMappedFile. In other cases of
47// size 0 (e.g. device files such as /dev/null), @error will be set
48// to the #GFileError value %G_FILE_ERROR_INVAL.
49func NewMappedFile(FilenameVar string, WritableVar bool) (*MappedFile, error) {
50 var cerr *Error
51
52 cret := xNewMappedFile(FilenameVar, WritableVar, &cerr)
53 if cerr == nil {
54 return cret, nil
55 }
56 return cret, cerr
57
58}
59
60var xNewMappedFileFromFd func(int, bool, **Error) *MappedFile
61
62// Maps a file into memory. On UNIX, this is using the mmap() function.
63//
64// If @writable is %TRUE, the mapped buffer may be modified, otherwise
65// it is an error to modify the mapped buffer. Modifications to the buffer
66// are not visible to other processes mapping the same file, and are not
67// written back to the file.
68//
69// Note that modifications of the underlying file might affect the contents
70// of the #GMappedFile. Therefore, mapping should only be used if the file
71// will not be modified, or if all modifications of the file are done
72// atomically (e.g. using g_file_set_contents()).
73func NewMappedFileFromFd(FdVar int, WritableVar bool) (*MappedFile, error) {
74 var cerr *Error
75
76 cret := xNewMappedFileFromFd(FdVar, WritableVar, &cerr)
77 if cerr == nil {
78 return cret, nil
79 }
80 return cret, cerr
81
82}
83
84var xMappedFileFree func(uintptr)
85
86// This call existed before #GMappedFile had refcounting and is currently
87// exactly the same as g_mapped_file_unref().
88func (x *MappedFile) Free() {
89
90 xMappedFileFree(x.GoPointer())
91
92}
93
94var xMappedFileGetBytes func(uintptr) *Bytes
95
96// Creates a new #GBytes which references the data mapped from @file.
97// The mapped contents of the file must not be modified after creating this
98// bytes object, because a #GBytes should be immutable.
99func (x *MappedFile) GetBytes() *Bytes {
100
101 cret := xMappedFileGetBytes(x.GoPointer())
102 return cret
103}
104
105var xMappedFileGetContents func(uintptr) string
106
107// Returns the contents of a #GMappedFile.
108//
109// Note that the contents may not be zero-terminated,
110// even if the #GMappedFile is backed by a text file.
111//
112// If the file is empty then %NULL is returned.
113func (x *MappedFile) GetContents() string {
114
115 cret := xMappedFileGetContents(x.GoPointer())
116 return cret
117}
118
119var xMappedFileGetLength func(uintptr) uint
120
121// Returns the length of the contents of a #GMappedFile.
122func (x *MappedFile) GetLength() uint {
123
124 cret := xMappedFileGetLength(x.GoPointer())
125 return cret
126}
127
128var xMappedFileRef func(uintptr) *MappedFile
129
130// Increments the reference count of @file by one. It is safe to call
131// this function from any thread.
132func (x *MappedFile) Ref() *MappedFile {
133
134 cret := xMappedFileRef(x.GoPointer())
135 return cret
136}
137
138var xMappedFileUnref func(uintptr)
139
140// Decrements the reference count of @file by one. If the reference count
141// drops to 0, unmaps the buffer of @file and frees it.
142//
143// It is safe to call this function from any thread.
144//
145// Since 2.22
146func (x *MappedFile) Unref() {
147
148 xMappedFileUnref(x.GoPointer())
149
150}
151
152func init() {
153 core.SetPackageName("GLIB", "glib-2.0")
154 core.SetSharedLibraries("GLIB", []string{"libgobject-2.0.so.0", "libglib-2.0.so.0"})
155 var libs []uintptr
156 for _, libPath := range core.GetPaths("GLIB") {
157 lib, err := purego.Dlopen(libPath, purego.RTLD_NOW|purego.RTLD_GLOBAL)
158 if err != nil {
159 panic(err)
160 }
161 libs = append(libs, lib)
162 }
163
164 core.PuregoSafeRegister(&xMappedFileGLibType, libs, "g_mapped_file_get_type")
165
166 core.PuregoSafeRegister(&xNewMappedFile, libs, "g_mapped_file_new")
167 core.PuregoSafeRegister(&xNewMappedFileFromFd, libs, "g_mapped_file_new_from_fd")
168
169 core.PuregoSafeRegister(&xMappedFileFree, libs, "g_mapped_file_free")
170 core.PuregoSafeRegister(&xMappedFileGetBytes, libs, "g_mapped_file_get_bytes")
171 core.PuregoSafeRegister(&xMappedFileGetContents, libs, "g_mapped_file_get_contents")
172 core.PuregoSafeRegister(&xMappedFileGetLength, libs, "g_mapped_file_get_length")
173 core.PuregoSafeRegister(&xMappedFileRef, libs, "g_mapped_file_ref")
174 core.PuregoSafeRegister(&xMappedFileUnref, libs, "g_mapped_file_unref")
175
176}