Add -DGLIB_COMPILATION for GLib-2.0.gir.
[gnome.gobject-introspection] / giscanner / grealpath.h
1 #ifndef __G_REALPATH_H__
2 #define __G_REALPATH_H__
3
4 #include <stdlib.h>
5
6 /**
7  * g_realpath:
8  *
9  * this should be a) filled in for win32 and b) put in glib...
10  */
11         
12 static inline gchar*
13 g_realpath (const char *path)
14 {
15 #ifndef _WIN32
16 #ifndef PATH_MAX
17 #define PATH_MAX 4096
18 #endif
19         char buffer [PATH_MAX];
20         if (realpath(path, buffer))
21                 return g_strdup(buffer);
22         else
23                 return NULL;
24 #else
25         /* We don't want to include <windows.h> as it clashes horribly
26          * with token names from scannerparser.h. So just declare
27          * GetFullPathNameA() here.
28          */
29         extern __stdcall GetFullPathNameA(const char*, int, char*, char**);
30         char *buffer;
31         char dummy;
32         int rc, len;
33
34         rc = GetFullPathNameA(path, 1, &dummy, NULL);
35
36         if (rc == 0)
37           {
38             /* Weird failure, so just return the input path as such */
39             return g_strdup(path);
40           }
41
42         len = rc + 1;
43         buffer = g_malloc(len);
44
45         rc = GetFullPathNameA(path, len, buffer, NULL);
46
47         if (rc == 0 || rc > len)
48           {
49             /* Weird failure again */
50             g_free(buffer);
51             return g_strdup(path);
52           }
53
54         return buffer;
55 #endif
56 }
57
58 #endif