GLib.file_open_tmp
Description: Reference for GLib.file_open_tmp

### Function

# GLibfile_open_tmp

#### Declaration [src]

    gint
    g_file_open_tmp (
      const gchar* tmpl,
      gchar** name_used,
      GError** error
    )

#### Description [src]

Opens a file for writing in the preferred directory for temporary files (as returned by g_get_tmp_dir()).

`tmpl` should be a string in the GLib file name encoding containing a sequence of six ‘X’ characters, as the parameter to g_mkstemp(). However, unlike these functions, the template should only be a basename, no directory components are allowed. If template is `NULL`, a default template is used.

Note that in contrast to `g_mkstemp()` (and mkstemp()) `tmpl` is not modified, and might thus be a read-only literal string.

Upon success, and if `name_used` is non-`NULL`, the actual name used is returned in `name_used`. This string should be freed with `g_free()` when not needed any longer. The returned name is in the GLib file name encoding.

#### Parameters

`tmpl`

  Type: `const gchar*`

  Template for file name, as in g_mkstemp(), basename only, or `NULL` for a default template.

  The argument can be `NULL`.
  The data is owned by the caller of the function.
  The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.

`name_used`

  Type: `gchar**`

  Location to store actual name used, or `NULL`.

  The argument will be set by the function.
  The caller of the function takes ownership of the returned data, and is responsible for freeing it.
  The value is a platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.

`error`

  Type: `GError **`

  The return location for a recoverable error.

  The argument can be `NULL`.
  If the return location is not `NULL`, then you must initialize it to a `NULL` `GError*`.
  The argument will be left initialized to `NULL` by the function if there are no errors.
  In case of error, the argument will be set to a newly allocated `GError`; the caller will take ownership of the data, and be responsible for freeing it.

#### Return value

Type: `gint`

A file handle (as from open()) to the file opened for reading and writing. The file is opened in binary mode on platforms where there is a difference. The file handle should be closed with close(). In case of errors, -1 is returned and `error` will be set.