win32 dirent

0.96
aCaB 16 years ago
parent 02daaed6dc
commit 13829b14c5
  1. 4
      win32/clamav-config.h
  2. 68
      win32/compat/dirent.c
  3. 16
      win32/compat/dirent.h
  4. 124
      win32/libclamav.vcproj
  5. 6
      win32/platform.h

@ -216,7 +216,7 @@
/* #undef HAVE_INTTYPES_H */
/* in_addr_t is defined */
#define HAVE_IN_ADDR_T 1
/* #define HAVE_IN_ADDR_T */
/* in_port_t is defined */
#define HAVE_IN_PORT_T 1
@ -346,7 +346,7 @@
#define HAVE_STDLIB_H 1
/* Define to 1 if you have the `strcasestr' function. */
#define HAVE_STRCASESTR 1
/* #define HAVE_STRCASESTR */
/* Define to 1 if you have the `strerror_r' function. */
#define HAVE_STRERROR_R 1

@ -18,9 +18,77 @@
* MA 02110-1301, USA.
*/
#include <errno.h>
#include "others.h"
#include "dirent.h"
#include "shared/misc.h"
DIR *opendir(const char *name) {
DIR *d;
DWORD attrs;
if(!(d = cli_malloc(sizeof(*d)))) {
errno = ENOMEM;
return NULL;
}
if(!(MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, name, -1, d->entry, sizeof(d->entry) / sizeof(d->entry[0])))) {
free(d);
errno = (GetLastError() == ERROR_INSUFFICIENT_BUFFER) ? ENAMETOOLONG : ENOENT;
return NULL;
}
/* FIXME: this should be UNC'd */
if((attrs = GetFileAttributesW(d->entry)) == INVALID_FILE_ATTRIBUTES) {
free(d);
errno = ENOENT;
return NULL;
}
if(!(attrs & FILE_ATTRIBUTE_DIRECTORY)) {
free(d);
errno = ENOTDIR;
return NULL;
}
d->dh = INVALID_HANDLE_VALUE;
return d;
}
struct dirent *readdir(DIR *dirp) {
while(1) {
BOOL cant_convert;
if(dirp->dh == INVALID_HANDLE_VALUE) {
if((dirp->dh = FindFirstFileW(dirp->entry, &dirp->wfd)) == INVALID_HANDLE_VALUE) {
errno = ENOENT;
return NULL;
}
} else {
if(!(FindNextFileW(dirp->dh, &dirp->wfd))) {
errno = (GetLastError() == ERROR_NO_MORE_FILES) ? 0 : ENOENT;
return NULL;
}
}
if(!WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, dirp->wfd.cFileName, -1, dirp->ent.d_name, sizeof(dirp->ent.d_name), NULL, &cant_convert) ||
cant_convert ||
!WideCharToMultiByte(CP_ACP, WC_NO_BEST_FIT_CHARS, dirp->wfd.cAlternateFileName, -1, dirp->ent.d_name, sizeof(dirp->ent.d_name), NULL, &cant_convert) ||
cant_convert ||
!dirp->ent.d_name[0]) {
/* FIXME: WARN HERE ! */
continue;
}
dirp->ent.d_ino = dirp->wfd.ftCreationTime.dwLowDateTime ^ dirp->wfd.nFileSizeLow;
if(!dirp->ent.d_ino) dirp->ent.d_ino = 0x1337;
dirp->ent.d_type = (dirp->wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) ? DT_DIR : DT_REG;
break;
}
return &dirp->ent;
}
void rewinddir(DIR *dirp) {
if(dirp->dh != INVALID_HANDLE_VALUE)
FindClose(dirp->dh);
dirp->dh = INVALID_HANDLE_VALUE;
}
int closedir(DIR *dirp) {
rewinddir(dirp);
free(dirp);
return 0;
}

@ -25,19 +25,21 @@
#include "clamav-config.h"
#endif
#define _DIRENT_HAVE_D_TYPE
//#define _DIRENT_HAVE_D_TYPE
typedef unsigned long ino_t;
typedef struct {
HANDLE dh;
WIN32_FIND_DATAW wfd;
char entry[MAX_PATH];
struct dirent {
ino_t d_ino; /* inode number */
unsigned char d_type; /* type of file */
char d_name[MAX_PATH]; /* filename */
} ent;
wchar_t entry[PATH_MAX];
} DIR;
struct dirent {
char d_ino; /* inode number */
unsigned char d_type; /* type of file */
char d_name[MAX_PATH]; /* filename */
};
enum {
DT_BLOCK,

@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)\3rdparty\zlib&quot;;&quot;$(SolutionDir)\3rdparty\pthreads&quot;;&quot;$(SolutionDir)\3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)\compat&quot;;&quot;$(SolutionDir)\3rdparty\zlib&quot;;&quot;$(SolutionDir)\3rdparty\pthreads&quot;;&quot;$(SolutionDir)\3rdparty\bzip2&quot;;&quot;$(SolutionDir)..\libltdl&quot;;&quot;$(SolutionDir)..&quot;"
PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H"
MinimalRebuild="true"
BasicRuntimeChecks="3"
@ -117,7 +117,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)\3rdparty\zlib&quot;;&quot;$(SolutionDir)\3rdparty\pthreads&quot;;&quot;$(SolutionDir)\3rdparty\bzip2&quot;;&quot;$(SolutionDir)..&quot;"
AdditionalIncludeDirectories="&quot;$(SolutionDir)&quot;;&quot;$(SolutionDir)..\libclamav&quot;;&quot;$(SolutionDir)\compat&quot;;&quot;$(SolutionDir)\3rdparty\zlib&quot;;&quot;$(SolutionDir)\3rdparty\pthreads&quot;;&quot;$(SolutionDir)\3rdparty\bzip2&quot;;&quot;$(SolutionDir)..\libltdl&quot;;&quot;$(SolutionDir)..&quot;"
PreprocessorDefinitions="WIN32_LEAN_AND_MEAN;HAVE_CONFIG_H"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
@ -180,6 +180,42 @@
RelativePath="..\libclamav\7z.c"
>
</File>
<File
RelativePath="..\libclamav\7z\7zBuf.c"
>
</File>
<File
RelativePath="..\libclamav\7z\7zCrc.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zDecode.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zExtract.c"
>
</File>
<File
RelativePath="..\libclamav\7z\7zFile.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zHeader.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zIn.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zItem.c"
>
</File>
<File
RelativePath="..\libclamav\7z\7zStream.c"
>
</File>
<File
RelativePath="..\libclamav\aspack.c"
>
@ -188,6 +224,10 @@
RelativePath="..\libclamav\autoit.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Bcj2.c"
>
</File>
<File
RelativePath="..\libclamav\bignum.c"
>
@ -200,6 +240,18 @@
RelativePath="..\libclamav\blob.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Bra.c"
>
</File>
<File
RelativePath="..\libclamav\7z\Bra86.c"
>
</File>
<File
RelativePath="..\libclamav\7z\BraIA64.c"
>
</File>
<File
RelativePath="..\libclamav\bytecode.c"
>
@ -236,6 +288,10 @@
RelativePath="..\libclamav\dconf.c"
>
</File>
<File
RelativePath=".\compat\dirent.c"
>
</File>
<File
RelativePath="..\libclamav\disasm.c"
>
@ -300,6 +356,10 @@
RelativePath="..\libclamav\lzma_iface.c"
>
</File>
<File
RelativePath="..\libclamav\7z\LzmaDec.c"
>
</File>
<File
RelativePath="..\libclamav\macho.c"
>
@ -332,6 +392,10 @@
RelativePath="..\libclamav\mew.c"
>
</File>
<File
RelativePath="..\shared\misc.c"
>
</File>
<File
RelativePath="..\libclamav\mpool.c"
>
@ -506,6 +570,38 @@
RelativePath="..\libclamav\7z.h"
>
</File>
<File
RelativePath="..\libclamav\7z\7zBuf.h"
>
</File>
<File
RelativePath="..\libclamav\7z\7zCrc.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zDecode.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zExtract.h"
>
</File>
<File
RelativePath="..\libclamav\7z\7zFile.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zHeader.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zIn.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Archive\7z\7zItem.h"
>
</File>
<File
RelativePath="..\libclamav\aspack.h"
>
@ -514,6 +610,10 @@
RelativePath="..\libclamav\autoit.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Bcj2.h"
>
</File>
<File
RelativePath="..\libclamav\bignum.h"
>
@ -530,6 +630,10 @@
RelativePath="..\libclamav\blob.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Bra.h"
>
</File>
<File
RelativePath="..\libclamav\bytecode.h"
>
@ -566,6 +670,10 @@
RelativePath="..\libclamav\cpio.h"
>
</File>
<File
RelativePath="..\libclamav\7z\CpuArch.h"
>
</File>
<File
RelativePath="..\libclamav\cvd.h"
>
@ -678,6 +786,10 @@
RelativePath="..\libclamav\lzma_iface.h"
>
</File>
<File
RelativePath="..\libclamav\7z\LzmaDec.h"
>
</File>
<File
RelativePath="..\libclamav\macho.h"
>
@ -710,6 +822,10 @@
RelativePath="..\libclamav\mew.h"
>
</File>
<File
RelativePath="..\shared\misc.h"
>
</File>
<File
RelativePath="..\libclamav\mpool.h"
>
@ -826,6 +942,10 @@
RelativePath="..\libclamav\type_desc.h"
>
</File>
<File
RelativePath="..\libclamav\7z\Types.h"
>
</File>
<File
RelativePath="..\libclamav\unarj.h"
>

@ -11,8 +11,12 @@
typedef int ssize_t;
#define strcasecmp lstrcmpi
#define strncasecmp strnicmp
/* FIXME: this one is b0rked */
#define snprintf _snprintf
#define PATH_MAX 32767
#define S_IRUSR S_IREAD
#define S_IWUSR S_IWRITE
#define S_IRWXU (S_IRUSR|S_IWUSR)
@ -23,6 +27,8 @@ typedef int ssize_t;
#define R_OK 4
#define X_OK R_OK
#define SEARCH_LIBDIR "."
#ifndef MIN
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif

Loading…
Cancel
Save