From 9d5894a43e3b4dcc4c3b2756b289aba51eef6c63 Mon Sep 17 00:00:00 2001 From: kx Date: Fri, 2 Oct 2026 08:45:51 +0300 Subject: Move per-user configuration to /home/kx/.mcpu/etc/mcpu-cpp.conf and add --sys-root=PATH --- src/mcpp-runtime.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 'src/mcpp-runtime.c') diff --git a/src/mcpp-runtime.c b/src/mcpp-runtime.c index f498b20..592a342 100644 --- a/src/mcpp-runtime.c +++ b/src/mcpp-runtime.c @@ -76,6 +76,29 @@ path_join( const char *directory, const char *name ) } +static char * +path_absolute( const char *path ) +{ + char cwd[PATH_MAX]; + char *result; + + if( path == NULL || *path == 0 ) + { + errno = EINVAL; + return( NULL ); + } + + if( path[0] == '/' ) + return( strdup(path) ); + + if( getcwd(cwd, sizeof(cwd)) == NULL ) + return( NULL ); + + result = path_join( cwd, path ); + return( result ); +} + + static int resolve_proc_self_exe( char path[PATH_MAX] ) { @@ -266,3 +289,43 @@ fail: free( system_include_path ); return( -1 ); } + + +int +mcpp_runtime_paths_set_root( mcpp_runtime_paths *paths, const char *root ) +{ + char *installation_root; + char *config_file; + char *system_include_path; + + if( paths == NULL || root == NULL || *root == 0 ) + { + errno = EINVAL; + return( -1 ); + } + + installation_root = path_absolute( root ); + if( installation_root == NULL ) + return( -1 ); + + config_file = path_join( installation_root, "etc/mcpu-cpp.conf" ); + if( config_file == NULL ) + goto fail; + + system_include_path = path_join( installation_root, "include" ); + if( system_include_path == NULL ) + goto fail; + + free( paths->installation_root ); + free( paths->config_file ); + free( paths->system_include_path ); + paths->installation_root = installation_root; + paths->config_file = config_file; + paths->system_include_path = system_include_path; + return( 0 ); + +fail: + free( installation_root ); + free( config_file ); + return( -1 ); +} -- cgit v1.2.3