Config/settings directory?

As an exercise in making Protrekkr more Haiku-friendly, I’m trying to move the configuration file from ./ptk.cfg to ~/config/settings/protrekkr_config but it seems to be read-only. How am I doing this wrong? Code fragment follows:

// ------------------------------------------------------
// Set default configuration path
#if defined(__HAIKU__)
#define ALLOCATE_CONFIGNAME char *FileName = "~/config/settings/protrekkr_config";
#define GENERATE_CONFIGNAME
#else
#define ALLOCATE_CONFIGNAME char FileName[MAX_PATH];
#define GENERATE_CONFIGNAME sprintf(FileName, "%s" SLASH "ptk.cfg", ExePath);
#endif

// ------------------------------------------------------
// Save the configuration file
void Save_Config(void)
{
    FILE *out;
    char extension[10];
    char Temph[MAX_PATH];
	ALLOCATE_CONFIGNAME
    int i;
    int Real_Palette_Idx;
    char KeyboardName[MAX_PATH];
    signed char phony = -1;

    sprintf(extension, "PROTCFGG");
    Status_Box("Saving 'ptk.cfg'...");

    GENERATE_CONFIGNAME
	
    memset(KeyboardName, 0, sizeof(KeyboardName));
    sprintf(KeyboardName, "%s", Keyboard_Name);

    out = fopen(FileName, "wb");
1 Like

~ isn’t understood by fopen, it’s interpreted by the shell when you use it on the command line!

Please don’t try to hardcode this.

There is a dedicated API. Please use it.

https://www.haiku-os.org/docs/api/FindDirectory_8h.html

4 Likes

Adding to this: Some examples from HaikuPorts Wiki.

2 Likes