-
-
Save DanielGibson/fbe439e4dd2aab2364ded4726c71f8c3 to your computer and use it in GitHub Desktop.
Test Cattle And Crops directory creation (in home-dir for savegames etc) on Linux
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// tests whether it's possible to create the directories for cattle and crops (and if not, prints error) | |
// compile with | |
// $ gcc -o testcreatedir testcreatedir.c | |
// then run it with | |
// ./testcreatedir | |
#include <errno.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <sys/stat.h> | |
#include <sys/types.h> | |
static void makeDir(const char* path) | |
{ | |
if( (mkdir(path, 0777) != 0) && (errno != EEXIST) ) | |
{ | |
printf("ERROR: Couldn't create directory '%s', reason: %s (%d)\n", path, strerror(errno), errno); | |
exit(1); | |
} | |
if(errno == EEXIST) | |
{ | |
printf("Didn't create directory '%s', it already exists\n", path); | |
} | |
else | |
{ | |
printf("Created directory '%s'\n", path); | |
} | |
} | |
int main(int argc, char** argv) | |
{ | |
const char* homeDir = getenv("HOME"); | |
char path[4096] = {0}; | |
if(homeDir == NULL) | |
{ | |
printf("ERROR: Couldn't get $HOME environment variable!\n"); | |
exit(1); | |
} | |
printf("Got $HOME: '%s'\n", homeDir); | |
snprintf(path, sizeof(path), "%s/.cattle-and-crops", homeDir); | |
makeDir(path); | |
snprintf(path, sizeof(path), "%s/.cattle-and-crops/Engine/", homeDir); | |
makeDir(path); | |
snprintf(path, sizeof(path), "%s/.cattle-and-crops/Profiles/", homeDir); | |
makeDir(path); | |
snprintf(path, sizeof(path), "%s/.cattle-and-crops/Mods/", homeDir); | |
makeDir(path); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment