Commit e268e855 authored by Yang Tse's avatar Yang Tse
Browse files

curl tool was using functions curlx_tvnow and curlx_tvdiff which are not

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.
parent 29bb6f65
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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
+3 −3
Original line number Diff line number Diff line
@@ -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)

+1 −4
Original line number Diff line number Diff line
@@ -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
+7 −7
Original line number Diff line number Diff line
@@ -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

src/curlutil.c

0 → 100644
+119 −0
Original line number Diff line number Diff line
/***************************************************************************
 *                                  _   _ ____  _
 *  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;
}
Loading