结构
GLibPathBuf
since: 2.76
说明 [src]
struct GPathBuf {
/* No available fields */
}
GPathBuf
是一个辅助类型,允许您使用平台特定的路径分隔符惯例,轻松地根据各个元素构建路径。
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");
您还可以加载一个完整路径,然后对其组件进行操作
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");
自 2.76 起可用