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