diff options
Diffstat (limited to 'src/mcpp-runtime.c')
| -rw-r--r-- | src/mcpp-runtime.c | 63 |
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 ); +} |
