Closed Jerboa-app closed 5 months ago
This code functions in a .app bundle which comes from apple... https://developer.apple.com/library/archive/qa/qa1549/_index.html
#include <glob.h>
#include <string>
#include <iostream>
#include <fstream>
#include <filesystem>
char* CreatePathByExpandingTildePath(char* path)
{
glob_t globbuf;
char **v;
char *expandedPath = NULL, *result = NULL;
if (path == NULL) { return "NULL"; }
if (glob(path, GLOB_TILDE, NULL, &globbuf) == 0) //success
{
v = globbuf.gl_pathv; //list of matched pathnames
expandedPath = v[0]; //number of matched pathnames, gl_pathc == 1
result = (char*)calloc(1, strlen(expandedPath) + 1); //the extra char is for the null-termination
if(result)
strncpy(result, expandedPath, strlen(expandedPath) + 1); //copy the null-termination as well
globfree(&globbuf);
}
return result;
}
int main()
{
std::string home = CreatePathByExpandingTildePath("~/");
std::cout << home << std::endl;
std::string support = home+"Library/Application Support/t";
if (!std::filesystem::exists(support)) { std::filesystem::create_directory(support); }
std::ofstream out(support+"/data.json");
out << "{ \"some\": 1 }";
out.close();
}