create a folder from /cpp program and run chmod command on created folder.

#include<iostream>
#include<unistd.h>
#include<string.h>
#include <sys/stat.h>
#include<pwd.h>
#include <stdlib.h>     /* getenv */

using namespace std;

char *homedir;
char *dir = "/Desktop/foo";
char* tmp="chmod +t ";
char cmd[100];

int main()
{
    if ((homedir = getenv("HOME")) == NULL) {
    homedir = getpwuid(getuid())->pw_dir;
}
    strcat(homedir,dir);
    cout<<homedir<<endl;

    mkdir(homedir,S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);

    strcpy(cmd, tmp );
    strcat(cmd,homedir );
    system(cmd);

return 0;
}



Related Contents to follow