random() for Windoze
authorvb
Sun, 08 Feb 2015 14:51:02 -0500
changeset 548f6b3a6b77a8
parent 53 d9eacd197962
child 55 0569864cb34e
random() for Windoze
src/etpan_mime.c
src/mime.h
src/platform_windows.cpp
src/platform_windows.h
     1.1 --- a/src/etpan_mime.c	Sun Feb 08 13:42:23 2015 -0500
     1.2 +++ b/src/etpan_mime.c	Sun Feb 08 14:51:02 2015 -0500
     1.3 @@ -12,12 +12,15 @@
     1.4      time_t now;
     1.5      char name[MAX_MESSAGE_ID];
     1.6      long value;
     1.7 -    
     1.8 + 
     1.9 +    id[MAX_MESSAGE_ID - 1] = 0;
    1.10 +    name[MAX_MESSAGE_ID - 1] = 0;
    1.11 +
    1.12      now = time(NULL);
    1.13  #ifndef WIN32
    1.14      value = random();
    1.15      
    1.16 -    gethostname(name, MAX_MESSAGE_ID);
    1.17 +    gethostname(name, MAX_MESSAGE_ID - 1);
    1.18  #else
    1.19      value = now;
    1.20      strcpy(name, "WINDOWS");
     2.1 --- a/src/mime.h	Sun Feb 08 13:42:23 2015 -0500
     2.2 +++ b/src/mime.h	Sun Feb 08 14:51:02 2015 -0500
     2.3 @@ -13,7 +13,7 @@
     2.4  //      plaintext (in)          plaintext of message as UTF-8 string
     2.5  //      htmltext (in)           optional HTML version of message as UTF-8
     2.6  //                              string or NULL if it does not apply
     2.7 -//      resulttext (out)        the resulting encoded text
     2.8 +//      resulttext (out)        the resulting encoded text or NULL on any error
     2.9  //
    2.10  //  return value:
    2.11  //      PEP_STATUS_OK           if everything worked
     3.1 --- a/src/platform_windows.cpp	Sun Feb 08 13:42:23 2015 -0500
     3.2 +++ b/src/platform_windows.cpp	Sun Feb 08 14:51:02 2015 -0500
     3.3 @@ -7,6 +7,8 @@
     3.4  #define _WIN32_WINNT 0x0600
     3.5  
     3.6  #include <windows.h>
     3.7 +#define _CRT_RAND_S
     3.8 +#include <stdlib.h>
     3.9  #include <assert.h>
    3.10  #include <string>
    3.11  #include <stdexcept>
    3.12 @@ -186,4 +188,18 @@
    3.13      return path.c_str();
    3.14  }
    3.15  
    3.16 +long random(void)
    3.17 +{
    3.18 +    unsigned int r;
    3.19 +    errno_t e;
    3.20 +
    3.21 +    assert(sizeof(unsigned int) == sizeof(long)); // this is Windoze
    3.22 +
    3.23 +    do {
    3.24 +        e = rand_s(&r);
    3.25 +    } while (e);
    3.26 +
    3.27 +    return (long) (r & ((1<<31)-1));
    3.28 +}
    3.29 +
    3.30  } // "C"
     4.1 --- a/src/platform_windows.h	Sun Feb 08 13:42:23 2015 -0500
     4.2 +++ b/src/platform_windows.h	Sun Feb 08 14:51:02 2015 -0500
     4.3 @@ -23,6 +23,8 @@
     4.4  const char *windoze_system_db(void);
     4.5  const char *gpg_conf(void);
     4.6  
     4.7 +long random(void);
     4.8 +
     4.9  #ifdef __cplusplus
    4.10  }
    4.11  #endif