summaryrefslogtreecommitdiff
path: root/src/mcpp-runtime.c
diff options
context:
space:
mode:
authorkx <kx@radix-linux.su>2026-10-02 08:45:51 +0300
committerkx <kx@radix-linux.su>2026-10-02 08:45:51 +0300
commit9d5894a43e3b4dcc4c3b2756b289aba51eef6c63 (patch)
tree5df3a0f2d7c387180da675aec606e276c0d76f11 /src/mcpp-runtime.c
parentba1b04d64bdfaf377915b22f77520216ebe47674 (diff)
downloadmcpu-cpp-9d5894a43e3b4dcc4c3b2756b289aba51eef6c63.tar.xz
Move per-user configuration to /home/kx/.mcpu/etc/mcpu-cpp.conf and add --sys-root=PATH
Diffstat (limited to 'src/mcpp-runtime.c')
-rw-r--r--src/mcpp-runtime.c63
1 files changed, 63 insertions, 0 deletions
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 );
+}