From ce9368870d952775dec0999118af885693c6c3e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B6r=C3=B6k=20Edvin?= Date: Sun, 9 Nov 2008 22:04:22 +0000 Subject: [PATCH] clamdtop: Apply mingw32 patches from Gianluigi Tiesi git-svn: trunk@4362 --- ChangeLog | 5 +++++ contrib/clamdtop/Makefile | 12 ++++++++++-- contrib/clamdtop/clamdtop.c | 26 ++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8f462402..ade23af14 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Nov 9 22:37:29 EET 2008 (edwin) +------------------------------------ + * contrib/clamdtop/Makefile, contrib/clamdtop/clamdtop.c: clamdtop: + Apply mingw32 patches from Gianluigi Tiesi + Sat Nov 8 17:24:59 EET 2008 (edwin) ------------------------------------ * libclamav/blob.h, libclamav/cab.h, libclamav/jsparse/js-norm.c: diff --git a/contrib/clamdtop/Makefile b/contrib/clamdtop/Makefile index 00a4703b0..ec6bbce3a 100644 --- a/contrib/clamdtop/Makefile +++ b/contrib/clamdtop/Makefile @@ -1,9 +1,17 @@ CFLAGS=-O2 -g -Wall -W -Wshadow CC=gcc -OBJS= clamdtop.o +OBJS=clamdtop.o +LDFLAGS= +CPPFLAGS= + +ifeq ($(MSYSTEM),MINGW32) +LIBS=-lpdcurses -lws2_32 +else +LIBS=-lncurses +endif clamdtop: $(OBJS) Makefile - $(CC) $(CFLAGS) $(OBJS) -lncurses -o $@ + $(CC) $(CPPFLAGS) $(CFLAGS) $(OBJS) -o $@ $(LDFLAGS) $(LIBS) clean: rm -f clamdtop $(OBJS) diff --git a/contrib/clamdtop/clamdtop.c b/contrib/clamdtop/clamdtop.c index d29fd68ee..da7e6a2df 100644 --- a/contrib/clamdtop/clamdtop.c +++ b/contrib/clamdtop/clamdtop.c @@ -29,11 +29,18 @@ #include #include #include +#ifdef _WIN32 +#include +#include +/* this is not correct, perhaps winsock errors are not mapped on errno */ +#define herror perror +#else #include #include #include #include #include +#endif #include #include #include @@ -237,8 +244,8 @@ static void show_bar(WINDOW *win, size_t i, unsigned live, unsigned idle, int y,x; unsigned len = 47; unsigned start = 1; - unsigned activ = ((live-idle)*(len - start - 2) + (max/2)) / max; - unsigned dim = idle*(len - start - 2) / max; + unsigned activ = max ? ((live-idle)*(len - start - 2) + (max/2)) / max : 0; + unsigned dim = max ? idle*(len - start - 2) / max : 0; unsigned rem = len - activ - dim - start-2; assert(activ + 2 < len && activ+dim + 2 < len && activ+dim+rem + 2 < len && "Invalid values"); @@ -301,6 +308,9 @@ static void print_con_error(const char *fmt, ...) static int make_connection(const char *soname, conn_t *conn) { int s; +#ifdef _WIN32 + { +#else if(access(soname, F_OK) == 0) { struct sockaddr_un addr; s = socket(AF_UNIX, SOCK_STREAM, 0); @@ -317,6 +327,7 @@ static int make_connection(const char *soname, conn_t *conn) return -1; } } else { +#endif struct sockaddr_in server; struct hostent *hp; unsigned port = 0; @@ -584,11 +595,22 @@ int main(int argc, char *argv[]) fd_set rfds; struct timeval tv_last, tv; +#ifdef _WIN32 + WSADATA wsaData; + if (WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { + fprintf(stderr, "Error at WSAStartup(): %d\n", WSAGetLastError()); + exit(1); + } + + if (make_connection(argc > 1 ? argv[1] : "localhost:3310", &conn) < 0) + exit(2); +#else /* TODO: parse clamd.conf */ if (make_connection(argc > 1 ? argv[1] : "/tmp/clamd.socket", &conn) < 0) exit(2); signal(SIGPIPE, SIG_IGN); +#endif gettimeofday(&tv_conn, NULL); send_string(&conn, "SESSION\nVERSION\n");