Email List: Xaustin-review-lX
[All Lists]

Defect in XCU awk

To: yyyyyyyyyyyyyyy@xxxxxxxxxxxxx
Subject: Defect in XCU awk
From: Geoff Clare <yyy@xxxxxxxxxxxxx>
Date: Fri, 16 Apr 2004 16:18:22 +0100
@ page 167 line 6364 section awk comment [gwc awk srand time]

Problem:

Defect code :  3. Clarification required

The description of the srand() function for awk says it uses the
"time of day" if no argument is passed to srand().

What does this mean exactly?  In particular:

    1. Does it relate to the time value returned by the function
    gettimeofday() in XSH?  If so, is it just the seconds or the
    fractional part as well?

    2. Or is it supposed to imply a value with a cycle of 24 hours?

All the implementations I have tried use just the seconds from the
time returned by gettimeofday() (i.e. the return value of time()).

I think a value with a cycle of 24 hours would be a bad idea and
the specification should make it clear that this is not allowed.
(Consider the effect on a cron job which is started at the same time
each day.)

Another thing to consider is that awk's srand() provides a known way
of obtaining the seconds since the epoch in a shell script (using
awk 'BEGIN { srand(); printf "%d\n", srand(); }').  It is currently
not clear how portable the method is, and a clarification of the
standard would remove any doubts.

Action:

Preferably change "time of day if expr is omitted" to one of the
following:

    "current system time, as would be returned by the time() function
    in the System Interfaces volume of IEEE Std 1003.1-2001, if expr
    is omitted"

or:
    "current system time, as would be returned in tv_sec by the
    gettimeofday() function in the System Interfaces volume of
    IEEE Std 1003.1-2001, optionally plus tv_usec*1.0e-6, if expr
    is omitted"

<Prev in Thread] Current Thread [Next in Thread>