[6.1,6.2][bug] ftime().timezone return invalid value on east

I guess ftime() isn’t used much, but setting timezone for east
(TZ=GMT-NN) makes timeb.timezone return some really wild value.

for GMT+1:
timeb.timezone=60 ------- correct
for GMT-1:
timeb.timezone=17416 ------- ??? should be -60


Looking at the 6.1 libc sources, lib/c/qnx/ftime.c:ftime() has

timeptr->timezone = (-tm_ptr->tm_gmtoff) / 60UL;

which will be promoted to (unsigned long) which will
clobber negative offset. There shouldn’t be UL here.


kabe
*** test code follows ***

#if shell
set -x
gcc $0
TZ=GMT+1 ./a.out
TZ=GMT-1 ./a.out
exit
#endif
#include <stdio.h>
#include <sys/timeb.h>

int
main()
{
struct timeb timeb;
tzset();
ftime(&timeb);
printf(“time=%s”, ctime(&timeb.time));
printf(“timeb.timezone=%d\n”, (int)(signed short)timeb.timezone);
}