### Function

# GLib creat

since: 2.8

#### Declaration

    int
    g_creat (
      const gchar* filename,
      int mode
    )

#### Description

A wrapper for the POSIX `creat()` function. The `creat()` function is used to convert a pathname into a file descriptor, creating a file if necessary.

On POSIX systems file descriptors are implemented by the operating system. On Windows, it’s the C library that implements `creat()` and file descriptors. The actual Windows API for opening files is different, see MSDN documentation for CreateFile(). The Win32 API uses file handles, which are more randomish integers, not small integers like file descriptors.

Because file descriptors are specific to the C library on Windows, the file descriptor returned by this function makes sense only to functions in the same C library. Thus if the GLib-using code uses a different C library than GLib does, the file descriptor returned by this function cannot be passed to C library functions like `write()` or read().

See your C library manual for more details about creat().

Available since: 2.8

#### Parameters

`filename`

  Type: `const gchar*`

  A pathname in the GLib file name encoding (UTF-8 on Windows)

  The data is owned by the caller of the function.
  The value is a file system path, using the OS encoding.

`mode`

  Type: `int`

  As in `creat()`

#### Return value

Type: `int`

A new file descriptor, or -1 if an error occurred. The return value can be used exactly like the return value from creat().