Branch data Line data Source code
1 : : #include "precizer.h"
2 : :
3 : : /**
4 : : * Save the runtime directory absolute path into global config structure,
5 : : * fopen() was not able to process relative paths, only absolute ones.
6 : : */
7 : 325 : Return determine_running_dir(void)
8 : : {
9 : 325 : char *cwd = NULL;
10 : :
11 : : #if defined(__GLIBC__)
12 : 325 : cwd = get_current_dir_name();
13 : : #else
14 : : // Portable fallback for platforms without get_current_dir_name (e.g., macOS)
15 : : cwd = getcwd(NULL,0);
16 : : #endif
17 : :
18 [ + - ]: 325 : if(cwd != NULL)
19 : : {
20 : 325 : remove_trailing_slash(cwd);
21 : 325 : config->running_dir = cwd;
22 : 325 : config->running_dir_size = (long int)strlen(config->running_dir) + 1;
23 : 325 : slog(TRACE,"Current directory: %s\n",config->running_dir);
24 : 325 : provide(SUCCESS);
25 : : } else {
26 : 0 : slog(ERROR,"Error getting current directory\n");
27 : 0 : provide(FAILURE);
28 : : }
29 : : }
|