Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: GPathBufLayout

[12:14] static extends: object

Generated struct layout helper for GIR record PathBuf.

Methods

  • layout ()

    Returns the Panama struct layout for PathBuf.

class: GPathBuf

[36:7] extends: object

GPathBuf is a helper type that allows you to easily build paths from individual elements, using the platform specific conventions for path separators. c g_auto (GPathBuf) path; g_path_buf_init (&path); g_path_buf_push (&path, "usr"); g_path_buf_push (&path, "bin"); g_path_buf_push (&path, "echo"); g_autofree char *echo = g_path_buf_to_path (&path); g_assert_cmpstr (echo, ==, "/usr/bin/echo"); You can also load a full path and then operate on its components: c g_auto (GPathBuf) path; g_path_buf_init_from_path (&path, "/usr/bin/echo"); g_path_buf_pop (&path); g_path_buf_push (&path, "sh"); g_autofree char *sh = g_path_buf_to_path (&path); g_assert_cmpstr (sh, ==, "/usr/bin/sh");

Members

  • handleObj
  • lib
  • retainedCallbacks
  • signalHandlerNames
  • signalSetterHandlers

Methods

  • GPathBuf (Handle = null)

    Creates a new PathBuf by wrapping a native handle or another wrapper.

    • @p Handle is the native handle or another wrapper whose handle to adopt.
  • toNativeHandle (Source)

    Normalizes a constructor argument into a raw pointer carrier. Accepts a raw NativeHandle, a raw NativeBuffer returned from fn.call(...), another generated wrapper exposing handle(), or null. Returns null when the argument carries no pointer.

    • @p Source is the raw handle, raw buffer, wrapper, or null.
    • @r A raw pointer carrier or null when no pointer is present.
  • getLib ()

    Returns the opened native library for this generated wrapper.

    • @r The opened native library.
  • handle ()

    Returns the wrapped NativeHandle.

    • @r The wrapped NativeHandle.
  • isNull ()

    Returns true when the wrapped handle is null.

    • @r A bool.
  • describe ()

    Returns a small string for debugging generated wrappers.

    • @r A string.
  • clear ()

    Clears the contents of the path buffer. This function should be use to free the resources in a stack-allocated GPathBuf initialized using g_path_buf_init() or g_path_buf_init_from_path().

    • @r None.
  • clear_to_path ()

    Clears the contents of the path buffer and returns the built path. This function returns NULL if the GPathBuf is empty. See also: g_path_buf_to_path()

    • @r the built path.
  • copy ()

    Copies the contents of a path buffer into a new GPathBuf.

    • @r the newly allocated path buffer.
  • free ()

    Frees a GPathBuf allocated by g_path_buf_new().

    • @r None.
  • free_to_path ()

    Frees a GPathBuf allocated by g_path_buf_new(), and returns the path inside the buffer. This function returns NULL if the GPathBuf is empty. See also: g_path_buf_to_path()

    • @r the path.
  • init ()

    Initializes a GPathBuf instance.

    • @r the initialized path builder.
  • init_from_path (string path)

    Initializes a GPathBuf instance with the given path.

    • @p path is a file system path.
    • @r the initialized path builder.
  • pop ()

    Removes the last element of the path buffer. If there is only one element in the path buffer (for example, / on Unix-like operating systems or the drive on Windows systems), it will not be removed and %FALSE will be returned instead. |[ GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/bin/sh"); g_path_buf_pop (&buf); g_path_buf_init_from_path (&cmp, "/bin"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_pop (&buf); g_path_buf_init_from_path (&cmp, "/"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_clear (&buf); ]|

    • @r TRUE if the buffer was modified and FALSE otherwise.
  • push (string path)

    Extends the given path buffer with @path. If @path is absolute, it replaces the current path. If @path contains a directory separator, the buffer is extended by as many elements the path provides. On Windows, both forward slashes and backslashes are treated as directory separators. On other platforms, %G_DIR_SEPARATOR_S is the only directory separator. |[ GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/tmp"); g_path_buf_push (&buf, ".X11-unix/X0"); g_path_buf_init_from_path (&cmp, "/tmp/.X11-unix/X0"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_push (&buf, "/etc/locale.conf"); g_path_buf_init_from_path (&cmp, "/etc/locale.conf"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_clear (&buf); ]|

    • @p path is a path.
    • @r the same pointer to @buf, for convenience.
  • set_extension (string extension)

    Adds an extension to the file name in the path buffer. If @extension is NULL, the extension will be unset. If the path buffer does not have a file name set, this function returns FALSE and leaves the path buffer unmodified.

    • @p extension is the file extension.
    • @r TRUE if the extension was replaced, and FALSE otherwise.
  • set_filename (string file_name)

    Sets the file name of the path. If the path buffer is empty, the filename is left unset and this function returns FALSE. If the path buffer only contains the root element (on Unix-like operating systems) or the drive (on Windows), this is the equivalent of pushing the new @file_name. If the path buffer contains a path, this is the equivalent of popping the path buffer and pushing @file_name, creating a sibling of the original path. |[ GPathBuf buf, cmp; g_path_buf_init_from_path (&buf, "/"); g_path_buf_set_filename (&buf, "bar"); g_path_buf_init_from_path (&cmp, "/bar"); g_assert_true (g_path_buf_equal (&buf, &cmp)); g_path_buf_clear (&cmp); g_path_buf_set_filename (&buf, "baz.txt"); g_path_buf_init_from_path (&cmp, "/baz.txt"); g_assert_true (g_path_buf_equal (&buf, &cmp); g_path_buf_clear (&cmp); g_path_buf_clear (&buf); ]|

    • @p file_name is the file name in the path.
    • @r TRUE if the file name was replaced, and FALSE otherwise.
  • to_path ()

    Retrieves the built path from the path buffer. On Windows, the result contains backslashes as directory separators, even if forward slashes were used in input. If the path buffer is empty, this function returns NULL.

    • @r the path.