Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions
os2rng.c File Reference
#include <os2.h>
#include <stdlib.h>
#include <time.h>
#include "primpl.h"

Go to the source code of this file.

Defines

#define INCL_DOS
#define INCL_DOSERRORS

Functions

static BOOL clockTickTime (unsigned long *phigh, unsigned long *plow)
PRSize _PR_MD_GetRandomNoise (void *buf, PRSize size)

Define Documentation

Definition at line 39 of file os2rng.c.

Definition at line 40 of file os2rng.c.


Function Documentation

PRSize _PR_MD_GetRandomNoise ( void buf,
PRSize  size 
)

Definition at line 61 of file os2rng.c.

{
    unsigned long high = 0;
    unsigned long low  = 0;
    clock_t val = 0;
    int n = 0;
    int nBytes = 0;
    time_t sTime;

    if (size <= 0)
       return 0;

    clockTickTime(&high, &low);

    /* get the maximally changing bits first */
    nBytes = sizeof(low) > size ? size : sizeof(low);
    memcpy(buf, &low, nBytes);
    n += nBytes;
    size -= nBytes;

    if (size <= 0)
       return n;

    nBytes = sizeof(high) > size ? size : sizeof(high);
    memcpy(((char *)buf) + n, &high, nBytes);
    n += nBytes;
    size -= nBytes;

    if (size <= 0)
       return n;

    /* get the number of milliseconds that have elapsed since application started */
    val = clock();

    nBytes = sizeof(val) > size ? size : sizeof(val);
    memcpy(((char *)buf) + n, &val, nBytes);
    n += nBytes;
    size -= nBytes;

    if (size <= 0)
       return n;

    /* get the time in seconds since midnight Jan 1, 1970 */
    time(&sTime);
    nBytes = sizeof(sTime) > size ? size : sizeof(sTime);
    memcpy(((char *)buf) + n, &sTime, nBytes);
    n += nBytes;

    return n;
}

Here is the call graph for this function:

static BOOL clockTickTime ( unsigned long phigh,
unsigned long plow 
) [static]

Definition at line 46 of file os2rng.c.

{
    APIRET rc = NO_ERROR;
    QWORD qword = {0,0};

    rc = DosTmrQueryTime(&qword);
    if (rc != NO_ERROR)
       return FALSE;

    *phigh = qword.ulHi;
    *plow  = qword.ulLo;

    return TRUE;
}

Here is the caller graph for this function: