2 #include "jimautoconf.h"
4 #if defined(_WIN32) || defined(WIN32)
8 #define WIN32_LEAN_AND_MEAN
11 #if defined(HAVE_DLOPEN_COMPAT)
12 void *dlopen(const char *path
, int mode
)
16 return (void *)LoadLibraryA(path
);
19 int dlclose(void *handle
)
21 FreeLibrary((HANDLE
)handle
);
25 void *dlsym(void *handle
, const char *symbol
)
27 return GetProcAddress((HMODULE
)handle
, symbol
);
33 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
34 LANG_NEUTRAL
, msg
, sizeof(msg
) - 1, NULL
);
41 #include <sys/timeb.h>
43 /* POSIX gettimeofday() compatibility for WIN32 */
44 int gettimeofday(struct timeval
*tv
, void *unused
)
50 tv
->tv_usec
= tb
.millitm
* 1000;
55 /* Posix dirent.h compatiblity layer for WIN32.
56 * Copyright Kevlin Henney, 1997, 2003. All rights reserved.
57 * Copyright Salvatore Sanfilippo ,2005.
59 * Permission to use, copy, modify, and distribute this software and its
60 * documentation for any purpose is hereby granted without fee, provided
61 * that this copyright and permissions notice appear in all copies and
64 * This software is supplied "as is" without express or implied warranty.
65 * This software was modified by Salvatore Sanfilippo for the Jim Interpreter.
68 DIR *opendir(const char *name
)
72 if (name
&& name
[0]) {
73 size_t base_length
= strlen(name
);
74 const char *all
= /* search pattern must end with suitable wildcard */
75 strchr("/\\", name
[base_length
- 1]) ? "*" : "/*";
77 if ((dir
= (DIR *) Jim_Alloc(sizeof *dir
)) != 0 &&
78 (dir
->name
= (char *)Jim_Alloc(base_length
+ strlen(all
) + 1)) != 0) {
79 strcat(strcpy(dir
->name
, name
), all
);
81 if ((dir
->handle
= (long)_findfirst(dir
->name
, &dir
->info
)) != -1)
82 dir
->result
.d_name
= 0;
101 int closedir(DIR * dir
)
106 if (dir
->handle
!= -1)
107 result
= _findclose(dir
->handle
);
111 if (result
== -1) /* map all errors to EBADF */
116 struct dirent
*readdir(DIR * dir
)
118 struct dirent
*result
= 0;
120 if (dir
&& dir
->handle
!= -1) {
121 if (!dir
->result
.d_name
|| _findnext(dir
->handle
, &dir
->info
) != -1) {
122 result
= &dir
->result
;
123 result
->d_name
= dir
->info
.name
;