OLD | NEW |
1 /* | 1 /* |
2 * date.c: Implementation of the EXSLT -- Dates and Times module | 2 * date.c: Implementation of the EXSLT -- Dates and Times module |
3 * | 3 * |
4 * References: | 4 * References: |
5 * http://www.exslt.org/date/date.html | 5 * http://www.exslt.org/date/date.html |
6 * | 6 * |
7 * See Copyright for the status of this software. | 7 * See Copyright for the status of this software. |
8 * | 8 * |
9 * Authors: | 9 * Authors: |
10 * Charlie Bozeman <cbozeman@HiWAAY.net> | 10 * Charlie Bozeman <cbozeman@HiWAAY.net> |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 #include <libxslt/xsltconfig.h> | 41 #include <libxslt/xsltconfig.h> |
42 #include <libxslt/xsltutils.h> | 42 #include <libxslt/xsltutils.h> |
43 #include <libxslt/xsltInternals.h> | 43 #include <libxslt/xsltInternals.h> |
44 #include <libxslt/extensions.h> | 44 #include <libxslt/extensions.h> |
45 | 45 |
46 #include "exslt.h" | 46 #include "exslt.h" |
47 | 47 |
48 #include <string.h> | 48 #include <string.h> |
49 | 49 |
| 50 #ifdef HAVE_ERRNO_H |
| 51 #include <errno.h> |
| 52 #endif |
50 #ifdef HAVE_MATH_H | 53 #ifdef HAVE_MATH_H |
51 #include <math.h> | 54 #include <math.h> |
52 #endif | 55 #endif |
53 | 56 |
54 /* needed to get localtime_r on Solaris */ | 57 /* needed to get localtime_r on Solaris */ |
55 #ifdef __sun | 58 #ifdef __sun |
56 #ifndef __EXTENSIONS__ | 59 #ifndef __EXTENSIONS__ |
57 #define __EXTENSIONS__ | 60 #define __EXTENSIONS__ |
58 #endif | 61 #endif |
59 #endif | 62 #endif |
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
745 #ifdef WITH_TIME | 748 #ifdef WITH_TIME |
746 /** | 749 /** |
747 * exsltDateCurrent: | 750 * exsltDateCurrent: |
748 * | 751 * |
749 * Returns the current date and time. | 752 * Returns the current date and time. |
750 */ | 753 */ |
751 static exsltDateValPtr | 754 static exsltDateValPtr |
752 exsltDateCurrent (void) | 755 exsltDateCurrent (void) |
753 { | 756 { |
754 struct tm localTm, gmTm; | 757 struct tm localTm, gmTm; |
| 758 #ifndef HAVE_GMTIME_R |
| 759 struct tm *tb = NULL; |
| 760 #endif |
755 time_t secs; | 761 time_t secs; |
756 int local_s, gm_s; | 762 int local_s, gm_s; |
757 exsltDateValPtr ret; | 763 exsltDateValPtr ret; |
| 764 #ifdef HAVE_ERRNO_H |
| 765 char *source_date_epoch; |
| 766 #endif /* HAVE_ERRNO_H */ |
| 767 int override = 0; |
758 | 768 |
759 ret = exsltDateCreateDate(XS_DATETIME); | 769 ret = exsltDateCreateDate(XS_DATETIME); |
760 if (ret == NULL) | 770 if (ret == NULL) |
761 return NULL; | 771 return NULL; |
762 | 772 |
| 773 #ifdef HAVE_ERRNO_H |
| 774 /* |
| 775 * Allow the date and time to be set externally by an exported |
| 776 * environment variable to enable reproducible builds. |
| 777 */ |
| 778 source_date_epoch = getenv("SOURCE_DATE_EPOCH"); |
| 779 if (source_date_epoch) { |
| 780 errno = 0; |
| 781 secs = (time_t) strtol (source_date_epoch, NULL, 10); |
| 782 if (errno == 0) { |
| 783 #if HAVE_GMTIME_R |
| 784 if (gmtime_r(&secs, &localTm) != NULL) |
| 785 override = 1; |
| 786 #else |
| 787 tb = gmtime(&secs); |
| 788 if (tb != NULL) { |
| 789 localTm = *tb; |
| 790 override = 1; |
| 791 } |
| 792 #endif |
| 793 } |
| 794 } |
| 795 #endif /* HAVE_ERRNO_H */ |
| 796 |
| 797 if (override == 0) { |
763 /* get current time */ | 798 /* get current time */ |
764 secs = time(NULL); | 799 » secs = time(NULL); |
| 800 |
765 #if HAVE_LOCALTIME_R | 801 #if HAVE_LOCALTIME_R |
766 localtime_r(&secs, &localTm); | 802 » localtime_r(&secs, &localTm); |
767 #else | 803 #else |
768 localTm = *localtime(&secs); | 804 » localTm = *localtime(&secs); |
769 #endif | 805 #endif |
| 806 } |
770 | 807 |
771 /* get real year, not years since 1900 */ | 808 /* get real year, not years since 1900 */ |
772 ret->value.date.year = localTm.tm_year + 1900; | 809 ret->value.date.year = localTm.tm_year + 1900; |
773 | 810 |
774 ret->value.date.mon = localTm.tm_mon + 1; | 811 ret->value.date.mon = localTm.tm_mon + 1; |
775 ret->value.date.day = localTm.tm_mday; | 812 ret->value.date.day = localTm.tm_mday; |
776 ret->value.date.hour = localTm.tm_hour; | 813 ret->value.date.hour = localTm.tm_hour; |
777 ret->value.date.min = localTm.tm_min; | 814 ret->value.date.min = localTm.tm_min; |
778 | 815 |
779 /* floating point seconds */ | 816 /* floating point seconds */ |
780 ret->value.date.sec = (double) localTm.tm_sec; | 817 ret->value.date.sec = (double) localTm.tm_sec; |
781 | 818 |
782 /* determine the time zone offset from local to gm time */ | 819 /* determine the time zone offset from local to gm time */ |
783 #if HAVE_GMTIME_R | 820 #if HAVE_GMTIME_R |
784 gmtime_r(&secs, &gmTm); | 821 gmtime_r(&secs, &gmTm); |
785 #else | 822 #else |
786 gmTm = *gmtime(&secs); | 823 tb = gmtime(&secs); |
| 824 if (tb != NULL) |
| 825 gmTm = *tb; |
787 #endif | 826 #endif |
788 ret->value.date.tz_flag = 0; | 827 ret->value.date.tz_flag = 0; |
789 #if 0 | 828 #if 0 |
790 ret->value.date.tzo = (((ret->value.date.day * 1440) + | 829 ret->value.date.tzo = (((ret->value.date.day * 1440) + |
791 (ret->value.date.hour * 60) + | 830 (ret->value.date.hour * 60) + |
792 ret->value.date.min) - | 831 ret->value.date.min) - |
793 ((gmTm.tm_mday * 1440) + (gmTm.tm_hour * 60) + | 832 ((gmTm.tm_mday * 1440) + (gmTm.tm_hour * 60) + |
794 gmTm.tm_min)); | 833 gmTm.tm_min)); |
795 #endif | 834 #endif |
796 local_s = localTm.tm_hour * SECS_PER_HOUR + | 835 local_s = localTm.tm_hour * SECS_PER_HOUR + |
(...skipping 3066 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3863 (const xmlChar *) EXSLT_DATE_NAMESPACE, | 3902 (const xmlChar *) EXSLT_DATE_NAMESPACE, |
3864 exsltDateWeekInYearFunction) | 3903 exsltDateWeekInYearFunction) |
3865 && !xmlXPathRegisterFuncNS(ctxt, | 3904 && !xmlXPathRegisterFuncNS(ctxt, |
3866 (const xmlChar *) "year", | 3905 (const xmlChar *) "year", |
3867 (const xmlChar *) EXSLT_DATE_NAMESPACE, | 3906 (const xmlChar *) EXSLT_DATE_NAMESPACE, |
3868 exsltDateYearFunction)) { | 3907 exsltDateYearFunction)) { |
3869 return 0; | 3908 return 0; |
3870 } | 3909 } |
3871 return -1; | 3910 return -1; |
3872 } | 3911 } |
OLD | NEW |