Functions
cfgpath.h File Reference

Cross platform methods for obtaining paths to configuration files. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static void get_user_cache_folder (char *out, unsigned int maxlen, const char *appname)
 
static void get_user_config_file (char *out, unsigned int maxlen, const char *appname)
 
static void get_user_config_folder (char *out, unsigned int maxlen, const char *appname)
 
static void get_user_data_folder (char *out, unsigned int maxlen, const char *appname)
 

Detailed Description

Cross platform methods for obtaining paths to configuration files.

Copyright (C) 2013 Adam Nielsen malvi.nosp@m.neou.nosp@m.s@shi.nosp@m.kadi.nosp@m..net

This code is placed in the public domain. You are free to use it for any purpose. If you add new platform support, please contribute a patch!

Example use:

char cfgdir[256]; get_user_config_file(cfgdir, sizeof(cfgdir), "myapp"); if (cfgdir[0] == 0) { printf("Unable to find home directory.\n"); return 1; } printf("Saving configuration file to %s\n", cfgdir);

A number of constants are also defined:

Definition in file cfgpath.h.

Function Documentation

◆ get_user_cache_folder()

static void get_user_cache_folder ( char *  out,
unsigned int  maxlen,
const char *  appname 
)
inlinestatic

Get an absolute path to a temporary storage folder, specific to this user.

This function is useful for programs that temporarily need to store larger amounts of data specific to each user. The output is a folder (which may not exist and will need to be created) suitable for storing a number of temporary files. The files may be lost or deleted when the program terminates.

This path should be used for temporary, unimportant data files that can safely be deleted after the program terminates. Do not use this path for any important files the user would want to keep. Use get_user_data_folder() for those instead.

The returned path will always end in a platform-specific trailing slash, so that a filename can simply be appended to the path.

Output is typically:

Windows: C:\Users\jcitizen\AppData\Local\appname\ Linux: /home/jcitizen/.cache/appname/ Mac: /Users/jcitizen/Library/Application Support/appname/

Parameters
outBuffer to write the path. On return will contain the path, or an empty string on error.
maxlenLength of out. Must be >= MAX_PATH.
appnameShort name of the application. Avoid using spaces or version numbers, and use lowercase if possible.
Postcondition
The folder is created if needed.

Definition at line 405 of file cfgpath.h.

◆ get_user_config_file()

static void get_user_config_file ( char *  out,
unsigned int  maxlen,
const char *  appname 
)
inlinestatic

Get an absolute path to a single configuration file, specific to this user.

This function is useful for programs that need only a single configuration file. The file is unique to the user account currently logged in.

Output is typically:

Windows: C:\Users\jcitizen\AppData\Roaming\appname.ini Linux: /home/jcitizen/.config/appname.conf Mac: /Users/jcitizen/Library/Application Support/appname.conf

Parameters
outBuffer to write the path. On return will contain the path, or an empty string on error.
maxlenLength of out. Must be >= MAX_PATH.
appnameShort name of the application. Avoid using spaces or version numbers, and use lowercase if possible.
Postcondition
The file may or may not exist.
The folder holding the file is created if needed.

Definition at line 96 of file cfgpath.h.

◆ get_user_config_folder()

static void get_user_config_folder ( char *  out,
unsigned int  maxlen,
const char *  appname 
)
inlinestatic

Get an absolute path to a configuration folder, specific to this user.

This function is useful for programs that need to store multiple configuration files. The output is a folder (which may not exist and will need to be created) suitable for storing a number of files.

The returned path will always end in a platform-specific trailing slash, so that a filename can simply be appended to the path.

Output is typically:

Windows: C:\Users\jcitizen\AppData\Roaming\appname\ Linux: /home/jcitizen/.config/appname/ Mac: /Users/jcitizen/Library/Application Support/appname/

Parameters
outBuffer to write the path. On return will contain the path, or an empty string on error.
maxlenLength of out. Must be >= MAX_PATH.
appnameShort name of the application. Avoid using spaces or version numbers, and use lowercase if possible.
Postcondition
The folder is created if needed.

Definition at line 203 of file cfgpath.h.

◆ get_user_data_folder()

static void get_user_data_folder ( char *  out,
unsigned int  maxlen,
const char *  appname 
)
inlinestatic

Get an absolute path to a data storage folder, specific to this user.

This function is useful for programs that need to store larger amounts of data specific to each user. The output is a folder (which may not exist and will need to be created) suitable for storing a number of data files.

This path should be used for persistent, important data files the user would want to keep. Do not use this path for temporary files, cache files, or other files that can be recreated if they are deleted. Use get_user_cache_folder() for those instead.

The returned path will always end in a platform-specific trailing slash, so that a filename can simply be appended to the path.

Output is typically:

Windows: C:\Users\jcitizen\AppData\Roaming\appname-data\ Linux: /home/jcitizen/.local/share/appname/ Mac: /Users/jcitizen/Library/Application Support/appname-data/

Parameters
outBuffer to write the path. On return will contain the path, or an empty string on error.
maxlenLength of out. Must be >= MAX_PATH.
appnameShort name of the application. Avoid using spaces or version numbers, and use lowercase if possible.
Postcondition
The folder is created if needed.

Definition at line 320 of file cfgpath.h.



mp2p_icp
Author(s):
autogenerated on Wed Oct 2 2024 02:45:25