1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
|
/*
* This file is part of the MLV Library.
*
* Copyright (C) 2011,2012 Adrien Boussicault, Marc Zipstein
*
*
* This Library is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This Library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "MLV_path.h"
#include "warning_error.h"
#include "memory_management.h"
#include "data_structure.h"
#include <glib.h>
#include <stdarg.h>
char* MLV_get_base_name( const char* path ){
return g_path_get_basename( path );
}
char* MLV_get_directory_name( const char* path ){
return g_path_get_dirname( path );
}
int MLV_path_is_absolute( const char* path ){
return g_path_is_absolute( path );
}
int MLV_path_is_relative( const char* path ){
return ! MLV_path_is_absolute( path );
}
char* MLV_build_path_v( char** elements ){
gchar* tmp_res = g_build_filenamev( elements );
char* result = strdup( tmp_res );
g_free( tmp_res ); // tmp_res have to be freed with g_free (
// see glib documentation
// )
return result;
}
char* MLV_build_path( const char* first_element, ...){
char *result;
if( !first_element ) return NULL;
va_list pile;
const char* type;
int compteur;
va_start( pile, first_element );
compteur = 2;
while(
(
type = va_arg( pile, char* )
) != NULL
){
compteur ++;
}
va_end( pile );
char** elements = MLV_MALLOC( compteur, char* );
elements[0] = strdup( first_element );
va_start( pile, first_element );
int i;
for( i=1; i<compteur; i++ ){
type = va_arg( pile, const char*);
if( type ){
elements[i] = strdup( (const char*) type );
}else{
elements[i] = NULL;
}
}
va_end( pile );
result = MLV_build_path_v( elements );
for( i=0; i<compteur-1; i++ ){
MLV_FREE( elements[i], char );
}
MLV_FREE( elements, char* );
return result;
}
int MLV_path_is_a_directory( const char* path ){
return g_file_test( path, G_FILE_TEST_IS_DIR );
}
int MLV_path_is_a_file( const char* path ){
return g_file_test( path, G_FILE_TEST_IS_REGULAR );
}
int MLV_path_exists( const char* path ){
return g_file_test( path, G_FILE_TEST_EXISTS );
}
char * MLV_get_current_directory( ){
return g_get_current_dir();
}
const char * MLV_get_temporary_directory( ){
return g_get_tmp_dir();
}
const char * MLV_get_home_directory( ){
return g_get_home_dir();
}
|