[Pkg-clamav-commits] [SCM] Debian repository for ClamAV branch, debian/unstable, updated. debian/0.95+dfsg-1-6156-g094ec9b
aCaB
acab at clamav.net
Sun Apr 4 01:08:03 UTC 2010
The following commit has been merged in the debian/unstable branch:
commit 5387e64b430a200f5c0e86ce16c332304f7aceed
Author: aCaB <acab at clamav.net>
Date: Fri Oct 16 20:10:34 2009 +0200
win32. dirent + stat
diff --git a/ChangeLog b/ChangeLog
index b55979a..e83b90c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Fri Oct 16 20:08:51 CEST 2009 (acab)
+------------------------------------
+ * win32: stat added, dirent updated
+
Fri Oct 16 14:56:10 CEST 2009 (tk)
----------------------------------
* clamdscan: fix some output msgs (bb#1716)
diff --git a/win32/compat/dirent.c b/win32/compat/dirent.c
index 24d70f0..88fce38 100644
--- a/win32/compat/dirent.c
+++ b/win32/compat/dirent.c
@@ -27,7 +27,16 @@ DIR *opendir(const char *name) {
DIR *d;
DWORD attrs;
int len;
+ struct stat sb;
+ if(stat(name, &sb) < 0) {
+ errno = ENOENT; /* FIXME: should be set by stat() */
+ return NULL;
+ }
+ if(!S_ISDIR(sb.st_mode)) {
+ errno = ENOTDIR;
+ return NULL;
+ }
if(!(d = cli_malloc(sizeof(*d)))) {
errno = ENOMEM;
return NULL;
@@ -38,17 +47,13 @@ DIR *opendir(const char *name) {
errno = (len || (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;
+ while(len) {
+ if(d->entry[len] == L'\\')
+ d->entry[len] = L'\0';
+ else
+ break;
}
+ /* FIXME: this should be UNC'd */
wcsncat(d->entry, L"\\*.*", 4);
d->dh = INVALID_HANDLE_VALUE;
return d;
diff --git a/win32/compat/w32_stat.c b/win32/compat/w32_stat.c
new file mode 100644
index 0000000..8744f76
--- /dev/null
+++ b/win32/compat/w32_stat.c
@@ -0,0 +1,67 @@
+/*
+ * Copyright (C) 2009 Sourcefire, Inc.
+ *
+ * Authors: aCaB <acab at clamav.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include "others.h"
+
+w32_stat(const char *path, struct stat *buf) {
+ int len = strlen(path) + 2;
+ wchar_t *wpath;
+ WIN32_FILE_ATTRIBUTE_DATA attrs;
+
+ if(len > PATH_MAX) {
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+ if(!(wpath = cli_malloc(len * 2))) {
+ errno = ENOMEM;
+ return -1;
+ }
+ /* FIXME: make it UNC */
+ if(!(len = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, path, -1, wpath, len))) {
+ errno = ENOENT;
+ free(wpath);
+ return -1;
+ }
+ if((len == 3 || (len == 7 && !wcsncmp(wpath, L"\\\\?\\", 4))) && (wpath[len-2] == L':') &&
+ ((wpath[len-3] >= L'A' && wpath[len-3] <= L'Z') || (wpath[len-3] >= L'a' && wpath[len-2] <= L'z')) ) {
+ /* stat drives as dirs */
+ wpath[len-1] = L'\\';
+ wpath[len] = L'\0';
+ }
+ len = GetFileAttributesExW(wpath, GetFileExInfoStandard, &attrs);
+ free(wpath);
+ if(!len) {
+ errno = ENOENT;
+ return -1;
+ }
+ buf->st_dev = 1;
+ buf->st_rdev = 1;
+ buf->st_uid = 0;
+ buf->st_gid = 0;
+ buf->st_ino = 1;
+ buf->st_atime = ((time_t)attrs.ftLastAccessTime.dwHighDateTime<<32) | attrs.ftLastAccessTime.dwLowDateTime;
+ buf->st_ctime = ((time_t)attrs.ftCreationTime.dwHighDateTime<<32) | attrs.ftCreationTime.dwLowDateTime;
+ buf->st_mtime = ((time_t)attrs.ftLastWriteTime.dwHighDateTime<<32) | attrs.ftLastWriteTime.dwLowDateTime;
+ buf->st_mode = (attrs.dwFileAttributes == FILE_ATTRIBUTE_READONLY) ? S_IRUSR: S_IWUSR;
+ buf->st_mode |= (attrs.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) ? _S_IFDIR : _S_IFREG;
+ buf->st_nlink = 1;
+ buf->st_size = ((uint64_t)attrs.nFileSizeHigh << (sizeof(attrs.nFileSizeLow)*8)) | attrs.nFileSizeLow;
+ return 0;
+}
diff --git a/win32/compat/w32_errno.c b/win32/compat/w32_stat.h
similarity index 63%
copy from win32/compat/w32_errno.c
copy to win32/compat/w32_stat.h
index b51273c..e5a69b2 100644
--- a/win32/compat/w32_errno.c
+++ b/win32/compat/w32_stat.h
@@ -18,11 +18,25 @@
* MA 02110-1301, USA.
*/
-#if HAVE_CONFIG_H
-#include "clamav-config.h"
-#endif
+#ifndef __W32_STAT_H
+#define __W32_STAT_H
+
+#include <sys/stat.h>
-#include "w32_errno.h"
+#define S_IRUSR S_IREAD
+#define S_IWUSR S_IWRITE
+#define S_IRWXU (S_IRUSR|S_IWUSR)
+#define S_ISDIR(mode) ((_S_IFDIR & mode)!=0)
+#define S_ISREG(mode) ((_S_IFREG & mode)!=0)
+#define S_ISLNK(mode) (0)
+#define F_OK 0
+#define W_OK 2
+#define R_OK 4
+#define X_OK R_OK
+int w32_stat(const char *path, struct stat *buf);
+#define lstat stat
+#define stat(path, buf) w32_stat(path, buf)
+#endif
diff --git a/win32/libclamav.def b/win32/libclamav.def
index d655774..224ccfb 100644
--- a/win32/libclamav.def
+++ b/win32/libclamav.def
@@ -71,3 +71,5 @@ EXPORTS w32_freeaddrinfo
EXPORTS w32_inet_ntop
EXPORTS w32_gethostbyname
EXPORTS w32_select
+
+EXPORTS w32_stat
\ No newline at end of file
diff --git a/win32/libclamav.vcproj b/win32/libclamav.vcproj
index 179c0c6..9ac4854 100644
--- a/win32/libclamav.vcproj
+++ b/win32/libclamav.vcproj
@@ -796,7 +796,11 @@
>
</File>
<File
- RelativePath=".\compat\w32_errno.h"
+ RelativePath=".\compat\w32_stat.c"
+ >
+ </File>
+ <File
+ RelativePath=".\compat\w32_stat.h"
>
</File>
</Filter>
diff --git a/win32/platform.h b/win32/platform.h
index 8e39a6b..df67e01 100644
--- a/win32/platform.h
+++ b/win32/platform.h
@@ -14,13 +14,13 @@
#include "snprintf.h"
#include "net.h"
#include "w32_errno.h"
+#include "w32_stat.h"
typedef unsigned short mode_t;
#define strcasecmp lstrcmpi
#define strncasecmp strnicmp
#define mkdir(path, mode) mkdir(path)
-#define lstat stat
#define sleep(sex) Sleep(sex)
#define getuid() 0
#define getgid() 0
@@ -46,17 +46,6 @@ char *strptime(const char *s, const char *format, struct tm *tm);
#define PATH_MAX 32767
-#define S_IRUSR S_IREAD
-#define S_IWUSR S_IWRITE
-#define S_IRWXU (S_IRUSR|S_IWUSR)
-#define S_ISDIR(mode) ((_S_IFDIR & mode)!=0)
-#define S_ISREG(mode) ((_S_IFREG & mode)!=0)
-#define S_ISLNK(mode) (0)
-#define F_OK 0
-#define W_OK 2
-#define R_OK 4
-#define X_OK R_OK
-
#define SEARCH_LIBDIR ""
#ifndef MIN
--
Debian repository for ClamAV
More information about the Pkg-clamav-commits
mailing list