From 66e78e8f5c07f7048fb90075737c38f5452ec5c2 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 24 Jun 2001 18:10:18 +0000 Subject: [PATCH] updates. --- CHANGES | 4 +++ lib/Makefile.am.pre | 8 ++++++ lib/contrib/Makefile.am | 4 +-- lib/silcutil/silcnet.c | 2 +- lib/silcutil/silcschedule.c | 4 +-- lib/silcutil/silctask.c | 2 +- lib/silcutil/silcutil.h | 1 + lib/silcutil/unix/silcunixutil.c | 7 +++++ lib/silcutil/win32/Makefile.am | 3 ++- lib/silcutil/win32/silcwin32util.c | 42 ++++++++++++++++++++++++++++++ 10 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 lib/silcutil/win32/silcwin32util.c diff --git a/CHANGES b/CHANGES index c1c2e9da..5fed3955 100644 --- a/CHANGES +++ b/CHANGES @@ -11,6 +11,10 @@ Sun Jun 24 19:49:23 EEST 2001 Pekka Riikonen * Do not use ptime structure or any of the posix process functions on WIN32 in lib/silccrypt/silrng.c. + * Added silc_gettimeofday to provide generic function + for struct timeval on all platforms. Added the function + to lib/silcutil/silcutil.h. + Sun Jun 24 12:19:52 EEST 2001 Pekka Riikonen * Moved the lib/silccore/silcsockconn.[ch] to the utility diff --git a/lib/Makefile.am.pre b/lib/Makefile.am.pre index d5c98900..60b16fb1 100644 --- a/lib/Makefile.am.pre +++ b/lib/Makefile.am.pre @@ -56,8 +56,16 @@ DISTCLEANFILES = libsilc.a libsilcclient.a if SILC_DIST_CLIENT all: remove libsilc.a libsilcclient.a else +if SILC_DIST_TOOLKIT +all: remove libsilc.a libsilcclient.a +else +if SILC_DIST_WIN32DLL +all: remove libsilc.a libsilcclient.a +else all: remove libsilc.a endif +endif +endif remove: -rm -rf libsilc.a diff --git a/lib/contrib/Makefile.am b/lib/contrib/Makefile.am index 73f34fdd..78f02843 100644 --- a/lib/contrib/Makefile.am +++ b/lib/contrib/Makefile.am @@ -21,9 +21,7 @@ AUTOMAKE_OPTIONS = 1.0 no-dependencies foreign noinst_LIBRARIES = libcontrib.a if SILC_WIN32 -libcontrib_a_SOURCES = \ - getopt.c \ - getopt1.c +libcontrib_a_SOURCES = else libcontrib_a_SOURCES = \ getopt.c \ diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index 826c2cc2..d92d80a6 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -41,7 +41,7 @@ int silc_net_set_socket_opt(int sock, int level, int option, int on) int silc_net_get_socket_opt(int sock, int level, int option, void *optval, int *opt_len) { - return getsockopt(sock, level, option, optval, (socklen_t *)opt_len); + return getsockopt(sock, level, option, optval, opt_len); } /* Checks whether IP address sent as argument is valid IP address. */ diff --git a/lib/silcutil/silcschedule.c b/lib/silcutil/silcschedule.c index 5a673d04..b7e99ed4 100644 --- a/lib/silcutil/silcschedule.c +++ b/lib/silcutil/silcschedule.c @@ -390,7 +390,7 @@ do { \ task = NULL; \ \ /* Get the current time */ \ - gettimeofday(&curtime, NULL); \ + silc_gettimeofday(&curtime); \ schedule->timeout = NULL; \ \ /* First task in the task queue has always the smallest timeout. */ \ @@ -572,7 +572,7 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs) case 0: /* Timeout */ SILC_LOG_DEBUG(("Running timeout tasks")); - gettimeofday(&curtime, NULL); + silc_gettimeofday(&curtime); SILC_SCHEDULE_RUN_TIMEOUT_TASKS; break; default: diff --git a/lib/silcutil/silctask.c b/lib/silcutil/silctask.c index 5697a3ac..5a1c6a3e 100644 --- a/lib/silcutil/silctask.c +++ b/lib/silcutil/silctask.c @@ -312,7 +312,7 @@ SilcTask silc_task_register(SilcTaskQueue queue, int fd, /* Create timeout if marked to be timeout task */ if (((seconds + useconds) > 0) && (type == SILC_TASK_TIMEOUT)) { - gettimeofday(&new->timeout, NULL); + silc_gettimeofday(&new->timeout); new->timeout.tv_sec += seconds + (useconds / 1000000L); new->timeout.tv_usec += (useconds % 1000000L); if (new->timeout.tv_usec > 999999L) { diff --git a/lib/silcutil/silcutil.h b/lib/silcutil/silcutil.h index 33cf92c0..5499f8a8 100644 --- a/lib/silcutil/silcutil.h +++ b/lib/silcutil/silcutil.h @@ -62,5 +62,6 @@ bool silc_hash_data_compare(void *key1, void *key2, void *user_context); char *silc_client_chmode(uint32 mode, const char *cipher, const char *hmac); char *silc_client_chumode(uint32 mode); char *silc_client_chumode_char(uint32 mode); +int silc_gettimeofday(struct timeval *p); #endif diff --git a/lib/silcutil/unix/silcunixutil.c b/lib/silcutil/unix/silcunixutil.c index 2dc40e14..581c7daf 100644 --- a/lib/silcutil/unix/silcunixutil.c +++ b/lib/silcutil/unix/silcunixutil.c @@ -167,3 +167,10 @@ char *silc_get_real_name() return realname; } + +/* Return current time to struct timeval. */ + +int silc_gettimeofday(struct timeval *p) +{ + return gettimeofday(p, NULL); +} diff --git a/lib/silcutil/win32/Makefile.am b/lib/silcutil/win32/Makefile.am index 14616887..70e1d45f 100644 --- a/lib/silcutil/win32/Makefile.am +++ b/lib/silcutil/win32/Makefile.am @@ -23,6 +23,7 @@ noinst_LIBRARIES = libsilcwin32util.a libsilcwin32util_a_SOURCES = \ silcwin32net.c \ silcwin32schedule.c \ - silcwin32sockconn.c + silcwin32sockconn.c \ + silcwin32util.c include $(top_srcdir)/Makefile.defines.in diff --git a/lib/silcutil/win32/silcwin32util.c b/lib/silcutil/win32/silcwin32util.c new file mode 100644 index 00000000..e12fa0a0 --- /dev/null +++ b/lib/silcutil/win32/silcwin32util.c @@ -0,0 +1,42 @@ +/* + + silcwin32util.c + + Author: Pekka Riikonen + + Copyright (C) 2001 Pekka Riikonen + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + 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. + +*/ +/* $Id$ */ + +#include "silcincludes.h" + +#define FILETIME_1970 0x019db1ded53e8000 +const BYTE DWLEN = sizeof(DWORD) * 8; + +/* Return current time in struct timeval. Code ripped from some xntp + implementation on http://src.openresources.com. */ + +int silc_gettimeofday(struct timeval *tv) +{ + FILETIME ft; + __int64 msec; + + GetSystemTimeAsFileTime(&ft); + msec = (__int64) ft.dwHighDateTime << DWLEN | ft.dwLowDateTime; + msec = (msec - FILETIME_1970) / 10; + tv->tv_sec = (long) (msec / 1000000); + tv->tv_usec = (long) (msec % 1000000); + + return 0; +} -- 2.24.0