part of the official libcurl API http://curl.haxx.se/lxr/source/lib/README.curlx
The documented way of using them would be to use timeval.c as a source code file.
The above described method works very well when statically linking libcurl and
apps, curl tool, but has several drawbacks when you build a true shared
libcurl (i.e. Name space clash at linkage stage as functions are defined more
than once. Windows makefiles are not capable of handling this system of
source-level sharing)
So...
Now curlutil.h and curlutil.c define and implement cutil_tvnow and cutil_tvdiff
which replace curlx_tvnow and curlx_tvdiff for the curl tool. Doing this we
avoid the above described problems.
OBJS = $(OBJ_DIR)\getpass.obj $(OBJ_DIR)\homedir.obj $(OBJ_DIR)\hugehelp.obj &
$(OBJ_DIR)\main.obj $(OBJ_DIR)\urlglob.obj $(OBJ_DIR)\writeenv.obj &
- $(OBJ_DIR)\writeout.obj $(OBJ_DIR)\timeval.obj
+ $(OBJ_DIR)\writeout.obj $(OBJ_DIR)\curlutil.obj
RESOURCE = $(OBJ_DIR)\curl.res
wrc -dCURLDEBUG=1 -q -r -zm -I..\include -fo=$@ curl.rc
.ERASE
-$(OBJ_DIR)\timeval.obj: ..\lib\timeval.c
+$(OBJ_DIR)\curlutil.obj: curlutil.c
$(CC) $[@ $(CFLAGS) -fo=$@
@echo .
..\include\curl\easy.h ..\include\curl\multi.h ..\include\curl\curl.h &
urlglob.h writeout.h getpass.h homedir.h hugehelp.h version.h &
..\include\curl\curlver.h ..\lib\curlx.h ..\include\curl\mprintf.h &
- ..\lib\strequal.h ..\lib\strtoofft.h ..\lib\setup.h ..\lib\timeval.h &
+ ..\lib\strequal.h ..\lib\strtoofft.h ..\lib\setup.h curlutil.h &
..\lib\memdebug.h
$(OBJ_DIR)/urlglob.obj: urlglob.c setup.h config-win32.h ..\lib\setup.h &
..\include\curl\easy.h ..\include\curl\multi.h ..\include\curl\curl.h &
..\include\curl\mprintf.h writeout.h
-$(OBJ_DIR)\timeval.obj: ..\lib\timeval.c ..\lib\timeval.h ..\lib\setup.h &
+$(OBJ_DIR)\curlutil.obj: curlutil.c curlutil.h ..\lib\setup.h &
..\lib\config-win32.h
# libcurl has sources that provide functions named curlx_* that aren't part of
# the official API, but we re-use the code here to avoid duplication.
-CURLX_ONES = $(top_srcdir)/lib/strtoofft.c $(top_srcdir)/lib/timeval.c \
+CURLX_ONES = $(top_srcdir)/lib/strtoofft.c \
$(top_srcdir)/lib/strdup.c
CURL_SOURCES = main.c hugehelp.c urlglob.c writeout.c writeenv.c \
- getpass.c homedir.c
+ getpass.c homedir.c curlutil.c
CURL_HFILES = hugehelp.h setup.h config-win32.h config-mac.h \
config-riscos.h urlglob.h version.h \
- writeout.h writeenv.h getpass.h homedir.h
+ writeout.h writeenv.h getpass.h homedir.h curlutil.h
curl_SOURCES = $(CURL_SOURCES) $(CURLX_ONES) $(CURL_HFILES)
# Makefile.inc provides the CSOURCES and HHEADERS defines
include Makefile.inc
-curl_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURL_SOURCES) ../lib/timeval.c)))
+curl_OBJECTS := $(patsubst %.c,%.o,$(strip $(CURL_SOURCES)))
# curlx_OBJECTS := $(patsubst %.c,%.o,$(notdir $(strip $(CURLX_ONES))))
# vpath %.c ../lib
$(LINK) $< $(curl_OBJECTS) $(curl_LDADD)
$(STRIP) $@
-timeval.o: ../lib/timeval.c
- $(COMPILE) -c $<
-
# We don't have nroff normally under win32
# hugehelp.c: ../README.curl ../curl.1 mkhelp.pl
# $(RM) hugehelp.c
## Updated by: Craig Davison <cd@securityfocus.com>\r
## release-ssl added by Miklos Nemeth <mnemeth@kfkisystems.com>\r
## winmm.lib added by Miklos Nemeth <mnemeth@kfkisystems.com> to support\r
-## timeGetTime() in timeval.c\r
+## timeGetTime() in curlutil.c\r
\r
PROGRAM_NAME = curl.exe\r
\r
urlglobr.obj \\r
getpassr.obj \\r
homedirr.obj \\r
- timevalr.obj \\r
+ curlutilr.obj \\r
strtoofftr.obj \\r
mainr.obj \\r
curlr.res\r
urlglobd.obj \\r
getpassd.obj \\r
homedird.obj \\r
- timevald.obj \\r
+ curlutild.obj \\r
strtoofftd.obj \\r
maind.obj \\r
curld.res\r
$(CCR) $(CFLAGS) /Fo"$@" getpass.c\r
homedirr.obj: homedir.c\r
$(CCR) $(CFLAGS) /Fo"$@" homedir.c\r
-timevalr.obj: ../lib/timeval.c\r
- $(CCR) $(CFLAGS) /Fo"$@" ../lib/timeval.c\r
+curlutilr.obj: curlutil.c\r
+ $(CCR) $(CFLAGS) /Fo"$@" curlutil.c\r
strtoofftr.obj: ../lib/strtoofft.c\r
$(CCR) $(CFLAGS) /Fo"$@" ../lib/strtoofft.c\r
mainr.obj: main.c\r
$(CCD) $(CFLAGS) /Fo"$@" getpass.c\r
homedird.obj: homedir.c\r
$(CCD) $(CFLAGS) /Fo"$@" homedir.c\r
-timevald.obj: ../lib/timeval.c\r
- $(CCD) $(CFLAGS) /Fo"$@" ../lib/timeval.c\r
+curlutild.obj: curlutil.c\r
+ $(CCD) $(CFLAGS) /Fo"$@" curlutil.c\r
strtoofftd.obj: ../lib/strtoofft.c\r
$(CCD) $(CFLAGS) /Fo"$@" ../lib/strtoofft.c\r
maind.obj: main.c\r
--- /dev/null
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+#include "curlutil.h"
+
+#ifndef HAVE_GETTIMEOFDAY
+
+#ifdef WIN32
+#include <mmsystem.h>
+
+static int gettimeofday(struct timeval *tp, void *nothing)
+{
+#ifdef WITHOUT_MM_LIB
+ SYSTEMTIME st;
+ time_t tt;
+ struct tm tmtm;
+ /* mktime converts local to UTC */
+ GetLocalTime (&st);
+ tmtm.tm_sec = st.wSecond;
+ tmtm.tm_min = st.wMinute;
+ tmtm.tm_hour = st.wHour;
+ tmtm.tm_mday = st.wDay;
+ tmtm.tm_mon = st.wMonth - 1;
+ tmtm.tm_year = st.wYear - 1900;
+ tmtm.tm_isdst = -1;
+ tt = mktime (&tmtm);
+ tp->tv_sec = tt;
+ tp->tv_usec = st.wMilliseconds * 1000;
+#else
+ /**
+ ** The earlier time calculations using GetLocalTime
+ ** had a time resolution of 10ms.The timeGetTime, part
+ ** of multimedia apis offer a better time resolution
+ ** of 1ms.Need to link against winmm.lib for this
+ **/
+ unsigned long Ticks = 0;
+ unsigned long Sec =0;
+ unsigned long Usec = 0;
+ Ticks = timeGetTime();
+
+ Sec = Ticks/1000;
+ Usec = (Ticks - (Sec*1000))*1000;
+ tp->tv_sec = Sec;
+ tp->tv_usec = Usec;
+#endif /* WITHOUT_MM_LIB */
+ (void)nothing;
+ return 0;
+}
+#else /* WIN32 */
+/* non-win32 version of Curl_gettimeofday() */
+static int gettimeofday(struct timeval *tp, void *nothing)
+{
+ (void)nothing; /* we don't support specific time-zones */
+ tp->tv_sec = (long)time(NULL);
+ tp->tv_usec = 0;
+ return 0;
+}
+#endif /* WIN32 */
+#endif /* HAVE_GETTIMEOFDAY */
+
+/* Return the current time in a timeval struct */
+struct timeval cutil_tvnow(void)
+{
+ struct timeval now;
+ (void)gettimeofday(&now, NULL);
+ return now;
+}
+
+/*
+ * Make sure that the first argument is the more recent time, as otherwise
+ * we'll get a weird negative time-diff back...
+ *
+ * Returns: the time difference in number of milliseconds.
+ */
+long cutil_tvdiff(struct timeval newer, struct timeval older)
+{
+ return (newer.tv_sec-older.tv_sec)*1000+
+ (newer.tv_usec-older.tv_usec)/1000;
+}
+
+/*
+ * Same as cutil_tvdiff but with full usec resolution.
+ *
+ * Returns: the time difference in seconds with subsecond resolution.
+ */
+double cutil_tvdiff_secs(struct timeval newer, struct timeval older)
+{
+ return (double)(newer.tv_sec-older.tv_sec)+
+ (double)(newer.tv_usec-older.tv_usec)/1000000.0;
+}
+
+/* return the number of seconds in the given input timeval struct */
+long cutil_tvlong(struct timeval t1)
+{
+ return t1.tv_sec;
+}
+
--- /dev/null
+#ifndef __CURL_SRC_UTIL_H
+#define __CURL_SRC_UTIL_H
+/***************************************************************************
+ * _ _ ____ _
+ * Project ___| | | | _ \| |
+ * / __| | | | |_) | |
+ * | (__| |_| | _ <| |___
+ * \___|\___/|_| \_\_____|
+ *
+ * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, et al.
+ *
+ * This software is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution. The terms
+ * are also available at http://curl.haxx.se/docs/copyright.html.
+ *
+ * You may opt to use, copy, modify, merge, publish, distribute and/or sell
+ * copies of the Software, and permit persons to whom the Software is
+ * furnished to do so, under the terms of the COPYING file.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ * $Id$
+ ***************************************************************************/
+
+#include "setup.h"
+
+
+struct timeval cutil_tvnow(void);
+
+/*
+ * Make sure that the first argument (t1) is the more recent time and t2 is
+ * the older time, as otherwise you get a weird negative time-diff back...
+ *
+ * Returns: the time difference in number of milliseconds.
+ */
+long cutil_tvdiff(struct timeval t1, struct timeval t2);
+
+/*
+ * Same as cutil_tvdiff but with full usec resolution.
+ *
+ * Returns: the time difference in seconds with subsecond resolution.
+ */
+double cutil_tvdiff_secs(struct timeval t1, struct timeval t2);
+
+long cutil_tvlong(struct timeval t1);
+
+
+#endif /* __CURL_SRC_UTIL_H */
+
#include "writeout.h"
#include "getpass.h"
#include "homedir.h"
+#include "curlutil.h"
#ifdef USE_MANUAL
#include "hugehelp.h"
#endif
#include <screen.h>
#endif
-#ifdef TIME_WITH_SYS_TIME
-/* We can include both fine */
-#include <sys/time.h>
-#include <time.h>
-#else
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#else
-# include <time.h>
-#endif
-#endif
-
-
#include "version.h"
#ifdef HAVE_IO_H /* typical win32 habit */
(void)handle; /* prevent compiler warning */
- tv = curlx_tvnow();
+ tv = cutil_tvnow();
secs = tv.tv_sec;
now = localtime(&secs); /* not multithread safe but we don't care */
if(config->tracetime)
config->conf=CONF_DEFAULT;
config->use_httpget=FALSE;
config->create_dirs=FALSE;
- config->lastrecvtime = curlx_tvnow();
- config->lastsendtime = curlx_tvnow();
+ config->lastrecvtime = cutil_tvnow();
+ config->lastsendtime = cutil_tvnow();
config->maxredirs = DEFAULT_MAXREDIRS;
if(argc>1 &&
retry_numretries = config->req_retry;
- retrystart = curlx_tvnow();
+ retrystart = cutil_tvnow();
do {
res = curl_easy_perform(curl);
time */
if(retry_numretries &&
(!config->retry_maxtime ||
- (curlx_tvdiff(curlx_tvnow(), retrystart)<
+ (cutil_tvdiff(cutil_tvnow(), retrystart)<
config->retry_maxtime*1000)) ) {
enum {
RETRY_NO,
README = ../docs/MANUAL
MKHELP = ../src/mkhelp.pl
-OBJS = getpass.c hugehelp.c main.c urlglob.c writeenv.c writeout.c
+OBJS = getpass.c hugehelp.c main.c urlglob.c writeenv.c writeout.c curlutil.c
all: hugehelp.c $(OBJS:.c=.o)
- rm -f $(PROGRAM) hugehelp.c
# DO NOT DELETE THIS LINE
+djgpp/curlutil.o: curlutil.c setup.h config.h ../lib/config.dj ../lib/setup.h \
+ ../lib/config.h curlutil.h
djgpp/getpass.o: getpass.c setup.h config.h ../lib/config.dj ../lib/setup.h \
../lib/config.h getpass.h
djgpp/homedir.o: homedir.c setup.h config.h ../lib/config.dj ../lib/setup.h \
../include/curl/easy.h ../include/curl/multi.h urlglob.h writeout.h \
getpass.h homedir.h hugehelp.h writeenv.h version.h ../lib/curlx.h \
../include/curl/mprintf.h ../lib/strequal.h ../lib/strtoofft.h \
- ../lib/timeval.h ../lib/memdebug.h ../lib/memory.h
+ curlutil.h ../lib/memdebug.h ../lib/memory.h
djgpp/urlglob.o: urlglob.c setup.h config.h ../lib/config.dj ../lib/setup.h \
../lib/config.h ../include/curl/curl.h ../include/curl/curlver.h \
../include/curl/easy.h ../include/curl/multi.h \