bug-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [Cvs-cvs] Changes to ccvs/src/main.c


From: Conrad T. Pino
Subject: RE: [Cvs-cvs] Changes to ccvs/src/main.c
Date: Thu, 29 Sep 2005 12:29:16 -0700

Hi Mark,

Microsoft Windows and Visual C++ 6.0 don't have the "O_NOCTTY" constant
and the "/dev/urandom" device is non-existant on Windows.

The "windows-NT/config.h" file contains:

        #define WOE32 1

Should some of this new logic be inside

        #if ! WOE32
        ...
        #endif

conditional compile block?

Best regards,

Conrad

> -----Original Message-----
> From: Mark D. Baushke
> Sent: Wednesday, September 28, 2005 16:59
> To: address@hidden
> Subject: [Cvs-cvs] Changes to ccvs/src/main.c
> 
> 
> Index: ccvs/src/main.c
> diff -u ccvs/src/main.c:1.257 ccvs/src/main.c:1.258
> --- ccvs/src/main.c:1.257     Mon Sep 26 00:33:39 2005
> +++ ccvs/src/main.c   Wed Sep 28 23:59:02 2005
> @@ -458,6 +458,46 @@
>  
>  
>  
> +
> +enum {RANDOM_BYTES = 8};
> +enum {N = (sizeof(time_t) + RANDOM_BYTES)};
> +
> +static char const alphabet[62] =
> +  "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
> +
> +/* Divide BUF by D, returning the remainder.  Replace BUF by the
> +   quotient.  BUF[0] is the most significant part of BUF.
> +   D must not exceed UINT_MAX >> CHAR_BIT.  */
> +static unsigned int
> +divide_by (unsigned char buf[N], unsigned int d)
> +{
> +    unsigned int carry = 0;
> +    int i;
> +    for (i = 0; i < N; i++)
> +    {
> +     unsigned int byte = buf[i];
> +     unsigned int dividend = (carry << CHAR_BIT) + byte;
> +     buf[i] = dividend / d;
> +     carry = dividend % d;
> +    }
> +    return carry;
> +}
> +
> +static void
> +convert (char const input[N], char *output)
> +{
> +    static char const zero[N] = { 0, };
> +    unsigned char buf[N];
> +    size_t o = 0;
> +    memcpy (buf, input, N);
> +    while (memcmp (buf, zero, N) != 0)
> +     output[o++] = alphabet[divide_by (buf, sizeof alphabet)];
> +    if (! o)
> +     output[o++] = '0';
> +    output[o] = '\0';
> +}
> +
> +
>  int
>  main (int argc, char **argv)
>  {
> @@ -733,8 +773,29 @@
>  
>      /* Calculate the cvs global session ID */
>  
> -    global_session_id = Xasprintf ("%x%08lx%04x", (int)getpid(),
> -                                  (long)time (NULL), rand()&0xFFFF);
> +    {
> +     char buf[N] = { 0, };
> +     char out[N*2];
> +     ssize_t len = 0;
> +     time_t rightnow = time (NULL);
> +     unsigned char *p = (unsigned char *) (buf + sizeof (time_t));
> +     int fd = open ("/dev/urandom", O_RDONLY, O_NOCTTY);
> +     if (fd >= 0) {
> +         len = read (fd, buf + sizeof (time_t), RANDOM_BYTES);
> +         close (fd);
> +     }
> +     if (len > 0 && rightnow >= 0) {
> +         while (rightnow != 0) {
> +             *--p = rightnow % (UCHAR_MAX + 1);
> +             rightnow /= UCHAR_MAX + 1;
> +         }
> +         convert(buf, out);
> +         global_session_id = strdup (out);
> +     } else
> +         global_session_id = Xasprintf ("%x%08lx%04x", (int)getpid(),
> +                                        (long)time (NULL), rand()&0xFFFF);
> +    }
> +
>  
>      TRACE (TRACE_FUNCTION, "main: Session ID is %s", global_session_id);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]