S
S
stsdc2014-11-06 01:16:29
linux
stsdc, 2014-11-06 01:16:29

Why doesn't mkdir create a folder?

mkdir returns -1 for some reason.
If you remove homedir->str and write the path yourself, then everything works.

//check if dir exists
    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);
    }

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
jcmvbkbc, 2014-11-06
@stsdc

mkdir returns -1 for some reason

errno? perror? didn't hear?
Does it work with nested directories?
g_string_append(homedir, getenv("HOME"));
g_string_append(homedir, ".some/qwe");
there is no slash between $HOME and .some/qwe.

S
Sergey, 2014-11-06
@butteff

1. Do you have rights to the folder where you create the file? on whose behalf the script is being run, does this user have write permissions?
2. If mkdir is run from a chroot environment of some kind, it can be replaced by another utility.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question