New internal function OPENSSL_gmtime, which is intended to do the same
[openssl.git] / crypto / asn1 / a_gentm.c
index 84062170e8389ca945a885ab0a6904bbb59fc1f8..ef95003510a9341048f9756ee2fc036fcf314176 100644 (file)
 #include <stdio.h>
 #include <time.h>
 #include "cryptlib.h"
+#include "o_time.h"
 #include <openssl/asn1.h>
 
-ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_new(void)
-{ return M_ASN1_GENERALIZEDTIME_new(); }
-
-void ASN1_GENERALIZEDTIME_free(ASN1_GENERALIZEDTIME *x)
-{ M_ASN1_GENERALIZEDTIME_free(x); }
+#if 0
 
 int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
        {
@@ -116,6 +113,8 @@ err:
        return(NULL);
        }
 
+#endif
+
 int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
        {
        static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
@@ -182,6 +181,7 @@ int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
                        {
                        ASN1_STRING_set((ASN1_STRING *)s,
                                (unsigned char *)str,t.length);
+                       s->type=V_ASN1_GENERALIZEDTIME;
                        }
                return(1);
                }
@@ -194,28 +194,24 @@ ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
        {
        char *p;
        struct tm *ts;
-#if defined(THREADS) && !defined(WIN32)
        struct tm data;
-#endif
 
        if (s == NULL)
                s=M_ASN1_GENERALIZEDTIME_new();
        if (s == NULL)
                return(NULL);
 
-#if defined(THREADS) && !defined(WIN32)
-       gmtime_r(&t,&data); /* should return &data, but doesn't on some systems, so we don't even look at the return value */
-       ts=&data;
-#else
-       ts=gmtime(&t);
-#endif
+       ts=OPENSSL_gmtime(&t, &data);
+       if (ts == NULL)
+               return(NULL);
+
        p=(char *)s->data;
        if ((p == NULL) || (s->length < 16))
                {
-               p=Malloc(20);
+               p=OPENSSL_malloc(20);
                if (p == NULL) return(NULL);
                if (s->data != NULL)
-                       Free(s->data);
+                       OPENSSL_free(s->data);
                s->data=(unsigned char *)p;
                }