Whamcloud - gitweb
libext2fs: Change EXT2_FLAG_DIRECT_IO to avoid conflict with devel branch
[tools/e2fsprogs.git] / lib / uuid / uuid_time.c
index f2fddfa..f25f5c9 100644 (file)
@@ -2,38 +2,70 @@
  * uuid_time.c --- Interpret the time field from a uuid.  This program
  *     violates the UUID abstraction barrier by reaching into the guts
  *     of a UUID and interpreting it.
- * 
+ *
  * Copyright (C) 1998, 1999 Theodore Ts'o.
  *
  * %Begin-Header%
- * This file may be redistributed under the terms of the GNU Public
- * License.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, and the entire permission notice in its entirety,
+ *    including the disclaimer of warranties.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote
+ *    products derived from this software without specific prior
+ *    written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
+ * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
+ * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
+ * DAMAGE.
  * %End-Header%
  */
 
+#ifdef _WIN32
+#define _WIN32_WINNT 0x0500
+#include <windows.h>
+#define UUID MYUUID
+#endif
+
 #include <stdio.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdlib.h>
 #include <sys/types.h>
+#ifdef HAVE_SYS_TIME_H
 #include <sys/time.h>
+#endif
 #include <time.h>
-#include <linux/ext2_fs.h>
 
 #include "uuidP.h"
 
-time_t uuid_time(uuid_t uu, struct timeval *ret_tv)
+time_t uuid_time(const uuid_t uu, struct timeval *ret_tv)
 {
-       struct uuid             uuid;
-       __u32                   high;
        struct timeval          tv;
-       unsigned long long      clock_reg;
+       struct uuid             uuid;
+       uint32_t                high;
+       uint64_t                clock_reg;
 
        uuid_unpack(uu, &uuid);
-       
+
        high = uuid.time_mid | ((uuid.time_hi_and_version & 0xFFF) << 16);
-       clock_reg = uuid.time_low | ((unsigned long long) high << 32);
+       clock_reg = uuid.time_low | ((uint64_t) high << 32);
 
-       clock_reg -= (((unsigned long long) 0x01B21DD2) << 32) + 0x13814000;
+       clock_reg -= (((uint64_t) 0x01B21DD2) << 32) + 0x13814000;
        tv.tv_sec = clock_reg / 10000000;
        tv.tv_usec = (clock_reg % 10000000) / 10;
 
@@ -43,20 +75,20 @@ time_t uuid_time(uuid_t uu, struct timeval *ret_tv)
        return tv.tv_sec;
 }
 
-int uuid_type(uuid_t uu)
+int uuid_type(const uuid_t uu)
 {
        struct uuid             uuid;
 
-       uuid_unpack(uu, &uuid); 
+       uuid_unpack(uu, &uuid);
        return ((uuid.time_hi_and_version >> 12) & 0xF);
 }
 
-int uuid_variant(uuid_t uu)
+int uuid_variant(const uuid_t uu)
 {
        struct uuid             uuid;
        int                     var;
 
-       uuid_unpack(uu, &uuid); 
+       uuid_unpack(uu, &uuid);
        var = uuid.clock_seq;
 
        if ((var & 0x8000) == 0)
@@ -83,7 +115,7 @@ static const char *variant_string(int variant)
        }
 }
 
-       
+
 int
 main(int argc, char **argv)
 {
@@ -131,9 +163,9 @@ main(int argc, char **argv)
                printf("Warning: not a time-based UUID, so UUID time "
                       "decoding will likely not work!\n");
        }
-       printf("UUID time is: (%d, %d): %s\n", tv.tv_sec, tv.tv_usec,
+       printf("UUID time is: (%ld, %ld): %s\n", tv.tv_sec, tv.tv_usec,
               ctime(&time_reg));
-       
+
        return 0;
 }
 #endif