]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/btime.c
Detect mount/junction points and ignore junctions in Windows
[bacula/bacula] / bacula / src / lib / btime.c
index f2777ea8c61b05515c922f9dc3014fdec8bc37e7..f49cb1075723bd65204ccd39c1d69a2ec88d95c0 100644 (file)
@@ -1,37 +1,37 @@
-/*
- * Bacula floating point time and date routines -- John Walker
- *
- * Later double precision integer time/date routines -- Kern Sibbald
- *
- *   Version $Id$
- */
 /*
    Bacula® - The Network Backup Solution
 
-   Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
+   Copyright (C) 2000-2008 Free Software Foundation Europe e.V.
 
    The main author of Bacula is Kern Sibbald, with contributions from
    many others, a complete list can be found in the file AUTHORS.
    This program is Free Software; you can redistribute it and/or
-   modify it under the terms of version two of the GNU General Public
-   License as published by the Free Software Foundation plus additions
-   that are listed in the file LICENSE.
+   modify it under the terms of version three of the GNU Affero General Public
+   License as published by the Free Software Foundation and included
+   in the file LICENSE.
 
    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
+   You should have received a copy of the GNU Affero General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
    02110-1301, USA.
 
-   Bacula® is a registered trademark of John Walker.
+   Bacula® is a registered trademark of Kern Sibbald.
    The licensor of Bacula is the Free Software Foundation Europe
    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
    Switzerland, email:ftf@fsfeurope.org.
 */
+/*
+ * Bacula floating point time and date routines -- John Walker
+ *
+ * Later double precision integer time/date routines -- Kern Sibbald
+ *
+ *   Version $Id$
+ */
 
 
 /* Concerning times. There are a number of differnt time standards
 #include <math.h>
 
 /* Formatted time for user display: dd-Mon-yyyy hh:mm */
-char *bstrftime(char *dt, int maxlen, utime_t tim)
+char *bstrftime(char *dt, int maxlen, utime_t utime)
 {
-   time_t ttime = (time_t)tim;
+   time_t time = (time_t)utime;
    struct tm tm;
 
    /* ***FIXME**** the format and localtime_r() should be user configurable */
-   (void)localtime_r(&ttime, &tm);
+   (void)localtime_r(&time, &tm);
    strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm);
    return dt;
 }
 
 /* Formatted time for user display: dd-Mon-yyyy hh:mm:ss */
-char *bstrftimes(char *dt, int maxlen, utime_t tim)
+char *bstrftimes(char *dt, int maxlen, utime_t utime)
 {
-   time_t ttime = (time_t)tim;
+   time_t time = (time_t)utime;
    struct tm tm;
 
    /* ***FIXME**** the format and localtime_r() should be user configurable */
-   (void)localtime_r(&ttime, &tm);
+   (void)localtime_r(&time, &tm);
    strftime(dt, maxlen, "%d-%b-%Y %H:%M:%S", &tm);
    return dt;
 }
 
 
 /* Formatted time for user display: dd-Mon hh:mm */
-char *bstrftime_ny(char *dt, int maxlen, utime_t tim)
+char *bstrftime_ny(char *dt, int maxlen, utime_t utime)
 {
-   time_t ttime = (time_t)tim;
+   time_t time = (time_t)utime;
    struct tm tm;
 
    /* ***FIXME**** the format and localtime_r() should be user configurable */
-   (void)localtime_r(&ttime, &tm);
+   (void)localtime_r(&time, &tm);
    strftime(dt, maxlen, "%d-%b %H:%M", &tm);
    return dt;
 }
 
 
 /* Formatted time for user display: dd-Mon-yy hh:mm  (no century) */
-char *bstrftime_nc(char *dt, int maxlen, utime_t tim)
+char *bstrftime_nc(char *dt, int maxlen, utime_t utime)
 {
-   time_t ttime = (time_t)tim;
+   time_t time = (time_t)utime;
    struct tm tm;
+   char *p, *q;
 
    /* ***FIXME**** the format and localtime_r() should be user configurable */
-   (void)localtime_r(&ttime, &tm);
+   (void)localtime_r(&time, &tm);
    /* NOTE! since the compiler complains about %y, I use %y and cut the century */
    strftime(dt, maxlen, "%d-%b-%Y %H:%M", &tm);
-   strcpy(dt+7, dt+9);
+   /* overlay the century */
+   p = dt+7;
+   q = dt+9;
+   while (*q) {
+      *p++ = *q++;
+   }
+   *p = 0;
    return dt;
 }
 
 
 /* Unix time to standard time string yyyy-mm-dd hh:mm:ss */
-char *bstrutime(char *dt, int maxlen, utime_t tim)
+char *bstrutime(char *dt, int maxlen, utime_t utime)
 {
-   time_t ttime = (time_t)tim;
+   time_t time = (time_t)utime;
    struct tm tm;
-   (void)localtime_r(&ttime, &tm);
+   (void)localtime_r(&time, &tm);
    strftime(dt, maxlen, "%Y-%m-%d %H:%M:%S", &tm);
    return dt;
 }
@@ -118,7 +125,7 @@ char *bstrutime(char *dt, int maxlen, utime_t tim)
 utime_t str_to_utime(char *str)
 {
    struct tm tm;
-   time_t ttime;
+   time_t time;
 
    /* Check for bad argument */
    if (!str || *str == 0) {
@@ -141,11 +148,11 @@ utime_t str_to_utime(char *str)
    }
    tm.tm_wday = tm.tm_yday = 0;
    tm.tm_isdst = -1;
-   ttime = mktime(&tm);
-   if (ttime == -1) {
-      ttime = 0;
+   time = mktime(&tm);
+   if (time == -1) {
+      time = 0;
    }
-   return (utime_t)ttime;
+   return (utime_t)time;
 }
 
 
@@ -211,11 +218,13 @@ int tm_woy(time_t stime)
    int woy, fty, tm_yday;
    time_t time4;
    struct tm tm;
+
    memset(&tm, 0, sizeof(struct tm));
    (void)localtime_r(&stime, &tm);
    tm_yday = tm.tm_yday;
    tm.tm_mon = 0;
    tm.tm_mday = 4;
+   tm.tm_isdst = 0;                   /* 4 Jan is not DST */ 
    time4 = mktime(&tm);
    (void)localtime_r(&time4, &tm);
    fty = 1 - tm.tm_wday;