2 #include "jimautoconf.h"
4 #if defined(HAVE_DLOPEN_COMPAT)
5 void *dlopen(const char *path
, int mode
)
9 return (void *)LoadLibraryA(path
);
12 int dlclose(void *handle
)
14 FreeLibrary((HANDLE
)handle
);
18 void *dlsym(void *handle
, const char *symbol
)
20 return GetProcAddress((HMODULE
)handle
, symbol
);
26 FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, GetLastError(),
27 LANG_NEUTRAL
, msg
, sizeof(msg
) - 1, NULL
);
33 /* POSIX gettimeofday() compatibility for WIN32 */
34 int gettimeofday(struct timeval
*tv
, void *unused
)
40 tv
->tv_usec
= tb
.millitm
* 1000;
45 /* Posix dirent.h compatiblity layer for WIN32.
46 * Copyright Kevlin Henney, 1997, 2003. All rights reserved.
47 * Copyright Salvatore Sanfilippo ,2005.
49 * Permission to use, copy, modify, and distribute this software and its
50 * documentation for any purpose is hereby granted without fee, provided
51 * that this copyright and permissions notice appear in all copies and
54 * This software is supplied "as is" without express or implied warranty.
55 * This software was modified by Salvatore Sanfilippo for the Jim Interpreter.
58 DIR *opendir(const char *name
)
62 if (name
&& name
[0]) {
63 size_t base_length
= strlen(name
);
64 const char *all
= /* search pattern must end with suitable wildcard */
65 strchr("/\\", name
[base_length
- 1]) ? "*" : "/*";
67 if ((dir
= (DIR *) Jim_Alloc(sizeof *dir
)) != 0 &&
68 (dir
->name
= (char *)Jim_Alloc(base_length
+ strlen(all
) + 1)) != 0) {
69 strcat(strcpy(dir
->name
, name
), all
);
71 if ((dir
->handle
= (long)_findfirst(dir
->name
, &dir
->info
)) != -1)
72 dir
->result
.d_name
= 0;
91 int closedir(DIR * dir
)
96 if (dir
->handle
!= -1)
97 result
= _findclose(dir
->handle
);
101 if (result
== -1) /* map all errors to EBADF */
106 struct dirent
*readdir(DIR * dir
)
108 struct dirent
*result
= 0;
110 if (dir
&& dir
->handle
!= -1) {
111 if (!dir
->result
.d_name
|| _findnext(dir
->handle
, &dir
->info
) != -1) {
112 result
= &dir
->result
;
113 result
->d_name
= dir
->info
.name
;