a/src/utils/smallut.cpp b/src/utils/smallut.cpp
...
...
993
        }
993
        }
994
    }
994
    }
995
    return true;
995
    return true;
996
}
996
}
997
997
998
#ifdef _WIN32
999
int setenv(const char *name, const char *value, int overwrite)
1000
{
1001
    if(!overwrite) {
1002
        const char *cp = getenv(name);
1003
        if (cp)
1004
            return -1;
1005
    }
1006
    return _putenv_s(name, value);
1007
}
1008
void unsetenv(const char *name)
1009
{
1010
    _putenv_s(name, "");
1011
}
1012
#endif
1013
1014
time_t portable_timegm(struct tm *tm)
1015
{
1016
    time_t ret;
1017
    char *tz;
1018
1019
    tz = getenv("TZ");
1020
    setenv("TZ", "", 1);
1021
    tzset();
1022
    ret = mktime(tm);
1023
    if (tz)
1024
        setenv("TZ", tz, 1);
1025
    else
1026
        unsetenv("TZ");
1027
    tzset();
1028
    return ret;
1029
}
1030
1031
#if 0
998
static void cerrdip(const string& s, DateInterval *dip)
1032
static void cerrdip(const string& s, DateInterval *dip)
999
{
1033
{
1000
    cerr << s << dip->y1 << "-" << dip->m1 << "-" << dip->d1 << "/"
1034
    cerr << s << dip->y1 << "-" << dip->m1 << "-" << dip->d1 << "/"
1001
         << dip->y2 << "-" << dip->m2 << "-" << dip->d2 
1035
         << dip->y2 << "-" << dip->m2 << "-" << dip->d2 
1002
         << endl;
1036
         << endl;
1003
}
1037
}
1038
#endif
1004
1039
1005
// Compute date + period. Won't work out of the unix era. 
1040
// Compute date + period. Won't work out of the unix era. 
1006
// or pre-1970 dates. Just convert everything to unixtime and
1041
// or pre-1970 dates. Just convert everything to unixtime and
1007
// seconds (with average durations for months/years), add and convert
1042
// seconds (with average durations for months/years), add and convert
1008
// back
1043
// back
...
...
1013
    // timegm sort it out
1048
    // timegm sort it out
1014
    memset(&tm, 0, sizeof(tm));
1049
    memset(&tm, 0, sizeof(tm));
1015
    tm.tm_year = dp->y1 - 1900 + pp->y1;
1050
    tm.tm_year = dp->y1 - 1900 + pp->y1;
1016
    tm.tm_mon = dp->m1 + pp->m1 -1;
1051
    tm.tm_mon = dp->m1 + pp->m1 -1;
1017
    tm.tm_mday = dp->d1 + pp->d1;
1052
    tm.tm_mday = dp->d1 + pp->d1;
1018
#ifdef sun
1019
    time_t tres = mktime(&tm);
1053
    time_t tres = mktime(&tm);
1020
    localtime_r(&tres, &tm);
1054
    localtime_r(&tres, &tm);
1021
#else
1022
    time_t tres = timegm(&tm);
1023
    gmtime_r(&tres, &tm);
1024
#endif
1025
    dp->y1 = tm.tm_year + 1900;
1055
    dp->y1 = tm.tm_year + 1900;
1026
    dp->m1 = tm.tm_mon + 1;
1056
    dp->m1 = tm.tm_mon + 1;
1027
    dp->d1 = tm.tm_mday;
1057
    dp->d1 = tm.tm_mday;
1028
    //cerrdip("Addperiod return", dp);
1058
    //cerrdip("Addperiod return", dp);
1029
    return true;
1059
    return true;