Merge commit 'a7bbba05838cabe2294f498e7008e1c51db6d664'
[bpt/guile.git] / libguile / stime.c
index 1c4f407..f656d88 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2011 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1997,1998,1999,2000,2001, 2003, 2004, 2005, 2006,
+ *   2007, 2008, 2009, 2011, 2013, 2014 Free Software Foundation, Inc.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public License
 #include "libguile/validate.h"
 #include "libguile/stime.h"
 
-#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-#endif
 
 \f
 #ifdef HAVE_CLOCK_GETTIME
 # include <time.h>
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_STRING_H
+#include <sys/types.h>
 #include <string.h>
-#endif
-
-#ifdef HAVE_SYS_TIMES_H
-# include <sys/times.h>
-#endif
+#include <sys/times.h>
 
 #ifdef HAVE_SYS_TIMEB_H
 # include <sys/timeb.h>
 #endif
 
-#ifndef tzname /* For SGI.  */
-extern char *tzname[]; /* RS6000 and others reject char **tzname.  */
-#endif
-#if defined (__MINGW32__)
-# define tzname _tzname
-#endif
-
 #if ! HAVE_DECL_STRPTIME
 extern char *strptime ();
 #endif
@@ -142,7 +126,11 @@ get_internal_real_time_posix_timer (void)
      ts.tv_nsec - posix_real_time_base.tv_nsec);
 }
 
-#ifdef _POSIX_CPUTIME
+#if defined _POSIX_CPUTIME && defined CLOCK_PROCESS_CPUTIME_ID
+/* You see, FreeBSD defines _POSIX_CPUTIME but not
+   CLOCK_PROCESS_CPUTIME_ID.  */
+#define HAVE_POSIX_CPUTIME 1
+
 struct timespec posix_run_time_base;
 
 static long
@@ -173,7 +161,6 @@ get_internal_real_time_gettimeofday (void)
 #endif
 
 
-#if defined HAVE_TIMES
 static long ticks_per_second;
 
 static long
@@ -184,7 +171,6 @@ get_internal_run_time_times (void)
   return (time_buffer.tms_utime + time_buffer.tms_stime)
     * TIME_UNITS_PER_SECOND / ticks_per_second;
 }
-#endif
 
 static timet fallback_real_time_base;
 static long
@@ -206,7 +192,6 @@ SCM_DEFINE (scm_get_internal_real_time, "get-internal-real-time", 0, 0, 0,
 #undef FUNC_NAME
 
 
-#ifdef HAVE_TIMES
 SCM_DEFINE (scm_times, "times", 0, 0, 0,
             (void),
            "Return an object with information about real and processor\n"
@@ -257,7 +242,6 @@ SCM_DEFINE (scm_times, "times", 0, 0, 0,
   return result;
 }
 #undef FUNC_NAME
-#endif /* HAVE_TIMES */
 
 long
 scm_c_get_internal_run_time (void)
@@ -521,7 +505,7 @@ SCM_DEFINE (scm_gmtime, "gmtime", 1, 0, 0,
 static void
 bdtime2c (SCM sbd_time, struct tm *lt, int pos, const char *subr)
 {
-  SCM_ASSERT (scm_is_simple_vector (sbd_time)
+  SCM_ASSERT (scm_is_vector (sbd_time)
              && SCM_SIMPLE_VECTOR_LENGTH (sbd_time) == 11,
              sbd_time, pos, subr);
 
@@ -547,13 +531,14 @@ bdtime2c (SCM sbd_time, struct tm *lt, int pos, const char *subr)
 
 SCM_DEFINE (scm_mktime, "mktime", 1, 1, 0,
             (SCM sbd_time, SCM zone),
-           "@var{bd-time} is an object representing broken down time and @code{zone}\n"
-           "is an optional time zone specifier (otherwise the TZ environment variable\n"
-           "or the system default is used).\n\n"
-           "Returns a pair: the car is a corresponding\n"
-           "integer time value like that returned\n"
-           "by @code{current-time}; the cdr is a broken down time object, similar to\n"
-           "as @var{bd-time} but with normalized values.")
+           "@var{sbd_time} is an object representing broken down time and\n"
+           "@code{zone} is an optional time zone specifier (otherwise the\n"
+           "TZ environment variable or the system default is used).\n"
+           "\n"
+           "Returns a pair: the car is a corresponding integer time value\n"
+           "like that returned by @code{current-time}; the cdr is a broken\n"
+           "down time object, similar to as @var{sbd_time} but with\n"
+           "normalized values.")
 #define FUNC_NAME s_scm_mktime
 {
   timet itime;
@@ -759,7 +744,7 @@ SCM_DEFINE (scm_strptime, "strptime", 2, 0, 0,
             (SCM format, SCM string),
            "Performs the reverse action to @code{strftime}, parsing\n"
            "@var{string} according to the specification supplied in\n"
-           "@var{template}.  The interpretation of month and day names is\n"
+           "@var{format}.  The interpretation of month and day names is\n"
            "dependent on the current locale.  The value returned is a pair.\n"
            "The car has an object with time components\n"
            "in the form returned by @code{localtime} or @code{gmtime},\n"
@@ -847,7 +832,7 @@ scm_init_stime()
   if (clock_gettime (CLOCK_REALTIME, &posix_real_time_base) == 0)
     get_internal_real_time = get_internal_real_time_posix_timer;
 
-#ifdef _POSIX_CPUTIME
+#ifdef HAVE_POSIX_CPUTIME
   {
     clockid_t dummy;
     
@@ -859,7 +844,7 @@ scm_init_stime()
     else
       errno = 0;
   }
-#endif /* _POSIX_CPUTIME */
+#endif /* HAVE_POSIX_CPUTIME */
 #endif /* HAVE_CLOCKTIME */
 
   /* If needed, init and use gettimeofday timer. */
@@ -871,7 +856,6 @@ scm_init_stime()
 
   /* Init ticks_per_second for scm_times, and use times(2)-based
      run-time timer if needed. */
-#ifdef HAVE_TIMES
 #ifdef _SC_CLK_TCK
   ticks_per_second = sysconf (_SC_CLK_TCK);
 #else
@@ -879,7 +863,6 @@ scm_init_stime()
 #endif
   if (!get_internal_run_time)
     get_internal_run_time = get_internal_run_time_times;
-#endif
 
   if (!get_internal_real_time)
     /* No POSIX timers, gettimeofday doesn't work... badness!  */
@@ -888,10 +871,6 @@ scm_init_stime()
       get_internal_real_time = get_internal_real_time_fallback;
     }
 
-  /* If we don't have a run-time timer, use real-time.  */
-  if (!get_internal_run_time)
-    get_internal_run_time = get_internal_real_time;
-
   scm_add_feature ("current-time");
 #include "libguile/stime.x"
 }