bl/path.c
changeset 27 afddb3519767
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/bl/path.c	Sat Feb 18 23:07:09 2012 +0000
     1.3 @@ -0,0 +1,53 @@
     1.4 +#ifdef WIN32
     1.5 +#include <windows.h>
     1.6 +#endif
     1.7 +#include <stdlib.h>
     1.8 +#include <glib.h>
     1.9 +#include <bl/bl.h>
    1.10 +
    1.11 +/*
    1.12 + * Return an absolute path to <path>.
    1.13 + * Note that this function makes no attempt to return a unique path, or
    1.14 + * to remove "." or ".." entries. It simply returns a path which will
    1.15 + * be unaffected by subsequent calls to chdir().
    1.16 + */
    1.17 +char *path_to_absolute(const char *path)
    1.18 +{
    1.19 +#ifdef WIN32
    1.20 +    long len;
    1.21 +    gunichar2 *path2;
    1.22 +    gunichar2 *abs2;
    1.23 +    char *abs;
    1.24 +    path2=g_utf8_to_utf16(path,-1,NULL,NULL,NULL);
    1.25 +    if (!path2)
    1.26 +	return NULL;
    1.27 +    len=GetFullPathNameW(path2,0,NULL,NULL);	/* len includes nul */
    1.28 +    if (!len)
    1.29 +    {
    1.30 +	g_free(path2);
    1.31 +	return NULL;
    1.32 +    }
    1.33 +    abs2=g_new(gunichar2,len);
    1.34 +    len=GetFullPathNameW(path2,len,abs2,NULL);	/* len excludes nul */
    1.35 +    g_free(path2);
    1.36 +    if (!len)
    1.37 +    {
    1.38 +	g_free(abs2);
    1.39 +	return NULL;
    1.40 +    }
    1.41 +    abs=g_utf16_to_utf8(abs2,len,NULL,NULL,NULL);
    1.42 +    g_free(abs2);
    1.43 +    return abs;
    1.44 +#else
    1.45 +    char *s,*abs;
    1.46 +    if (*path=='/')
    1.47 +	abs=g_strdup(path);
    1.48 +    else
    1.49 +    {
    1.50 +	s=g_get_current_dir();
    1.51 +	abs=g_build_filename(s,path,NULL);
    1.52 +	g_free(s);
    1.53 +    }
    1.54 +    return abs;
    1.55 +#endif
    1.56 +}