|
6 | 6 | #include <windows.h>
|
7 | 7 | #endif
|
8 | 8 |
|
9 |
| -static inline int file_attr_to_st_mode (DWORD attr) |
| 9 | +static inline int file_attr_to_st_mode (DWORD attr, DWORD tag) |
10 | 10 | {
|
11 | 11 | int fMode = S_IREAD;
|
12 |
| - if (attr & FILE_ATTRIBUTE_DIRECTORY) |
| 12 | + if ((attr & FILE_ATTRIBUTE_REPARSE_POINT) && tag == IO_REPARSE_TAG_SYMLINK) |
| 13 | + fMode |= S_IFLNK; |
| 14 | + else if (attr & FILE_ATTRIBUTE_DIRECTORY) |
13 | 15 | fMode |= S_IFDIR;
|
14 | 16 | else
|
15 | 17 | fMode |= S_IFREG;
|
@@ -38,4 +40,41 @@ static inline int get_file_attr(const char *fname, WIN32_FILE_ATTRIBUTE_DATA *fd
|
38 | 40 | }
|
39 | 41 | }
|
40 | 42 |
|
| 43 | +/* simplify loading of DLL functions */ |
| 44 | + |
| 45 | +struct proc_addr { |
| 46 | + const char *const dll; |
| 47 | + const char *const function; |
| 48 | + FARPROC pfunction; |
| 49 | + unsigned initialized : 1; |
| 50 | +}; |
| 51 | + |
| 52 | +/* Declares a function to be loaded dynamically from a DLL. */ |
| 53 | +#define DECLARE_PROC_ADDR(dll, rettype, function, ...) \ |
| 54 | + static struct proc_addr proc_addr_##function = \ |
| 55 | + { #dll, #function, NULL, 0 }; \ |
| 56 | + static rettype (WINAPI *function)(__VA_ARGS__) |
| 57 | + |
| 58 | +/* |
| 59 | + * Loads a function from a DLL (once-only). |
| 60 | + * Returns non-NULL function pointer on success. |
| 61 | + * Returns NULL + errno == ENOSYS on failure. |
| 62 | + */ |
| 63 | +#define INIT_PROC_ADDR(function) (function = get_proc_addr(&proc_addr_##function)) |
| 64 | + |
| 65 | +static inline void *get_proc_addr(struct proc_addr *proc) |
| 66 | +{ |
| 67 | + /* only do this once */ |
| 68 | + if (!proc->initialized) { |
| 69 | + proc->initialized = 1; |
| 70 | + HANDLE hnd = LoadLibraryA(proc->dll); |
| 71 | + if (hnd) |
| 72 | + proc->pfunction = GetProcAddress(hnd, proc->function); |
| 73 | + } |
| 74 | + /* set ENOSYS if DLL or function was not found */ |
| 75 | + if (!proc->pfunction) |
| 76 | + errno = ENOSYS; |
| 77 | + return proc->pfunction; |
| 78 | +} |
| 79 | + |
41 | 80 | #endif
|
0 commit comments