bl/path.c
author ali <ali@juiblex.co.uk>
Sat Feb 18 21:23:39 2012 +0000 (2012-02-18)
changeset 26 d9f14c625111
permissions -rw-r--r--
Add testcase for he/be jeebies
     1 #ifdef WIN32
     2 #include <windows.h>
     3 #endif
     4 #include <stdlib.h>
     5 #include <glib.h>
     6 #include <bl/bl.h>
     7 
     8 /*
     9  * Return an absolute path to <path>.
    10  * Note that this function makes no attempt to return a unique path, or
    11  * to remove "." or ".." entries. It simply returns a path which will
    12  * be unaffected by subsequent calls to chdir().
    13  */
    14 char *path_to_absolute(const char *path)
    15 {
    16 #ifdef WIN32
    17     long len;
    18     gunichar2 *path2;
    19     gunichar2 *abs2;
    20     char *abs;
    21     path2=g_utf8_to_utf16(path,-1,NULL,NULL,NULL);
    22     if (!path2)
    23 	return NULL;
    24     len=GetFullPathNameW(path2,0,NULL,NULL);	/* len includes nul */
    25     if (!len)
    26     {
    27 	g_free(path2);
    28 	return NULL;
    29     }
    30     abs2=g_new(gunichar2,len);
    31     len=GetFullPathNameW(path2,len,abs2,NULL);	/* len excludes nul */
    32     g_free(path2);
    33     if (!len)
    34     {
    35 	g_free(abs2);
    36 	return NULL;
    37     }
    38     abs=g_utf16_to_utf8(abs2,len,NULL,NULL,NULL);
    39     g_free(abs2);
    40     return abs;
    41 #else
    42     char *s,*abs;
    43     if (*path=='/')
    44 	abs=g_strdup(path);
    45     else
    46     {
    47 	s=g_get_current_dir();
    48 	abs=g_build_filename(s,path,NULL);
    49 	g_free(s);
    50     }
    51     return abs;
    52 #endif
    53 }