torture3: Fix CID 1435119 Error handling issues (CHECKED_RETURN)
[samba.git] / source3 / lib / time.c
index 7fe53928ab72fdf96c59de0f124c69cb1c37e2d4..30ad1ec9a014c68251410e75647c5f0f05e2dd0e 100644 (file)
@@ -1,21 +1,21 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    time handling functions
 
    Copyright (C) Andrew Tridgell               1992-2004
-   Copyright (C) Stefan (metze) Metzmacher     2002   
+   Copyright (C) Stefan (metze) Metzmacher     2002
    Copyright (C) Jeremy Allison                        2007
 
    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
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -87,17 +87,17 @@ bool nt_time_is_zero(const NTTIME *nt)
 
 /****************************************************************************
  Convert ASN.1 GeneralizedTime string to unix-time.
- Returns 0 on failure; Currently ignores timezone. 
+ Returns 0 on failure; Currently ignores timezone.
 ****************************************************************************/
 
 time_t generalized_to_unix_time(const char *str)
-{ 
+{
        struct tm tm;
 
        ZERO_STRUCT(tm);
 
-       if (sscanf(str, "%4d%2d%2d%2d%2d%2d", 
-                  &tm.tm_year, &tm.tm_mon, &tm.tm_mday, 
+       if (sscanf(str, "%4d%2d%2d%2d%2d%2d",
+                  &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
                   &tm.tm_hour, &tm.tm_min, &tm.tm_sec) != 6) {
                return 0;
        }
@@ -164,7 +164,7 @@ void round_timespec(enum timestamp_set_resolution res, struct timespec *ts)
 }
 
 /****************************************************************************
- Take a Unix time and convert to an NTTIME structure and place in buffer 
+ Take a Unix time and convert to an NTTIME structure and place in buffer
  pointed to by p, rounded to the correct resolution.
 ****************************************************************************/
 
@@ -172,9 +172,8 @@ void put_long_date_timespec(enum timestamp_set_resolution res, char *p, struct t
 {
        NTTIME nt;
        round_timespec(res, &ts);
-       unix_timespec_to_nt_time(&nt, ts);
-       SIVAL(p, 0, nt & 0xFFFFFFFF);
-       SIVAL(p, 4, nt >> 32);
+       nt = unix_timespec_to_nt_time(ts);
+       SBVAL(p, 0, nt);
 }
 
 void put_long_date(char *p, time_t t)
@@ -198,25 +197,7 @@ void dos_filetime_timespec(struct timespec *tsp)
 
 time_t make_unix_date(const void *date_ptr, int zone_offset)
 {
-       uint32_t dos_date=0;
-       struct tm t;
-       time_t ret;
-
-       dos_date = IVAL(date_ptr,0);
-
-       if (dos_date == 0) {
-               return 0;
-       }
-  
-       interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon,
-                       &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec);
-       t.tm_isdst = -1;
-  
-       ret = timegm(&t);
-
-       ret += zone_offset;
-
-       return(ret);
+       return pull_dos_date(date_ptr, zone_offset);
 }
 
 /*******************************************************************
@@ -225,13 +206,7 @@ time_t make_unix_date(const void *date_ptr, int zone_offset)
 
 time_t make_unix_date2(const void *date_ptr, int zone_offset)
 {
-       uint32_t x,x2;
-
-       x = IVAL(date_ptr,0);
-       x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16);
-       SIVAL(&x,0,x2);
-
-       return(make_unix_date((const void *)&x, zone_offset));
+       return pull_dos_date2(date_ptr, zone_offset);
 }
 
 /*******************************************************************
@@ -241,11 +216,7 @@ time_t make_unix_date2(const void *date_ptr, int zone_offset)
 
 time_t make_unix_date3(const void *date_ptr, int zone_offset)
 {
-       time_t t = (time_t)IVAL(date_ptr,0);
-       if (!null_time(t)) {
-               t += zone_offset;
-       }
-       return(t);
+       return pull_dos_date3(date_ptr, zone_offset);
 }
 
 time_t srv_make_unix_date(const void *date_ptr)
@@ -272,14 +243,14 @@ time_t srv_make_unix_date3(const void *date_ptr)
 struct timespec interpret_long_date(const char *p)
 {
        NTTIME nt;
-       nt = IVAL(p,0) + ((uint64_t)IVAL(p,4) << 32);
+       nt = BVAL(p, 0);
        if (nt == (uint64_t)-1) {
                struct timespec ret;
                ret.tv_sec = (time_t)-1;
                ret.tv_nsec = 0;
                return ret;
        }
-       return nt_time_to_unix_timespec(&nt);
+       return nt_time_to_unix_timespec(nt);
 }
 
 /*******************************************************************
@@ -400,12 +371,12 @@ void unix_to_nt_time_abs(NTTIME *nt, time_t t)
                *nt = 0x7fffffffffffffffLL;
                return;
        }
-               
+
        if (t == (time_t)-1) {
                /* that's what NT uses for infinite */
                *nt = NTTIME_INFINITY;
                return;
-       }               
+       }
 
        d = (double)(t);
        d *= 1.0e7;
@@ -451,7 +422,7 @@ const char *display_time(NTTIME nttime)
        if (nttime==NTTIME_INFINITY)
                return "Never";
 
-       high = 65536;   
+       high = 65536;
        high = high/10000;
        high = high*65536;
        high = high/1000;