+ /* the config_main_directory we need for the $config_dir expansion.
+ And config_dir is the directory of the current configuration, used for
+ relative .includes. We do need to know it's name, as we change our working
+ directory later. */
+
+ if (filename[0] == '/')
+ config_main_directory = slash > filename ? string_copyn(filename, slash - filename) : US"/";
+ else
+ {
+ /* relative configuration file name: working dir + / + basename(filename) */
+
+ char buf[PATH_MAX];
+ int offset = 0;
+ int size = 0;
+ const uschar *p = Ustrrchr(filename, '/');
+
+ if (getcwd(buf, PATH_MAX) == NULL)
+ {
+ perror("exim: getcwd");
+ exit(EXIT_FAILURE);
+ }
+ config_main_directory = string_cat(NULL, &size, &offset, buf);
+
+ /* If the dir does not end with a "/", append one */
+ if (config_main_directory[offset-1] != '/')
+ string_cat(config_main_directory, &size, &offset, US"/");
+
+ /* If the config file contains a "/", extract the directory part */
+ if (p)
+ string_catn(config_main_directory, &size, &offset, filename, p - filename);
+ }
+ config_directory = config_main_directory;