bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: removing asctime_r, ctime_r from the time_r module


From: Paul Eggert
Subject: Re: removing asctime_r, ctime_r from the time_r module
Date: Sun, 12 Mar 2006 00:09:29 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

Jim Meyering <address@hidden> writes:

> Good idea.
> Thanks for doing that.

OK, I've checked it into gnulib.  I've also copied gnulib/m4/time_r.m4
into coreutils and made the obvious corresponding changes.  Here's the
diff, for coreutils:

2006-03-12  Paul Eggert  <address@hidden>

        * lib/Makefile.am (libcoreutils_a_SOURCES): Remove time_r.c, time_r.h,
        as this is now done in m4.
        * lib/time_r.h (asctime_r, ctime_r): Remove.  These functions can
        overrun buffers and shouldn't be used (much as gets shouldn't be
        used).
        * lib/time_r.c (asctime_r, ctime_r): Likewise.
        * m4/prereq.m4 (gl_PREREQ): Require gl_TIME_R.
        * m4/time_r.m4: New file, from gnulib.

Index: lib/Makefile.am
===================================================================
RCS file: /fetish/cu/lib/Makefile.am,v
retrieving revision 1.243
diff -p -u -r1.243 Makefile.am
--- lib/Makefile.am     27 Feb 2006 10:49:40 -0000      1.243
+++ lib/Makefile.am     12 Mar 2006 08:02:45 -0000
@@ -45,7 +45,6 @@ libcoreutils_a_SOURCES = \
   strcase.h \
   strnlen1.c strnlen1.h \
   strstr.h \
-  time_r.c time_r.h \
   unicodeio.c unicodeio.h \
   verify.h \
   xalloc-die.c \
Index: lib/time_r.c
===================================================================
RCS file: /fetish/cu/lib/time_r.c,v
retrieving revision 1.3
diff -p -u -r1.3 time_r.c
--- lib/time_r.c        22 Sep 2005 06:05:39 -0000      1.3
+++ lib/time_r.c        12 Mar 2006 08:02:45 -0000
@@ -1,6 +1,6 @@
 /* Reentrant time functions like localtime_r.
 
-   Copyright (C) 2003 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2006 Free Software Foundation, Inc.
 
    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
@@ -44,18 +44,6 @@ copy_tm_result (struct tm *dest, struct 
 }
 
 
-char *
-asctime_r (struct tm const * restrict tm, char * restrict buf)
-{
-  return copy_string_result (buf, asctime (tm));
-}
-
-char *
-ctime_r (time_t const *t, char *buf)
-{
-  return copy_string_result (buf, ctime (t));
-}
-
 struct tm *
 gmtime_r (time_t const * restrict t, struct tm * restrict tp)
 {
Index: lib/time_r.h
===================================================================
RCS file: /fetish/cu/lib/time_r.h,v
retrieving revision 1.3
diff -p -u -r1.3 time_r.h
--- lib/time_r.h        22 Sep 2005 06:05:39 -0000      1.3
+++ lib/time_r.h        12 Mar 2006 08:02:45 -0000
@@ -1,6 +1,6 @@
 /* Reentrant time functions like localtime_r.
 
-   Copyright (C) 2003, 2005 Free Software Foundation, Inc.
+   Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc.
 
    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
@@ -27,25 +27,20 @@
 #include <time.h>
 
 #if !HAVE_TIME_R_POSIX
-# undef asctime_r
-# undef ctime_r
+
+/* Don't bother with asctime_r and ctime_r, since these functions are
+   not safe (like asctime and ctime, they can overrun their 26-byte
+   output buffers when given outlandish struct tm values), and we
+   don't want to encourage applications to use unsafe functions.  Use
+   strftime or even sprintf instead.  */
+
 # undef gmtime_r
 # undef localtime_r
 
-# define asctime_r rpl_asctime_r
-# define ctime_r rpl_ctime_r
 # define gmtime_r rpl_gmtime_r
 # define localtime_r rpl_localtime_r
 
 /* See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/asctime.html>.  */
-char *asctime_r (struct tm const * restrict, char * restrict);
-
-/* See the POSIX:2001 specification
-   <http://www.opengroup.org/susv3xsh/ctime.html>.  */
-char *ctime_r (time_t const *, char *);
-
-/* See the POSIX:2001 specification
    <http://www.opengroup.org/susv3xsh/gmtime.html>.  */
 struct tm *gmtime_r (time_t const * restrict, struct tm * restrict);
 
Index: m4/prereq.m4
===================================================================
RCS file: /fetish/cu/m4/prereq.m4,v
retrieving revision 1.123
diff -p -u -r1.123 prereq.m4
--- m4/prereq.m4        12 Jan 2006 07:19:00 -0000      1.123
+++ m4/prereq.m4        12 Mar 2006 08:02:45 -0000
@@ -146,6 +146,7 @@ AC_DEFUN([gl_PREREQ],
   AC_REQUIRE([gl_STRNUMCMP])
   AC_REQUIRE([gl_STRIPSLASH])
   AC_REQUIRE([gl_TIMESPEC])
+  AC_REQUIRE([gl_TIME_R])
   AC_REQUIRE([gl_UNICODEIO])
   AC_REQUIRE([gl_UNISTD_SAFER])
   AC_REQUIRE([gl_UNLINKDIR])
--- /dev/null   2005-09-24 22:00:15.000000000 -0700
+++ m4/time_r.m4        2006-03-10 01:35:45.000000000 -0800
@@ -0,0 +1,38 @@
+dnl Reentrant time functions like localtime_r.
+
+dnl Copyright (C) 2003 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl_TIME_R],
+[
+  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+  AC_REQUIRE([gl_C_RESTRICT])
+
+  AC_CACHE_CHECK([whether localtime_r is compatible with its POSIX signature],
+    [gl_cv_time_r_posix],
+    [AC_TRY_COMPILE(
+       [#include <time.h>],
+       [/* We don't need to append 'restrict's to the argument types,
+          even though the POSIX signature has the 'restrict's,
+          since C99 says they can't affect type compatibility.  */
+       struct tm * (*ptr) (time_t const *, struct tm *) = localtime_r;],
+       [gl_cv_time_r_posix=yes],
+       [gl_cv_time_r_posix=no])])
+  if test $gl_cv_time_r_posix = yes; then
+    AC_DEFINE([HAVE_TIME_R_POSIX], 1,
+      [Define to 1 if localtime_r, etc. have the type signatures that
+       POSIX requires.])
+  else
+    AC_LIBOBJ([time_r])
+    gl_PREREQ_TIME_R
+  fi
+])
+
+# Prerequisites of lib/time_r.c.
+AC_DEFUN([gl_PREREQ_TIME_R], [
+  :
+])




reply via email to

[Prev in Thread] Current Thread [Next in Thread]