Remove AFS_PARISC_LINUX24_ENV references
[openafs.git] / src / lwp / fasttime.c
index 71eb741..0fced09 100644 (file)
@@ -1,27 +1,12 @@
-
-#ifndef lint
-#endif
-
 /*
-****************************************************************************
-*        Copyright IBM Corporation 1988, 1989 - All Rights Reserved        *
-*                                                                          *
-* Permission to use, copy, modify, and distribute this software and its    *
-* documentation for any purpose and without fee is hereby granted,         *
-* provided that the above copyright notice appear in all copies and        *
-* that both that copyright notice and this permission notice appear in     *
-* supporting documentation, and that the name of IBM not be used in        *
-* advertising or publicity pertaining to distribution of the software      *
-* without specific, written prior permission.                              *
-*                                                                          *
-* IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
-* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
-* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY      *
-* DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER  *
-* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING   *
-* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.    *
-****************************************************************************
-*/
+ * Copyright 2000, International Business Machines Corporation and others.
+ * All Rights Reserved.
+ *
+ * This software has been released under the terms of the IBM Public
+ * License.  For details, see the LICENSE file in the top-level source
+ * directory or online at http://www.openafs.org/dl/license10.html
+ */
+
 /*
  *     fasttime.c -- Get the time of day quickly by mapping the kernel's
  *                   time of day variable.
  *               This saves a (precious) file descriptor.
  */
 
+#include <afsconfig.h>
 #include <afs/param.h>
-#include <stdio.h>
-#include <sys/types.h>
-#ifdef AFS_NT40_ENV
-#include <sys/timeb.h>
-#include <winsock2.h>
-#else
-#include <sys/time.h>
-#include <sys/file.h>
-#endif
-#if !defined(AFS_AIX_ENV) && !defined(AFS_NT40_ENV)
-#include <sys/mman.h>
-#endif
-#include <afs/afsutil.h>
 
-extern char *valloc ();
+#include <roken.h>
+
 int ft_debug;
 
 #define TRUE   1
@@ -62,7 +36,7 @@ int ft_debug;
 static enum InitState { notTried, tried, done } initState = notTried;
 
 struct timeval FT_LastTime;    /* last time returned by RT_FastTime.  Used to implement
-                                  FT_ApproxTime */
+                                * FT_ApproxTime */
 
 
 /* Call this to get the memory mapped.  It will return -1 if anything went
@@ -73,17 +47,18 @@ struct timeval FT_LastTime; /* last time returned by RT_FastTime.  Used to imple
    You might want this if your program won't run too long and the nlist
    call is too expensive.  Yeah, it's pretty horrible.
 */
-int FT_Init (int printErrors, int notReally)
+int
+FT_Init(int printErrors, int notReally)
 {
     if (initState != notTried && !notReally)
-       return (initState == done? 0: -1);      /* This is in case explicit initialization
-                                                  occurs after automatic initialization */
+       return (initState == done ? 0 : -1);    /* This is in case explicit initialization
+                                                * occurs after automatic initialization */
     initState = tried;
     if (notReally)
        return 0;               /* fake success, but leave initState
-                                  wrong. */
+                                * wrong. */
     if (printErrors)
-       fprintf (stderr, "FT_Init: mmap  not implemented on this kernel\n");
+       fprintf(stderr, "FT_Init: mmap  not implemented on this kernel\n");
     return (-1);
 }
 
@@ -92,17 +67,20 @@ int FT_Init (int printErrors, int notReally)
    call FT_Init yourself.  If the initialization failed, this will just
    call gettimeofday.  If you ask for the timezone info, this routine will
    punt to gettimeofday. */
-int FT_GetTimeOfDay(struct timeval *tv, struct timezone *tz)
+int
+FT_GetTimeOfDay(struct timeval *tv, struct timezone *tz)
 {
-    register int ret;
-    ret = gettimeofday (tv, tz);
+    int ret;
+    ret = gettimeofday(tv, tz);
     if (!ret) {
        /* need to bounds check 'cause Unix can fail these checks, (esp on Suns)
-           and time package can generate invalid (to select syscall) values
-           for the time until the next interesting event if it encounters
-           out of range microsecond fields */
-       if (tv->tv_usec < 0) tv->tv_usec = 0;
-       if (tv->tv_usec > 999999) tv->tv_usec = 999999;
+        * and time package can generate invalid (to select syscall) values
+        * for the time until the next interesting event if it encounters
+        * out of range microsecond fields */
+       if (tv->tv_usec < 0)
+           tv->tv_usec = 0;
+       if (tv->tv_usec > 999999)
+           tv->tv_usec = 999999;
        FT_LastTime.tv_sec = tv->tv_sec;
        FT_LastTime.tv_usec = tv->tv_usec;
     }
@@ -111,14 +89,14 @@ int FT_GetTimeOfDay(struct timeval *tv, struct timezone *tz)
 
 
 /* For compatibility.  Should go away. */
-TM_GetTimeOfDay (tv, tz)
-    struct timeval *tv;
-    struct timezone *tz;
+int
+TM_GetTimeOfDay(struct timeval *tv, struct timezone *tz)
 {
     return FT_GetTimeOfDay(tv, tz);
 }
 
-int FT_AGetTimeOfDay(struct timeval *tv, struct timezone *tz)
+int
+FT_AGetTimeOfDay(struct timeval *tv, struct timezone *tz)
 {
     if (FT_LastTime.tv_sec) {
        tv->tv_sec = FT_LastTime.tv_sec;
@@ -128,10 +106,18 @@ int FT_AGetTimeOfDay(struct timeval *tv, struct timezone *tz)
     return FT_GetTimeOfDay(tv, tz);
 }
 
+#ifdef AFS_PTHREAD_ENV
 unsigned int FT_ApproxTime(void)
 {
+    return time(0);
+}
+#else
+unsigned int
+FT_ApproxTime(void)
+{
     if (!FT_LastTime.tv_sec) {
        FT_GetTimeOfDay(&FT_LastTime, 0);
     }
     return FT_LastTime.tv_sec;
 }
+#endif