remove empty dir
[ghc-hetmet.git] / compat / cbits / directory.c
1 #include "HsFFI.h"
2
3 #include "../../../includes/ghcconfig.h"
4
5 #if HAVE_LIMITS_H
6 #include <limits.h>
7 #endif
8 #if HAVE_WINDOWS_H
9 #include <windows.h>
10 #endif
11 #include "directory.h"
12
13 #define INLINE /* nothing */
14
15 /*
16  * Following code copied from libraries/base/includes/HsBase.h
17  */
18
19 #ifdef PATH_MAX
20 /* A size that will contain many path names, but not necessarily all
21  * (PATH_MAX is not defined on systems with unlimited path length,
22  * e.g. the Hurd).
23  */
24 INLINE HsInt __compat_long_path_size() { return PATH_MAX; } 
25 #else
26 INLINE HsInt __compat_long_path_size() { return 4096; }
27 #endif
28
29 #if defined(mingw32_HOST_OS)
30
31 /* Make sure we've got the reqd CSIDL_ constants in scope;
32  * w32api header files are lagging a bit in defining the full set.
33  */
34 #if !defined(CSIDL_APPDATA)
35 #define CSIDL_APPDATA 0x001a
36 #endif
37 #if !defined(CSIDL_PERSONAL)
38 #define CSIDL_PERSONAL 0x0005
39 #endif
40 #if !defined(CSIDL_PROFILE)
41 #define CSIDL_PROFILE 0x0028
42 #endif
43 #if !defined(CSIDL_WINDOWS)
44 #define CSIDL_WINDOWS 0x0024
45 #endif
46
47 INLINE int __hscore_CSIDL_PROFILE()  { return CSIDL_PROFILE;  }
48 INLINE int __hscore_CSIDL_APPDATA()  { return CSIDL_APPDATA;  }
49 INLINE int __hscore_CSIDL_WINDOWS()  { return CSIDL_WINDOWS;  }
50 INLINE int __hscore_CSIDL_PERSONAL() { return CSIDL_PERSONAL; }
51
52 #if __GLASGOW_HASKELL__ < 604
53 /*
54  * Function: __hscore_getFolderPath()
55  *
56  * Late-bound version of SHGetFolderPath(), coping with OS versions
57  * that have shell32's lacking that particular API.
58  *
59  */
60 typedef HRESULT (*HSCORE_GETAPPFOLDERFUNTY)(HWND,int,HANDLE,DWORD,char*);
61 int
62 __hscore_getFolderPath(HWND hwndOwner,
63                        int nFolder,
64                        HANDLE hToken,
65                        DWORD dwFlags,
66                        char*  pszPath)
67 {
68     static int loaded_dll = 0;
69     static HMODULE hMod = (HMODULE)NULL;
70     static HSCORE_GETAPPFOLDERFUNTY funcPtr = NULL;
71     /* The DLLs to try loading entry point from */
72     char* dlls[] = { "shell32.dll", "shfolder.dll" };
73     
74     if (loaded_dll < 0) {
75         return (-1);
76     } else if (loaded_dll == 0) {
77         int i;
78         for(i=0;i < sizeof(dlls); i++) {
79             hMod = LoadLibrary(dlls[i]);
80             if ( hMod != NULL &&
81                  (funcPtr = (HSCORE_GETAPPFOLDERFUNTY)GetProcAddress(hMod, "SHGetFolderPathA")) ) {
82                 loaded_dll = 1;
83                 break;
84             }
85         }
86         if (loaded_dll == 0) {
87             loaded_dll = (-1);
88             return (-1);
89         }
90     }
91     /* OK, if we got this far the function has been bound */
92     return (int)funcPtr(hwndOwner,nFolder,hToken,dwFlags,pszPath);
93     /* ToDo: unload the DLL on shutdown? */
94 }
95 #endif /* __GLASGOW_HASKELL__ < 604 */
96 #endif