GLib.stat
Description: Reference for GLib.stat

### Function

# GLibstat

since: 2.6

#### Declaration [src]

    int
    g_stat (
      const gchar* filename,
      GStatBuf* buf
    )

#### Description [src]

A wrapper for the POSIX `stat()` function. The `stat()` function returns information about a file. On Windows the `stat()` function in the C library checks only the FAT-style READONLY attribute and does not look at the ACL at all. Thus on Windows the protection bits in the `st_mode` field are a fabrication of little use.

On Windows the Microsoft C libraries have several variants of the stat struct and `stat()` function with names like _stat(), _stat32(), _stat32i64() and _stat64i32(). The one used here is for 32-bit code the one with 32-bit size and time fields, specifically called _stat32().

In Microsoft’s compiler, by default struct stat means one with 64-bit time fields while in MinGW struct stat is the legacy one with 32-bit fields. To hopefully clear up this messs, the gstdio.h header defines a type `GStatBuf` which is the appropriate struct type depending on the platform and/or compiler being used. On POSIX it is just struct stat, but note that even on POSIX platforms, `stat()` might be a macro.

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

Available since: 2.6

#### 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 platform-native string, using the preferred OS encoding on Unix and UTF-8 on Windows.

`buf`

  Type: `GStatBuf`

  A pointer to a stat struct, which will be filled with the file information.

  The data is owned by the caller of the function.

#### Return value

Type: `int`

0 if the information was successfully retrieved, -1 if an error occurred.