[tlbuild] dvibook failure on Cygwin

Ken Brown kbrow1i at gmail.com
Sat Feb 25 15:24:43 CET 2012


On 2/24/2012 8:46 PM, Akira Kakuto wrote:
> Dear Ken,
> 
>>>     Something is seriously wrong with getopt
>>>     (from kpathsea) on Cygwin.
>>>
>>> And always has been, and just never been noticed before?
>>> Possible, I suppose, but doesn't seem especially likely.
> 
> Try by adding a prototype declaration in dvibook.c,
> since stdlib.h seems not to be read:
> 
> int atoi (const char *str);

Hi Akira,

Thanks for the suggestion, but the problem is unfortunately unrelated to
atoi.  The involvement of atoi is only that it tries to dereference the
null pointer that it was passed.  The underlying problem is with option
processing.  Here's another example:

$ dvibook -i playsel.dvi
dvibook: cannot read -i: No such file or directory

Notice that "-i" is treated as though it were the first argument passed
*after* the options, and dvibook treats it as a filename.  When I run
this under gdb to see what's going on, I get the following:

(gdb) b main
Breakpoint 1 at 0x402036: file ../../../texk/seetexk/dvibook.c, line 371.
(gdb) r -i playsel.dvi
Starting program:
/home/kbrown/src/texlive/Build/test/Work/texk/seetexk/dvibook -i playsel.dvi
[New Thread 4672.0xd5c]
[New Thread 4672.0x11cc]

Breakpoint 1, main (argc=3, argv=0x28cc50)
    at ../../../texk/seetexk/dvibook.c:371
371             char *outname = NULL;
[...]
(gdb) n
378             while ((c = getopt(argc, argv, "i:o:s:q")) != EOF) {
(gdb) n
379                     switch (c) {
(gdb) p c
$1 = 105
(gdb) n
386                             if (DVIFileName != NULL)
(gdb) p DVIFileName
$2 = 0x0
(gdb) n
388                             DVIFileName = optarg;
(gdb) p optarg
$3 = 0x28ccba "playsel.dvi"
(gdb) n
389                             break;
(gdb) p DVIFileName
$4 = 0x0
(gdb) n
378             while ((c = getopt(argc, argv, "i:o:s:q")) != EOF) {
(gdb) n
419             while (optind < argc) {
(gdb) n
420                     s = argv[optind++];
(gdb) n
421                     c = *s;
(gdb) p s
$5 = 0x28ccb7 "-i"

So getopt is clearly messed up here, though it seems to work fine in
other programs.

Ken


More information about the tlbuild mailing list