Browse Source

2008-06-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>

	Applied Ross's aria2-0.13.2+1-mingw.patch and
	aria2-0.13.2+1-mingw-2.patch.
	* src/ConsoleStatCalc.cc: Added HAVE_TERMIOUS_H directive for 
the
	systems	which don't have termious.h. I moved the directive 
inside of
	if(isTTY) { ... clause so that line is wiped out without 
termious.h.
	I also removed HAVE_ASCTIME_R clause because asctime_r is 
provided
	anyway.
	* src/asctime_r.h
	* src/asctime_r.c: Added for the systems don't have asctime_r 
function.
	I added 2nd argument to the prototype declaration.
	* src/StringFormat.cc: Get rid of vasprintf.
	* src/getaddrinfo.h: Fixed constants.
	* configure.ac: Added the check for asctime_r function.
	* src/Makefile.am: Added conditional based on HAVE_ASCTIME_R
Tatsuhiro Tsujikawa 17 years ago
parent
commit
b559054701
11 changed files with 377 additions and 70 deletions
  1. 17 0
      ChangeLog
  2. 3 0
      config.h.in
  3. 131 3
      configure
  4. 3 0
      configure.ac
  5. 6 0
      src/ConsoleStatCalc.cc
  6. 4 0
      src/Makefile.am
  7. 28 24
      src/Makefile.in
  8. 4 4
      src/StringFormat.cc
  9. 73 0
      src/asctime_r.c
  10. 51 0
      src/asctime_r.h
  11. 57 39
      src/getaddrinfo.h

+ 17 - 0
ChangeLog

@@ -1,3 +1,20 @@
+2008-06-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
+
+	Applied Ross's aria2-0.13.2+1-mingw.patch and
+	aria2-0.13.2+1-mingw-2.patch.
+	* src/ConsoleStatCalc.cc: Added HAVE_TERMIOUS_H directive for the
+	systems	which don't have termious.h. I moved the directive inside of
+	if(isTTY) { ... clause so that line is wiped out without termious.h.
+	I also removed HAVE_ASCTIME_R clause because asctime_r is provided
+	anyway.
+	* src/asctime_r.h
+	* src/asctime_r.c: Added for the systems don't have asctime_r function.
+	I added 2nd argument to the prototype declaration.
+	* src/StringFormat.cc: Get rid of vasprintf.
+	* src/getaddrinfo.h: Fixed constants.
+	* configure.ac: Added the check for asctime_r function.
+	* src/Makefile.am: Added conditional based on HAVE_ASCTIME_R
+	
 2008-06-16  Tatsuhiro Tsujikawa  <tujikawa at rednoah dot com>
 
 	Added writable test for Socket when the sending message is in progress.

+ 3 - 0
config.h.in

@@ -52,6 +52,9 @@
 /* Define to 1 if you have the <arpa/inet.h> header file. */
 #undef HAVE_ARPA_INET_H
 
+/* Define to 1 if you have the `asctime_r' function. */
+#undef HAVE_ASCTIME_R
+
 /* Define to 1 if you have the `asprintf' function. */
 #undef HAVE_ASPRINTF
 

+ 131 - 3
configure

@@ -798,6 +798,8 @@ LIBINTL
 LTLIBINTL
 POSUB
 LIBOBJS
+HAVE_ASCTIME_R_TRUE
+HAVE_ASCTIME_R_FALSE
 HAVE_BASENAME_TRUE
 HAVE_BASENAME_FALSE
 HAVE_GAI_STRERROR_TRUE
@@ -20094,6 +20096,116 @@ done
 
 
 
+for ac_func in asctime_r
+do
+as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
+{ echo "$as_me:$LINENO: checking for $ac_func" >&5
+echo $ECHO_N "checking for $ac_func... $ECHO_C" >&6; }
+if { as_var=$as_ac_var; eval "test \"\${$as_var+set}\" = set"; }; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+/* Define $ac_func to an innocuous variant, in case <limits.h> declares $ac_func.
+   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
+#define $ac_func innocuous_$ac_func
+
+/* System header to define __stub macros and hopefully few prototypes,
+    which can conflict with char $ac_func (); below.
+    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
+    <limits.h> exists even on freestanding compilers.  */
+
+#ifdef __STDC__
+# include <limits.h>
+#else
+# include <assert.h>
+#endif
+
+#undef $ac_func
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char $ac_func ();
+/* The GNU C library defines this for functions which it implements
+    to always fail with ENOSYS.  Some functions are actually named
+    something starting with __ and the normal name is an alias.  */
+#if defined __stub_$ac_func || defined __stub___$ac_func
+choke me
+#endif
+
+int
+main ()
+{
+return $ac_func ();
+  ;
+  return 0;
+}
+_ACEOF
+rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_cxx_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  eval "$as_ac_var=yes"
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+	eval "$as_ac_var=no"
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext conftest.$ac_ext
+fi
+ac_res=`eval echo '${'$as_ac_var'}'`
+	       { echo "$as_me:$LINENO: result: $ac_res" >&5
+echo "${ECHO_T}$ac_res" >&6; }
+if test `eval echo '${'$as_ac_var'}'` = yes; then
+  cat >>confdefs.h <<_ACEOF
+#define `echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+  if true; then
+  HAVE_ASCTIME_R_TRUE=
+  HAVE_ASCTIME_R_FALSE='#'
+else
+  HAVE_ASCTIME_R_TRUE='#'
+  HAVE_ASCTIME_R_FALSE=
+fi
+
+else
+   if false; then
+  HAVE_ASCTIME_R_TRUE=
+  HAVE_ASCTIME_R_FALSE='#'
+else
+  HAVE_ASCTIME_R_TRUE='#'
+  HAVE_ASCTIME_R_FALSE=
+fi
+
+fi
+done
+
+
 for ac_func in basename
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
@@ -21184,6 +21296,20 @@ echo "$as_me: error: conditional \"ENABLE_ASYNC_DNS\" was never defined.
 Usually this means the macro was only invoked conditionally." >&2;}
    { (exit 1); exit 1; }; }
 fi
+if test -z "${HAVE_ASCTIME_R_TRUE}" && test -z "${HAVE_ASCTIME_R_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"HAVE_ASCTIME_R\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"HAVE_ASCTIME_R\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+if test -z "${HAVE_ASCTIME_R_TRUE}" && test -z "${HAVE_ASCTIME_R_FALSE}"; then
+  { { echo "$as_me:$LINENO: error: conditional \"HAVE_ASCTIME_R\" was never defined.
+Usually this means the macro was only invoked conditionally." >&5
+echo "$as_me: error: conditional \"HAVE_ASCTIME_R\" was never defined.
+Usually this means the macro was only invoked conditionally." >&2;}
+   { (exit 1); exit 1; }; }
+fi
 if test -z "${HAVE_BASENAME_TRUE}" && test -z "${HAVE_BASENAME_FALSE}"; then
   { { echo "$as_me:$LINENO: error: conditional \"HAVE_BASENAME\" was never defined.
 Usually this means the macro was only invoked conditionally." >&5
@@ -22078,6 +22204,8 @@ LIBINTL!$LIBINTL$ac_delim
 LTLIBINTL!$LTLIBINTL$ac_delim
 POSUB!$POSUB$ac_delim
 LIBOBJS!$LIBOBJS$ac_delim
+HAVE_ASCTIME_R_TRUE!$HAVE_ASCTIME_R_TRUE$ac_delim
+HAVE_ASCTIME_R_FALSE!$HAVE_ASCTIME_R_FALSE$ac_delim
 HAVE_BASENAME_TRUE!$HAVE_BASENAME_TRUE$ac_delim
 HAVE_BASENAME_FALSE!$HAVE_BASENAME_FALSE$ac_delim
 HAVE_GAI_STRERROR_TRUE!$HAVE_GAI_STRERROR_TRUE$ac_delim
@@ -22090,8 +22218,6 @@ HAVE_INET_ATON_TRUE!$HAVE_INET_ATON_TRUE$ac_delim
 HAVE_INET_ATON_FALSE!$HAVE_INET_ATON_FALSE$ac_delim
 HAVE_LOCALTIME_R_TRUE!$HAVE_LOCALTIME_R_TRUE$ac_delim
 HAVE_LOCALTIME_R_FALSE!$HAVE_LOCALTIME_R_FALSE$ac_delim
-HAVE_STRPTIME_TRUE!$HAVE_STRPTIME_TRUE$ac_delim
-HAVE_STRPTIME_FALSE!$HAVE_STRPTIME_FALSE$ac_delim
 _ACEOF
 
   if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 97; then
@@ -22133,12 +22259,14 @@ _ACEOF
 ac_delim='%!_!# '
 for ac_last_try in false false false false false :; do
   cat >conf$$subs.sed <<_ACEOF
+HAVE_STRPTIME_TRUE!$HAVE_STRPTIME_TRUE$ac_delim
+HAVE_STRPTIME_FALSE!$HAVE_STRPTIME_FALSE$ac_delim
 HAVE_TIMEGM_TRUE!$HAVE_TIMEGM_TRUE$ac_delim
 HAVE_TIMEGM_FALSE!$HAVE_TIMEGM_FALSE$ac_delim
 LTLIBOBJS!$LTLIBOBJS$ac_delim
 _ACEOF
 
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 3; then
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 5; then
     break
   elif $ac_last_try; then
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5

+ 3 - 0
configure.ac

@@ -185,6 +185,9 @@ AC_CHECK_FUNCS([__argz_count __argz_next __argz_stringify atexit daemon ftruncat
 
 AC_CHECK_FUNCS([epoll_create])
 
+AC_CHECK_FUNCS([asctime_r],
+	[AM_CONDITIONAL([HAVE_ASCTIME_R], true)],
+	[AM_CONDITIONAL([HAVE_ASCTIME_R], false)])
 AC_CHECK_FUNCS([basename],
 	[AM_CONDITIONAL([HAVE_BASENAME], true)],
 	[AM_CONDITIONAL([HAVE_BASENAME], false)])

+ 6 - 0
src/ConsoleStatCalc.cc

@@ -43,8 +43,12 @@
 #ifdef ENABLE_BITTORRENT
 # include "BtContext.h"
 #endif // ENABLE_BITTORRENT
+#ifdef HAVE_TERMIOS_H
 #include <termios.h>
+#endif // HAVE_TERMIOS_H
+#ifdef HAVE_SYS_IOCTL_H
 #include <sys/ioctl.h>
+#endif // HAVE_SYS_IOCTL_H
 #include <unistd.h>
 #include <iomanip>
 #include <iostream>
@@ -169,10 +173,12 @@ ConsoleStatCalc::calculateStat(const RequestGroupManHandle& requestGroupMan,
   bool isTTY = isatty(STDOUT_FILENO) == 1;
   unsigned short int cols = 80;
   if(isTTY) {
+#ifdef HAVE_TERMIOS_H
     struct winsize size;
     if(ioctl(STDOUT_FILENO, TIOCGWINSZ, &size) == 0) {
       cols = size.ws_col;
     }
+#endif // HAVE_TERMIOS_H
     std::cout << '\r' << std::setfill(' ') << std::setw(cols) << ' ' << '\r';
   }
   std::ostringstream o;

+ 4 - 0
src/Makefile.am

@@ -422,6 +422,10 @@ if ENABLE_LIBEXPAT
 SRCS += ExpatMetalinkProcessor.cc ExpatMetalinkProcessor.h
 endif # ENABLE_LIBEXPAT
 
+if !HAVE_ASCTIME_R
+SRCS += asctime_r.c asctime_r.h
+endif # !HAVE_ASCTIME_R
+
 if !HAVE_BASENAME
 SRCS += libgen.c libgen.h
 endif # !HAVE_BASENAME

+ 28 - 24
src/Makefile.in

@@ -252,14 +252,15 @@ bin_PROGRAMS = aria2c$(EXEEXT)
 
 @ENABLE_LIBXML2_TRUE@am__append_5 = XML2SAXMetalinkProcessor.cc XML2SAXMetalinkProcessor.h
 @ENABLE_LIBEXPAT_TRUE@am__append_6 = ExpatMetalinkProcessor.cc ExpatMetalinkProcessor.h
-@HAVE_BASENAME_FALSE@am__append_7 = libgen.c libgen.h
-@HAVE_GETADDRINFO_FALSE@am__append_8 = getaddrinfo.c getaddrinfo.h
-@HAVE_GAI_STRERROR_FALSE@am__append_9 = gai_strerror.c gai_strerror.h
-@HAVE_GETTIMEOFDAY_FALSE@am__append_10 = gettimeofday.c gettimeofday.h
-@HAVE_INET_ATON_FALSE@am__append_11 = inet_aton.c inet_aton.h
-@HAVE_LOCALTIME_R_FALSE@am__append_12 = localtime_r.c localtime_r.h
-@HAVE_STRPTIME_FALSE@am__append_13 = strptime.c strptime.h
-@HAVE_TIMEGM_FALSE@am__append_14 = timegm.c timegm.h
+@HAVE_ASCTIME_R_FALSE@am__append_7 = asctime_r.c asctime_r.h
+@HAVE_BASENAME_FALSE@am__append_8 = libgen.c libgen.h
+@HAVE_GETADDRINFO_FALSE@am__append_9 = getaddrinfo.c getaddrinfo.h
+@HAVE_GAI_STRERROR_FALSE@am__append_10 = gai_strerror.c gai_strerror.h
+@HAVE_GETTIMEOFDAY_FALSE@am__append_11 = gettimeofday.c gettimeofday.h
+@HAVE_INET_ATON_FALSE@am__append_12 = inet_aton.c inet_aton.h
+@HAVE_LOCALTIME_R_FALSE@am__append_13 = localtime_r.c localtime_r.h
+@HAVE_STRPTIME_FALSE@am__append_14 = strptime.c strptime.h
+@HAVE_TIMEGM_FALSE@am__append_15 = timegm.c timegm.h
 subdir = src
 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in alloca.c
 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
@@ -557,10 +558,11 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 	MetalinkPostDownloadHandler.h MetalinkHelper.cc \
 	MetalinkHelper.h XML2SAXMetalinkProcessor.cc \
 	XML2SAXMetalinkProcessor.h ExpatMetalinkProcessor.cc \
-	ExpatMetalinkProcessor.h libgen.c libgen.h getaddrinfo.c \
-	getaddrinfo.h gai_strerror.c gai_strerror.h gettimeofday.c \
-	gettimeofday.h inet_aton.c inet_aton.h localtime_r.c \
-	localtime_r.h strptime.c strptime.h timegm.c timegm.h
+	ExpatMetalinkProcessor.h asctime_r.c asctime_r.h libgen.c \
+	libgen.h getaddrinfo.c getaddrinfo.h gai_strerror.c \
+	gai_strerror.h gettimeofday.c gettimeofday.h inet_aton.c \
+	inet_aton.h localtime_r.c localtime_r.h strptime.c strptime.h \
+	timegm.c timegm.h
 @ENABLE_ASYNC_DNS_TRUE@am__objects_1 = AsyncNameResolver.$(OBJEXT)
 @ENABLE_MESSAGE_DIGEST_TRUE@am__objects_2 = IteratableChunkChecksumValidator.$(OBJEXT) \
 @ENABLE_MESSAGE_DIGEST_TRUE@	IteratableChecksumValidator.$(OBJEXT) \
@@ -710,15 +712,16 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
 @ENABLE_LIBXML2_TRUE@	XML2SAXMetalinkProcessor.$(OBJEXT)
 @ENABLE_LIBEXPAT_TRUE@am__objects_6 =  \
 @ENABLE_LIBEXPAT_TRUE@	ExpatMetalinkProcessor.$(OBJEXT)
-@HAVE_BASENAME_FALSE@am__objects_7 = libgen.$(OBJEXT)
-@HAVE_GETADDRINFO_FALSE@am__objects_8 = getaddrinfo.$(OBJEXT)
-@HAVE_GAI_STRERROR_FALSE@am__objects_9 = gai_strerror.$(OBJEXT)
-@HAVE_GETTIMEOFDAY_FALSE@am__objects_10 = gettimeofday.$(OBJEXT)
-@HAVE_INET_ATON_FALSE@am__objects_11 = inet_aton.$(OBJEXT)
-@HAVE_LOCALTIME_R_FALSE@am__objects_12 = localtime_r.$(OBJEXT)
-@HAVE_STRPTIME_FALSE@am__objects_13 = strptime.$(OBJEXT)
-@HAVE_TIMEGM_FALSE@am__objects_14 = timegm.$(OBJEXT)
-am__objects_15 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
+@HAVE_ASCTIME_R_FALSE@am__objects_7 = asctime_r.$(OBJEXT)
+@HAVE_BASENAME_FALSE@am__objects_8 = libgen.$(OBJEXT)
+@HAVE_GETADDRINFO_FALSE@am__objects_9 = getaddrinfo.$(OBJEXT)
+@HAVE_GAI_STRERROR_FALSE@am__objects_10 = gai_strerror.$(OBJEXT)
+@HAVE_GETTIMEOFDAY_FALSE@am__objects_11 = gettimeofday.$(OBJEXT)
+@HAVE_INET_ATON_FALSE@am__objects_12 = inet_aton.$(OBJEXT)
+@HAVE_LOCALTIME_R_FALSE@am__objects_13 = localtime_r.$(OBJEXT)
+@HAVE_STRPTIME_FALSE@am__objects_14 = strptime.$(OBJEXT)
+@HAVE_TIMEGM_FALSE@am__objects_15 = timegm.$(OBJEXT)
+am__objects_16 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	AbstractCommand.$(OBJEXT) \
 	InitiateConnectionCommandFactory.$(OBJEXT) \
 	DownloadCommand.$(OBJEXT) \
@@ -794,8 +797,8 @@ am__objects_15 = SocketCore.$(OBJEXT) Command.$(OBJEXT) \
 	$(am__objects_5) $(am__objects_6) $(am__objects_7) \
 	$(am__objects_8) $(am__objects_9) $(am__objects_10) \
 	$(am__objects_11) $(am__objects_12) $(am__objects_13) \
-	$(am__objects_14)
-am_libaria2c_a_OBJECTS = $(am__objects_15)
+	$(am__objects_14) $(am__objects_15)
+am_libaria2c_a_OBJECTS = $(am__objects_16)
 libaria2c_a_OBJECTS = $(am_libaria2c_a_OBJECTS)
 am__installdirs = "$(DESTDIR)$(bindir)"
 binPROGRAMS_INSTALL = $(INSTALL_PROGRAM)
@@ -1114,7 +1117,7 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
 	$(am__append_4) $(am__append_5) $(am__append_6) \
 	$(am__append_7) $(am__append_8) $(am__append_9) \
 	$(am__append_10) $(am__append_11) $(am__append_12) \
-	$(am__append_13) $(am__append_14)
+	$(am__append_13) $(am__append_14) $(am__append_15)
 noinst_LIBRARIES = libaria2c.a
 libaria2c_a_SOURCES = $(SRCS)
 aria2c_LDADD = libaria2c.a @LIBINTL@ @ALLOCA@ @LIBGNUTLS_LIBS@\
@@ -1474,6 +1477,7 @@ distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/VerificationMetalinkParserState.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/VersionMetalinkParserState.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/XML2SAXMetalinkProcessor.Po@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/asctime_r.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gai_strerror.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getaddrinfo.Po@am__quote@
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/gettimeofday.Po@am__quote@

+ 4 - 4
src/StringFormat.cc

@@ -45,10 +45,10 @@ StringFormat::StringFormat(const char* fmt, ...)
 {
   va_list ap;
   va_start(ap, fmt);
-  char* strp;
-  if(vasprintf(&strp, fmt, ap) != -1) {
-    _msg.assign(&strp[0], &strp[strlen(strp)]);
-    free(strp);
+  char buf[1024];
+  int r;
+  if((r = vsnprintf(buf, sizeof(buf), fmt, ap)) > 0) {
+    _msg.assign(&buf[0], &buf[r]);
   }
   va_end(ap);
 }

+ 73 - 0
src/asctime_r.c

@@ -0,0 +1,73 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2008 Tatsuhiro Tsujikawa
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+
+#include <time.h>
+#include <stdlib.h>
+
+#ifdef __MINGW32__
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+#endif // __MINGW32__
+
+#include "asctime_r.h"
+
+#ifdef __MINGW32__
+
+static CRITICAL_SECTION asctime_r_cs;
+
+static void asctime_r_atexit()
+{
+	DeleteCriticalSection(&asctime_r_cs);
+}
+
+char * asctime_r (const struct tm*, char *buf);
+{
+	static char *p;
+	static int initialized = 0;
+
+	if (!initialized) {
+		++initialized;
+		InitializeCriticalSection(&asctime_r_cs);
+		atexit(asctime_r_atexit);
+	}
+
+	EnterCriticalSection(&asctime_r_cs);
+	p = asctime(tm);
+	memcpy(buf, p, 26);
+	LeaveCriticalSection(&asctime_r_cs);
+	return buf;
+};
+
+#endif // __MINGW32__

+ 51 - 0
src/asctime_r.h

@@ -0,0 +1,51 @@
+/* <!-- copyright */
+/*
+ * aria2 - The high speed download utility
+ *
+ * Copyright (C) 2008 Tatsuhiro Tsujikawa
+ *
+ * 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.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ * In addition, as a special exception, the copyright holders give
+ * permission to link the code of portions of this program with the
+ * OpenSSL library under certain conditions as described in each
+ * individual source file, and distribute linked combinations
+ * including the two.
+ * You must obey the GNU General Public License in all respects
+ * for all of the code used other than OpenSSL.  If you modify
+ * file(s) with this exception, you may extend this exception to your
+ * version of the file(s), but you are not obligated to do so.  If you
+ * do not wish to do so, delete this exception statement from your
+ * version.  If you delete this exception statement from all source
+ * files in the program, then also delete it here.
+ */
+/* copyright --> */
+
+#ifndef _D_ASCTIME_R_H
+#define _D_ASCTIME_R_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+  
+#include <time.h>
+  
+char * asctime_r (const struct tm*, char*);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* not _D_ASCTIME_R_H */

+ 57 - 39
src/getaddrinfo.h

@@ -161,50 +161,68 @@ extern "C" {
 #define getnameinfo my_getnameinfo
 #endif
 
-/********************************************************************/
-/*
- * Error codes.
- */
-#define EAI_ADDRFAMILY	1
-#define EAI_AGAIN	2
-#define EAI_BADFLAGS	3
-#define EAI_FAIL	4
-#define EAI_FAMILY	5
-#define EAI_MEMORY	6
-#define EAI_NONAME	7
-#define EAI_OVERFLOW	8
-#define EAI_SERVICE	9
-#define EAI_SOCKTYPE	10
-#define EAI_SYSTEM	11
-
-/*
- * Flags for getaddrinfo().
- */
-#define AI_ADDRCONFIG	0x0001
-#define AI_ALL		0x0002
-#define AI_CANONNAME	0x0004
-#define AI_NUMERICHOST	0x0008
-#define AI_NUMERICSERV	0x0010
-#define AI_PASSIVE	0x0020
-#define AI_V4MAPPED	0x0040
-#define AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
+# <from linux's netdb.h>
+/* Possible values for `ai_flags' field in `addrinfo' structure.  */
+# define AI_PASSIVE     0x0001  /* Socket address is intended for `bind'.  */
+# define AI_CANONNAME   0x0002  /* Request for canonical name.  */
+# define AI_NUMERICHOST 0x0004  /* Don't use name resolution.  */
+# define AI_V4MAPPED    0x0008  /* IPv4 mapped addresses are acceptable.  */
+# define AI_ALL         0x0010  /* Return IPv4 mapped and IPv6 addresses.  */
+# define AI_ADDRCONFIG  0x0020  /* Use configuration of this host to choose
+                                   returned address type..  */
+# ifdef __USE_GNU
+#  define AI_IDN        0x0040  /* IDN encode input (assuming it is encoded
+                                   in the current locale's character set)
+                                   before looking it up. */
+#  define AI_CANONIDN   0x0080  /* Translate canonical name from IDN format. */
+#  define AI_IDN_ALLOW_UNASSIGNED 0x0100 /* Don't reject unassigned Unicode
+                                            code points.  */
+#  define AI_IDN_USE_STD3_ASCII_RULES 0x0200 /* Validate strings according to
+                                                STD3 rules.  */
+# endif
+# define AI_NUMERICSERV 0x0400  /* Don't use name resolution.  */
 
-/*
- * Flags for getnameinfo().
- */
-#define NI_DGRAM	0x0001
-#define NI_NAMEREQD	0x0002
-#define NI_NOFQDN	0x0004
-#define NI_NUMERICHOST	0x0008
-#define NI_NUMERICSCOPE	0x0010
-#define NI_NUMERICSERV	0x0020
+/* Error values for `getaddrinfo' function.  */
+# define EAI_BADFLAGS     -1    /* Invalid value for `ai_flags' field.  */
+# define EAI_NONAME       -2    /* NAME or SERVICE is unknown.  */
+# define EAI_AGAIN        -3    /* Temporary failure in name resolution.  */
+# define EAI_FAIL         -4    /* Non-recoverable failure in name res.  */
+# define EAI_NODATA       -5    /* No address associated with NAME.  */
+# define EAI_FAMILY       -6    /* `ai_family' not supported.  */
+# define EAI_SOCKTYPE     -7    /* `ai_socktype' not supported.  */
+# define EAI_SERVICE      -8    /* SERVICE not supported for `ai_socktype'.  */
+# define EAI_ADDRFAMILY   -9    /* Address family for NAME not supported.  */
+# define EAI_MEMORY       -10   /* Memory allocation failure.  */
+# define EAI_SYSTEM       -11   /* System error returned in `errno'.  */
+# define EAI_OVERFLOW     -12   /* Argument buffer overflow.  */
+# ifdef __USE_GNU
+#  define EAI_INPROGRESS  -100  /* Processing request in progress.  */
+#  define EAI_CANCELED    -101  /* Request canceled.  */
+#  define EAI_NOTCANCELED -102  /* Request not canceled.  */
+#  define EAI_ALLDONE     -103  /* All requests done.  */
+#  define EAI_INTR        -104  /* Interrupted by a signal.  */
+#  define EAI_IDN_ENCODE  -105  /* IDN encoding failed.  */
+# endif
 
-/*
- * Maximum length of FQDN and servie name for getnameinfo().
- */
 #define NI_MAXHOST	1025
 #define NI_MAXSERV	32
 
+# define NI_NUMERICHOST 1       /* Don't try to look up hostname.  */
+# define NI_NUMERICSERV 2       /* Don't convert port number to name.  */
+# define NI_NOFQDN      4       /* Only return nodename portion.  */
+# define NI_NAMEREQD    8       /* Don't return numeric addresses.  */
+# define NI_DGRAM       16      /* Look up UDP service rather than TCP.  */
+# ifdef __USE_GNU
+#  define NI_IDN        32      /* Convert name from IDN format.  */
+#  define NI_IDN_ALLOW_UNASSIGNED 64 /* Don't reject unassigned Unicode
+                                        code points.  */
+#  define NI_IDN_USE_STD3_ASCII_RULES 128 /* Validate strings according to
+                                             STD3 rules.  */
+# endif
+# </from linux's netdb.h>
+
+#define AI_DEFAULT	(AI_V4MAPPED | AI_ADDRCONFIG)
+
 /*
  * Address families and Protocol families.
  */