@@ -145,9 +145,9 @@ extension LogLevelFlags: Hashable {}
145
145
/// - level: log level (defaults to `.debug`)
146
146
@inlinable public func g_log( messagePtr: UnsafePointer < CChar > ? , level: LogLevelFlags = . debug) {
147
147
guard let msg = messagePtr else { return }
148
- #if swift(<5.2)
148
+ #if swift(<5.2)
149
149
g_logv ( nil , level. value, msg, CVaListPointer ( _fromUnsafeMutablePointer: UnsafeMutableRawPointer ( mutating: msg) ) )
150
- #else
150
+ #else
151
151
guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else {
152
152
print ( String ( cString: msg) )
153
153
return
@@ -161,7 +161,7 @@ extension LogLevelFlags: Hashable {}
161
161
logStructuredArray ( logLevel: level, fields: & fields, nFields: fields. count)
162
162
}
163
163
}
164
- #endif
164
+ #endif
165
165
}
166
166
167
167
/// Logging function
@@ -178,9 +178,9 @@ extension LogLevelFlags: Hashable {}
178
178
withUnsafeMutableBytes ( of: & buffer) {
179
179
guard let buffer = $0. baseAddress else { return }
180
180
let msg = buffer. assumingMemoryBound ( to: CChar . self)
181
- #if swift(<5.2)
181
+ #if swift(<5.2)
182
182
g_logv ( domain, level. value, msg, CVaListPointer ( _fromUnsafeMutablePointer: buffer) )
183
- #else
183
+ #else
184
184
guard GLIB_MAJOR_VERSION > 2 || GLIB_MINOR_VERSION >= 50 else {
185
185
print ( message)
186
186
return
@@ -199,7 +199,7 @@ extension LogLevelFlags: Hashable {}
199
199
}
200
200
}
201
201
}
202
- #endif
202
+ #endif
203
203
}
204
204
}
205
205
#endif
@@ -216,3 +216,175 @@ extension LogLevelFlags: Hashable {}
216
216
g_log ( message, level: . warning)
217
217
}
218
218
}
219
+
220
+ #if os(macOS) || os(Linux)
221
+ /// Change the mode oft a filesystem object.
222
+ ///
223
+ /// This function is a wrapper around the `chmod()` system call,
224
+ /// changing the mode of the filesystem object pointed to by `path`.
225
+ ///
226
+ /// - Parameters:
227
+ /// - path: The filesystem path of the object to query.
228
+ /// - mode: The new mode for the object.
229
+ /// - Returns: `0` on success, `-1` on error.
230
+ @inlinable
231
+ public func g_chmod( _ path: UnsafePointer < CChar > , _ mode: gint ) -> CInt {
232
+ return chmod ( path, mode_t ( mode) )
233
+ }
234
+
235
+ /// Create a file.
236
+ ///
237
+ /// This function is a wrapper around the `creat()` system call,
238
+ /// creating a filesystem object pointed to by `path`.
239
+ ///
240
+ /// - Parameters:
241
+ /// - path: The filesystem path of the object to create.
242
+ /// - mode: The new mode for the object.
243
+ /// - Returns: `0` on success, `-1` on error.
244
+ @inlinable
245
+ public func g_creat( _ path: UnsafePointer < CChar > , _ mode: gint ) -> CInt {
246
+ return creat ( path, mode_t ( mode) )
247
+ }
248
+
249
+ /// Open or create a buiffered stream.
250
+ ///
251
+ /// This function is a wrapper around the `fopen()` system call,
252
+ /// creating a filesystem stream object pointed to by `path`.
253
+ ///
254
+ /// - Parameters:
255
+ /// - path: The filesystem path of the object to open.
256
+ /// - mode: The new mode for the object when created.
257
+ /// - Returns: a pointer to the new stream object, `nil` on error.
258
+ @inlinable
259
+ public func g_fopen( _ path: UnsafePointer < CChar > , _ mode: UnsafePointer < CChar > ) -> UnsafeMutablePointer < FILE > ? {
260
+ return fopen ( path, mode)
261
+ }
262
+
263
+ /// Repen a buiffered stream.
264
+ ///
265
+ /// This function is a wrapper around the `freopen()` system call,
266
+ /// reopening a filesystem stream object pointed to by `path` and
267
+ /// associates the stream with the given file pointer.
268
+ ///
269
+ /// - Parameters:
270
+ /// - path: The filesystem path of the object to open.
271
+ /// - mode: The new mode for the object when created.
272
+ /// - stream: The stream to associate with the file pointer.
273
+ /// - Returns: a pointer to the stream object, `nil` on error.
274
+ @inlinable
275
+ public func g_freopen( _ path: UnsafePointer < CChar > , _ mode: UnsafePointer < CChar > , _ stream: UnsafeMutablePointer < FILE > ! ) -> UnsafeMutablePointer < FILE > ? {
276
+ return freopen ( path, mode, stream)
277
+ }
278
+
279
+ /// Syncronize a filesystem object.
280
+ ///
281
+ /// This function is a wrapper around the `fsync()` system call,
282
+ /// synchronising the files descriptor passed in.
283
+ ///
284
+ /// - Parameters:
285
+ /// - fileDescriptor: The file descriptor to syncronise.
286
+ /// - Returns: `0` on success, `-1` on error.
287
+ @inlinable
288
+ public func g_fsync( _ fileDescriptor: CInt ) -> CInt {
289
+ return fsync ( fileDescriptor)
290
+ }
291
+
292
+ /// Get information about a filesystem object.
293
+ ///
294
+ /// This function is a wrapper around the `lstat()` system call,
295
+ /// returning information about the file pointed to by `path`,
296
+ /// without following symbolic links.
297
+ ///
298
+ /// - Parameters:
299
+ /// - path: The filesystem path of the object to query.
300
+ /// - buf: A `GStatBuf` structure to fill in with information about the file.
301
+ /// - Returns: `0` on success, `-1` on error.
302
+ @inlinable
303
+ public func g_lstat( _ path: UnsafePointer < CChar > , _ buf: UnsafeMutablePointer < GStatBuf > ! ) -> CInt {
304
+ return lstat ( path, buf)
305
+ }
306
+
307
+ /// Create a directory.
308
+ ///
309
+ /// This function is a wrapper around the `mkdir()` system call,
310
+ /// creating a directory pointed to by `path`.
311
+ ///
312
+ /// - Parameters:
313
+ /// - path: The filesystem path of the directory to create.
314
+ /// - mode: The new mode for the directory.
315
+ /// - Returns: `0` on success, `-1` on error.
316
+ @inlinable
317
+ public func g_mkdir( _ path: UnsafePointer < CChar > , _ mode: gint ) -> CInt {
318
+ return mkdir ( path, mode_t ( mode) )
319
+ }
320
+
321
+ /// Open a file.
322
+ ///
323
+ /// This function is a wrapper around the `open()` system call,
324
+ /// opening a filesystem object pointed to by `path`.
325
+ ///
326
+ /// - Parameters:
327
+ /// - path: The filesystem path of the object to open.
328
+ /// - flags: The flags to use when opening the object.
329
+ /// - mode: The new mode for the object.
330
+ /// - Returns: `0` on success, `-1` on error.
331
+ @inlinable
332
+ public func g_open( _ path: UnsafePointer < CChar > , _ flags: CInt , _ mode: gint = 0 ) -> CInt {
333
+ return open ( path, flags, mode_t ( mode) )
334
+ }
335
+
336
+ /// Remove a filesystem object.
337
+ ///
338
+ /// This function is a wrapper around the `remove()` system call,
339
+ /// removing the filesystem object pointed to by `path`.
340
+ ///
341
+ /// - Parameter path: The filesystem path of the object to remove.
342
+ /// - Returns: `0` on success, `-1` on error.
343
+ @inlinable
344
+ public func g_remove( _ path: UnsafePointer < CChar > ) -> CInt {
345
+ return remove ( path)
346
+ }
347
+
348
+ /// Rename a filesystem object.
349
+ ///
350
+ /// This function is a wrapper around the `rename()` system call,
351
+ /// renaming the filesystem object pointed to by `old` to `new`.
352
+ ///
353
+ /// - Parameters:
354
+ /// - old: The old filesystem path.
355
+ /// - new: The new filesystem path.
356
+ /// - Returns: `0` on success, `-1` on error.
357
+ @inlinable
358
+ public func g_rename( _ old: UnsafePointer < CChar > , _ new: UnsafePointer < CChar > ) -> CInt {
359
+ return rename ( old, new)
360
+ }
361
+
362
+ /// Get information about a filesystem object.
363
+ ///
364
+ /// This function is a wrapper around the `stat()` system call,
365
+ /// returning information about the file pointed to by `path`.
366
+ ///
367
+ /// - Parameters:
368
+ /// - path: The filesystem path of the object to query.
369
+ /// - buf: A `GStatBuf` structure to fill in with information about the file.
370
+ /// - Returns: `0` on success, `-1` on error.
371
+ @inlinable
372
+ public func g_stat( _ path: UnsafePointer < CChar > , _ buf: UnsafeMutablePointer < GStatBuf > ! ) -> CInt {
373
+ return stat ( path, buf)
374
+ }
375
+
376
+ /// Set filesystem object times.
377
+ ///
378
+ /// This function is a wrapper around the `utime()` system call,
379
+ /// setting time information about the file pointed to by `path`.
380
+ ///
381
+ /// - Parameters:
382
+ /// - path: The filesystem path of the object to query.
383
+ /// - times: Pointer to a`utimbuf` structure with information about the file access and modification times.
384
+ /// - Returns: `0` on success, `-1` on error.
385
+ @inlinable
386
+ public func g_utime( _ path: UnsafePointer < CChar > , _ times: UnsafePointer < utimbuf > ! ) -> CInt {
387
+ return utime ( path, times)
388
+ }
389
+ #endif
390
+
0 commit comments