This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gettimeofday and POSIX


Hi Eric,

How about the attached patch instead? It goes through and cleans up all the implementations as well so there is no need for the flag check.

-- Jeff J.

Eric Blake wrote:
gnulib projects that use gettimeofday currently crash when configured with
-Werror [1], because gettimeofday has the wrong signature according to
POSIX rules.  OK to apply this patch?

[1] http://lists.gnu.org/archive/html/bug-gnulib/2007-07/msg00063.html

2007-07-05 Eric Blake <ebb9@byu.net>

	* libc/include/sys/time.h (gettimeofday): Make signature match
	POSIX.

Index: libc/include/sys/time.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/time.h,v
retrieving revision 1.10
diff -u -p -b -r1.10 time.h
--- libc/include/sys/time.h	15 Feb 2006 10:26:30 -0000	1.10
+++ libc/include/sys/time.h	5 Jul 2007 14:31:08 -0000
@@ -70,7 +70,11 @@ struct  itimerval {
   } while (0)
 #endif /* defined (__rtems__) || defined (__CYGWIN__) */

+#ifdef _COMPILING_NEWLIB
 int _EXFUN(gettimeofday, (struct timeval *__p, struct timezone *__z));
+#else
+int _EXFUN(gettimeofday, (struct timeval *__p, void *__z));
+#endif
 int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *));
 int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp));
 int _EXFUN(getitimer, (int __which, struct itimerval *__value));


Index: libgloss/arm/syscalls.c
===================================================================
RCS file: /cvs/src/src/libgloss/arm/syscalls.c,v
retrieving revision 1.14
diff -u -p -r1.14 syscalls.c
--- libgloss/arm/syscalls.c	3 Jan 2007 16:55:25 -0000	1.14
+++ libgloss/arm/syscalls.c	5 Jul 2007 17:48:54 -0000
@@ -22,7 +22,7 @@ int     _system     _PARAMS ((const char
 int     _rename     _PARAMS ((const char *, const char *));
 int     _isatty		_PARAMS ((int));
 clock_t _times		_PARAMS ((struct tms *));
-int     _gettimeofday	_PARAMS ((struct timeval *, struct timezone *));
+int     _gettimeofday	_PARAMS ((struct timeval *, void *));
 int     _unlink		_PARAMS ((const char *));
 int     _link 		_PARAMS ((void));
 int     _stat 		_PARAMS ((const char *, struct stat *));
@@ -525,9 +525,9 @@ _unlink (const char *path)
 }
 
 int
-_gettimeofday (struct timeval * tp, struct timezone * tzp)
+_gettimeofday (struct timeval * tp, void * tzvp)
 {
-
+  struct timezone *tzp = (struct timezone *)tzvp;
   if (tp)
     {
     /* Ask the host for the seconds since the Unix epoch.  */
Index: libgloss/bfin/syscalls.c
===================================================================
RCS file: /cvs/src/src/libgloss/bfin/syscalls.c,v
retrieving revision 1.1
diff -u -p -r1.1 syscalls.c
--- libgloss/bfin/syscalls.c	8 Nov 2006 19:36:56 -0000	1.1
+++ libgloss/bfin/syscalls.c	5 Jul 2007 17:48:54 -0000
@@ -196,7 +196,7 @@ _raise (void)
 }
 
 int
-_gettimeofday (struct timeval *tv, struct timezone *tz)
+_gettimeofday (struct timeval *tv, void *tz)
 {
   tv->tv_usec = 0;
   tv->tv_sec = do_syscall (SYS_time, 0);
Index: libgloss/cris/gensyscalls
===================================================================
RCS file: /cvs/src/src/libgloss/cris/gensyscalls,v
retrieving revision 1.1
diff -u -p -r1.1 gensyscalls
--- libgloss/cris/gensyscalls	27 Jan 2005 22:57:32 -0000	1.1
+++ libgloss/cris/gensyscalls	5 Jul 2007 17:48:54 -0000
@@ -93,7 +93,7 @@ cat > gettod.c <<EOF
 $lu#include <sys/time.h>
 #include <sys/times.h>
 int
-_gettimeofday (struct timeval *tp, struct timezone *tzp
+_gettimeofday (struct timeval *tp, void *tzp
 ${r}gettimeofday (tp, tzp))
 EOF
 cat > isatty.c <<EOF
Index: libgloss/cris/linunistd.h
===================================================================
RCS file: /cvs/src/src/libgloss/cris/linunistd.h,v
retrieving revision 1.2
diff -u -p -r1.2 linunistd.h
--- libgloss/cris/linunistd.h	17 Nov 2005 12:01:44 -0000	1.2
+++ libgloss/cris/linunistd.h	5 Jul 2007 17:48:54 -0000
@@ -413,7 +413,7 @@ static inline _syscall1(long,mmap,long *
 struct timeval;
 struct timezone;
 static inline _syscall2(int,gettimeofday,struct timeval *,tp,
-                        struct timezone *, tzp)
+                        void *, tzp)
 static inline _syscall2(int,link,const char *,old,const char *,new)
 static inline _syscall1(int,unlink,const char *, f)
 struct rusage;
Index: libgloss/crx/time.c
===================================================================
RCS file: /cvs/src/src/libgloss/crx/time.c,v
retrieving revision 1.1
diff -u -p -r1.1 time.c
--- libgloss/crx/time.c	5 Oct 2004 20:00:53 -0000	1.1
+++ libgloss/crx/time.c	5 Jul 2007 17:48:54 -0000
@@ -43,8 +43,9 @@ clock_t times (struct tms *buf)
 }
 
 /* _gettimeofday -- implement in terms of time.  */
-int gettimeofday (struct timeval *tv, struct timezone *tz)
+int gettimeofday (struct timeval *tv, void *tzvp)
 {
+  struct time *tz = (struct timezone *)tzvp;
   if (tz)
     tz->tz_minuteswest = tz->tz_dsttime = 0;
 
Index: libgloss/frv/sim-time.c
===================================================================
RCS file: /cvs/src/src/libgloss/frv/sim-time.c,v
retrieving revision 1.1
diff -u -p -r1.1 sim-time.c
--- libgloss/frv/sim-time.c	18 Jun 2002 21:19:17 -0000	1.1
+++ libgloss/frv/sim-time.c	5 Jul 2007 17:48:54 -0000
@@ -67,8 +67,9 @@ _DEFUN (_times, _times (buf),
 int
 _DEFUN (_gettimeofday, _gettimeofday (tv, tz),
 	struct timeval *tv _AND
-	struct timezone *tz)
+	void *tzvp)
 {
+  struct timezone *tz = (struct timezone *)tzvp;
   if (tz)
     tz->tz_minuteswest = tz->tz_dsttime = 0;
 
Index: libgloss/i386/cygmon-salib.c
===================================================================
RCS file: /cvs/src/src/libgloss/i386/cygmon-salib.c,v
retrieving revision 1.3
diff -u -p -r1.3 cygmon-salib.c
--- libgloss/i386/cygmon-salib.c	12 Aug 2003 18:06:01 -0000	1.3
+++ libgloss/i386/cygmon-salib.c	5 Jul 2007 17:48:54 -0000
@@ -40,7 +40,7 @@ _syscall1(char **,__get_program_argument
 _syscall1(void,__sys_exit,int,exitcode);
 _syscall1(void,putTtyChar,int,character);
 _syscall1(time_t,time,time_t *,ptr);
-_syscall2(int, gettimeofday, struct timeval *,time, struct timezone *,z);
+_syscall2(int, gettimeofday, struct timeval *,time, void *,z);
 _syscall3(int, __open, const char *, filename, int, mode, int, filemode);
 _syscall4(void, profil, unsigned short *, buff, unsigned int, bufsiz,
 	  unsigned int, offset, unsigned int, scale);
Index: libgloss/libnosys/gettod.c
===================================================================
RCS file: /cvs/src/src/libgloss/libnosys/gettod.c,v
retrieving revision 1.1
diff -u -p -r1.1 gettod.c
--- libgloss/libnosys/gettod.c	17 Mar 2000 22:48:50 -0000	1.1
+++ libgloss/libnosys/gettod.c	5 Jul 2007 17:48:54 -0000
@@ -18,7 +18,7 @@ struct timezone;
 int
 _DEFUN (_gettimeofday, (ptimeval, ptimezone),
         struct timeval  *ptimeval  _AND
-        struct timezone *ptimezone)
+        void *ptimezone)
 {
   errno = ENOSYS;
   return -1;
Index: libgloss/m68k/io-gettimeofday.c
===================================================================
RCS file: /cvs/src/src/libgloss/m68k/io-gettimeofday.c,v
retrieving revision 1.2
diff -u -p -r1.2 io-gettimeofday.c
--- libgloss/m68k/io-gettimeofday.c	11 Dec 2006 19:58:01 -0000	1.2
+++ libgloss/m68k/io-gettimeofday.c	5 Jul 2007 17:48:54 -0000
@@ -28,11 +28,12 @@
  *   1 : errno
  */
 
-int gettimeofday (struct timeval *tv, struct timezone *tz)
+int gettimeofday (struct timeval *tv, void *tzvp)
 {
 #if HOSTED
   gdb_parambuf_t parameters;
   struct gdb_timeval gtv;
+  struct timezone *tz = (struct timezone *)tzvp;
   if (!tv)
     return 0;
   if (tz)
Index: libgloss/sparc/cygmon-salib.c
===================================================================
RCS file: /cvs/src/src/libgloss/sparc/cygmon-salib.c,v
retrieving revision 1.2
diff -u -p -r1.2 cygmon-salib.c
--- libgloss/sparc/cygmon-salib.c	17 Apr 2002 17:29:02 -0000	1.2
+++ libgloss/sparc/cygmon-salib.c	5 Jul 2007 17:48:54 -0000
@@ -168,7 +168,7 @@ __install_signal_handler (void *func)
 }
 
 int
-gettimeofday (struct timeval *tp, struct timezone *tzp)
+gettimeofday (struct timeval *tp, void *tzp)
 {
   asm ("or %g0, 156, %g1	\n\
 	ta 8			\n\
Index: libgloss/spu/gettimeofday.c
===================================================================
RCS file: /cvs/src/src/libgloss/spu/gettimeofday.c,v
retrieving revision 1.4
diff -u -p -r1.4 gettimeofday.c
--- libgloss/spu/gettimeofday.c	5 Jun 2007 19:01:30 -0000	1.4
+++ libgloss/spu/gettimeofday.c	5 Jul 2007 17:48:54 -0000
@@ -43,7 +43,7 @@ typedef struct
 } syscall_gettimeofday_t;
 
 int
-gettimeofday (struct timeval *tv, struct timezone *tz)
+gettimeofday (struct timeval *tv, void *tz)
 {
 	syscall_gettimeofday_t sys;
 
Index: newlib/libc/include/reent.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/reent.h,v
retrieving revision 1.5
diff -u -p -r1.5 reent.h
--- newlib/libc/include/reent.h	27 Aug 2003 16:24:57 -0000	1.5
+++ newlib/libc/include/reent.h	5 Jul 2007 17:48:54 -0000
@@ -80,7 +80,7 @@ extern int _wait_r _PARAMS ((struct _ree
 extern _ssize_t _write_r _PARAMS ((struct _reent *, int, const void *, size_t));
 
 /* This one is not guaranteed to be available on all targets.  */
-extern int _gettimeofday_r _PARAMS ((struct _reent *, struct timeval *tp, struct timezone *tzp));
+extern int _gettimeofday_r _PARAMS ((struct _reent *, struct timeval *__tp, void *__tzp));
 
 #ifdef __LARGE64_FILES
 
Index: newlib/libc/include/sys/time.h
===================================================================
RCS file: /cvs/src/src/newlib/libc/include/sys/time.h,v
retrieving revision 1.10
diff -u -p -r1.10 time.h
--- newlib/libc/include/sys/time.h	15 Feb 2006 10:26:30 -0000	1.10
+++ newlib/libc/include/sys/time.h	5 Jul 2007 17:48:54 -0000
@@ -70,7 +70,7 @@ struct  itimerval {
   } while (0)
 #endif /* defined (__rtems__) || defined (__CYGWIN__) */
 
-int _EXFUN(gettimeofday, (struct timeval *__p, struct timezone *__z));
+int _EXFUN(gettimeofday, (struct timeval *__p, void *__tz));
 int _EXFUN(settimeofday, (const struct timeval *, const struct timezone *));
 int _EXFUN(utimes, (const char *__path, const struct timeval *__tvp));
 int _EXFUN(getitimer, (int __which, struct itimerval *__value));
Index: newlib/libc/reent/gettimeofdayr.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/reent/gettimeofdayr.c,v
retrieving revision 1.1
diff -u -p -r1.1 gettimeofdayr.c
--- newlib/libc/reent/gettimeofdayr.c	21 Feb 2007 19:22:33 -0000	1.1
+++ newlib/libc/reent/gettimeofdayr.c	5 Jul 2007 17:48:58 -0000
@@ -40,7 +40,7 @@ ANSI_SYNOPSIS
 	#include <time.h>
 	int _gettimeofday_r(struct _reent *<[ptr]>,
 		struct timeval *<[ptimeval]>,
-		struct timezone *<[ptimezone]>);
+		void *<[ptimezone]>);
 
 TRAD_SYNOPSIS
 	#include <reent.h>
@@ -48,7 +48,7 @@ TRAD_SYNOPSIS
 	int _gettimeofday_r(<[ptr]>, <[ptimeval]>, <[ptimezone]>)
 	struct _reent *<[ptr]>;
 	struct timeval *<[ptimeval]>;
-	struct timezone *<[ptimezone]>;
+	void *<[ptimezone]>;
 
 DESCRIPTION
 	This is a reentrant version of <<gettimeofday>>.  It
@@ -63,7 +63,7 @@ int
 _DEFUN (_gettimeofday_r, (ptr, ptimeval, ptimezone),
      struct _reent *ptr _AND
      struct timeval *ptimeval _AND
-     struct timezone *ptimezone)
+     void *ptimezone)
 {
   int ret;
 
Index: newlib/libc/sys/arm/syscalls.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/arm/syscalls.c,v
retrieving revision 1.13
diff -u -p -r1.13 syscalls.c
--- newlib/libc/sys/arm/syscalls.c	13 Jun 2006 20:50:24 -0000	1.13
+++ newlib/libc/sys/arm/syscalls.c	5 Jul 2007 17:48:58 -0000
@@ -22,7 +22,7 @@ int     _system     _PARAMS ((const char
 int     _rename     _PARAMS ((const char *, const char *));
 int     isatty		_PARAMS ((int));
 clock_t _times		_PARAMS ((struct tms *));
-int     _gettimeofday	_PARAMS ((struct timeval *, struct timezone *));
+int     _gettimeofday	_PARAMS ((struct timeval *, void *));
 void    _raise 		_PARAMS ((void));
 int     _unlink		_PARAMS ((const char *));
 int     _link 		_PARAMS ((void));
@@ -559,9 +559,9 @@ _raise (void)
 }
 
 int
-_gettimeofday (struct timeval * tp, struct timezone * tzp)
+_gettimeofday (struct timeval * tp, void * tzvp)
 {
-
+  struct timezone *tzp = (struct timezone *)tzvp;
   if (tp)
     {
     /* Ask the host for the seconds since the Unix epoch.  */
Index: newlib/libc/sys/rdos/gettod.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/rdos/gettod.c,v
retrieving revision 1.1
diff -u -p -r1.1 gettod.c
--- newlib/libc/sys/rdos/gettod.c	31 Jan 2006 19:33:56 -0000	1.1
+++ newlib/libc/sys/rdos/gettod.c	5 Jul 2007 17:48:58 -0000
@@ -8,7 +8,7 @@
 struct timeval;
 struct timezone;
 
-int gettimeofday(struct timeval *ptimeval, struct timezone *ptimezone)
+int gettimeofday(struct timeval *ptimeval, void *ptimezone)
 {
   errno = ENOSYS;
   return -1;
Index: newlib/libc/sys/sh/syscalls.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/sys/sh/syscalls.c,v
retrieving revision 1.5
diff -u -p -r1.5 syscalls.c
--- newlib/libc/sys/sh/syscalls.c	1 Feb 2001 21:25:56 -0000	1.5
+++ newlib/libc/sys/sh/syscalls.c	5 Jul 2007 17:48:58 -0000
@@ -185,7 +185,7 @@ _times (struct tms *tp)
 }
 
 int
-_gettimeofday (struct timeval *tv, struct timezone *tz)
+_gettimeofday (struct timeval *tv, void *tz)
 {
   tv->tv_usec = 0;
   tv->tv_sec = __trap34 (SYS_time);
Index: newlib/libc/time/time.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/time/time.c,v
retrieving revision 1.2
diff -u -p -r1.2 time.c
--- newlib/libc/time/time.c	7 Apr 2006 21:46:00 -0000	1.2
+++ newlib/libc/time/time.c	5 Jul 2007 17:48:58 -0000
@@ -43,7 +43,7 @@ _DEFUN (time, (t),
 {
   struct timeval now;
 
-  if (_gettimeofday_r (_REENT, &now, (struct timezone *) 0) >= 0)
+  if (_gettimeofday_r (_REENT, &now, NULL) >= 0)
     {
       if (t)
 	*t = now.tv_sec;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]