| 1 |
# strftime.awk ; test the strftime code |
| 2 |
# |
| 3 |
# input is the output of `date', see Makefile.in |
| 4 |
|
| 5 |
BEGIN { |
| 6 |
maxtries = 10 |
| 7 |
# On DOS/Windows, DATECMD is set by the Makefile to point to |
| 8 |
# Unix-like 'date' command. |
| 9 |
datecmd = DATECMD |
| 10 |
if (datecmd == "") |
| 11 |
datecmd = "date" |
| 12 |
fmt = "%a %b %e %H:%M:%S %Z %Y" |
| 13 |
|
| 14 |
# loop until before equals after, thereby protecting |
| 15 |
# against a race condition where the seconds field might have |
| 16 |
# incremented between running date and strftime |
| 17 |
i = 0 |
| 18 |
while (1) { |
| 19 |
if (++i > maxtries) { |
| 20 |
printf "Warning: this system is so slow that after %d attempts, we could never get two sequential invocations of strftime to give the same result!\n", maxtries > "/dev/stderr" |
| 21 |
break |
| 22 |
} |
| 23 |
before = strftime(fmt) |
| 24 |
datecmd | getline sd |
| 25 |
after = strftime(fmt) |
| 26 |
close(datecmd) |
| 27 |
if (before == after) { |
| 28 |
if (i > 1) |
| 29 |
printf "Notice: it took %d loops to get the before and after strftime values to match\n", i > "/dev/stderr" |
| 30 |
break |
| 31 |
} |
| 32 |
} |
| 33 |
print sd > "strftime.ok" |
| 34 |
print after > OUTPUT |
| 35 |
} |