aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/Makefile.Watcom8
-rw-r--r--src/Makefile.inc6
-rw-r--r--src/Makefile.m325
-rw-r--r--src/Makefile.vc614
-rw-r--r--src/curlutil.c119
-rw-r--r--src/curlutil.h50
-rw-r--r--src/main.c24
-rw-r--r--src/makefile.amiga2
-rw-r--r--src/makefile.dj4
9 files changed, 194 insertions, 38 deletions
diff --git a/src/Makefile.Watcom b/src/Makefile.Watcom
index 2f48f3bc6..1292ae303 100644
--- a/src/Makefile.Watcom
+++ b/src/Makefile.Watcom
@@ -29,7 +29,7 @@ OBJ_DIR = Watcom_obj
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
@@ -59,7 +59,7 @@ $(RESOURCE): curl.rc
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 .
@@ -89,7 +89,7 @@ $(OBJ_DIR)/main.obj: main.c setup.h config-win32.h ..\lib\setup.h &
..\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 &
@@ -105,5 +105,5 @@ $(OBJ_DIR)/writeout.obj: writeout.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
diff --git a/src/Makefile.inc b/src/Makefile.inc
index b6583e72c..1ebbd0dfe 100644
--- a/src/Makefile.inc
+++ b/src/Makefile.inc
@@ -2,15 +2,15 @@
# 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)
diff --git a/src/Makefile.m32 b/src/Makefile.m32
index 49f070ad6..ced5c7003 100644
--- a/src/Makefile.m32
+++ b/src/Makefile.m32
@@ -66,7 +66,7 @@ curl_LDADD += -lwsock32 -lws2_32 -lwinmm -L$(ZLIB_PATH) -lz
# 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
@@ -79,9 +79,6 @@ curl.exe: curl.res $(curl_OBJECTS) $(curl_DEPENDENCIES)
$(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
diff --git a/src/Makefile.vc6 b/src/Makefile.vc6
index b7ea2d8b1..29efaec37 100644
--- a/src/Makefile.vc6
+++ b/src/Makefile.vc6
@@ -11,7 +11,7 @@
## Updated by: Craig Davison <cd@securityfocus.com>
## release-ssl added by Miklos Nemeth <mnemeth@kfkisystems.com>
## winmm.lib added by Miklos Nemeth <mnemeth@kfkisystems.com> to support
-## timeGetTime() in timeval.c
+## timeGetTime() in curlutil.c
PROGRAM_NAME = curl.exe
@@ -77,7 +77,7 @@ RELEASE_OBJS= \
urlglobr.obj \
getpassr.obj \
homedirr.obj \
- timevalr.obj \
+ curlutilr.obj \
strtoofftr.obj \
mainr.obj \
curlr.res
@@ -88,7 +88,7 @@ DEBUG_OBJS= \
urlglobd.obj \
getpassd.obj \
homedird.obj \
- timevald.obj \
+ curlutild.obj \
strtoofftd.obj \
maind.obj \
curld.res
@@ -221,8 +221,8 @@ getpassr.obj: getpass.c
$(CCR) $(CFLAGS) /Fo"$@" getpass.c
homedirr.obj: homedir.c
$(CCR) $(CFLAGS) /Fo"$@" homedir.c
-timevalr.obj: ../lib/timeval.c
- $(CCR) $(CFLAGS) /Fo"$@" ../lib/timeval.c
+curlutilr.obj: curlutil.c
+ $(CCR) $(CFLAGS) /Fo"$@" curlutil.c
strtoofftr.obj: ../lib/strtoofft.c
$(CCR) $(CFLAGS) /Fo"$@" ../lib/strtoofft.c
mainr.obj: main.c
@@ -241,8 +241,8 @@ getpassd.obj: getpass.c
$(CCD) $(CFLAGS) /Fo"$@" getpass.c
homedird.obj: homedir.c
$(CCD) $(CFLAGS) /Fo"$@" homedir.c
-timevald.obj: ../lib/timeval.c
- $(CCD) $(CFLAGS) /Fo"$@" ../lib/timeval.c
+curlutild.obj: curlutil.c
+ $(CCD) $(CFLAGS) /Fo"$@" curlutil.c
strtoofftd.obj: ../lib/strtoofft.c
$(CCD) $(CFLAGS) /Fo"$@" ../lib/strtoofft.c
maind.obj: main.c
diff --git a/src/curlutil.c b/src/curlutil.c
new file mode 100644
index 000000000..0394d80e2
--- /dev/null
+++ b/src/curlutil.c
@@ -0,0 +1,119 @@
+/***************************************************************************
+ * _ _ ____ _
+ * 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;
+}
+
diff --git a/src/curlutil.h b/src/curlutil.h
new file mode 100644
index 000000000..50f0bfaf5
--- /dev/null
+++ b/src/curlutil.h
@@ -0,0 +1,50 @@
+#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 */
+
diff --git a/src/main.c b/src/main.c
index e06582f09..b3f629590 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,7 @@
#include "writeout.h"
#include "getpass.h"
#include "homedir.h"
+#include "curlutil.h"
#ifdef USE_MANUAL
#include "hugehelp.h"
#endif
@@ -50,19 +51,6 @@
#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 */
@@ -3028,7 +3016,7 @@ int my_trace(CURL *handle, curl_infotype type,
(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)
@@ -3502,8 +3490,8 @@ operate(struct Configurable *config, int argc, char *argv[])
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 &&
@@ -4265,7 +4253,7 @@ operate(struct Configurable *config, int argc, char *argv[])
retry_numretries = config->req_retry;
- retrystart = curlx_tvnow();
+ retrystart = cutil_tvnow();
do {
res = curl_easy_perform(curl);
@@ -4276,7 +4264,7 @@ operate(struct Configurable *config, int argc, char *argv[])
time */
if(retry_numretries &&
(!config->retry_maxtime ||
- (curlx_tvdiff(curlx_tvnow(), retrystart)<
+ (cutil_tvdiff(cutil_tvnow(), retrystart)<
config->retry_maxtime*1000)) ) {
enum {
RETRY_NO,
diff --git a/src/makefile.amiga b/src/makefile.amiga
index 9e03e070f..f5762fc35 100644
--- a/src/makefile.amiga
+++ b/src/makefile.amiga
@@ -14,7 +14,7 @@ MANPAGE = ../docs/curl.1
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)
diff --git a/src/makefile.dj b/src/makefile.dj
index 9e1287eae..8e0d22802 100644
--- a/src/makefile.dj
+++ b/src/makefile.dj
@@ -60,6 +60,8 @@ realclean vclean: clean
- 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 \
@@ -72,7 +74,7 @@ djgpp/main.o: main.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 \