c - Why mkdir doesn't work with GString? -



c - Why mkdir doesn't work with GString? -

if utilize "/home/user/.some/qwe" instead of homedir->str, works.

struct stat st = {0}; gstring* homedir = g_string_new(null); g_string_append(homedir, getenv("home")); g_string_append(homedir, ".some/qwe"); printf("%s", homedir->str); if (stat(homedir->str, &st) == -1) { int res= mkdir(homedir->str, 0777); g_string_free(homedir, true); }

you able avoid bug , build valid path names using g_build_filename():

char *homedir = g_build_filename(getenv("home"), ".some", "qwe", null); printf("%s, homedir); if (stat(homedir, &st) == -1) { int res = mkdir(homedir, 0777); } g_free(homedir);

c linux glib

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -