[tlbuild] Test failing on NetBSD

Bruno Haible bruno at clisp.org
Sun Jan 10 11:12:27 CET 2021


Marc Baudoin wrote:
> The following program:
> 
> -----------------------------------------------------------------
> 
> #include <ctype.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <unistd.h>
> 
> int main ( void )
> {
>    int fd = open ( "postV3.afm" , O_RDONLY ) ;
>    char buf[BUFSIZ] ;
>    int n ;
>    while ( n = read ( fd , buf , sizeof ( buf ) ) )
>    {
>       for ( int i = 0 ; i < n ; i ++ )
>       {
>          printf ( "%c\t%d\n" , buf[i] , iscntrl ( buf[i] ) ) ;
>       }
>    }
>    close ( fd ) ;
> }
> 
> -----------------------------------------------------------------
> 
> prints:
> 
> [...]
> P       0
> a       0
> l       0
> l       0
> e       0
>         0
> J       0
> <BF>    2	<<< this is the problem
> r       0
> g       0
> e       0
> n       0
> s       0
> e       0
> n       0
> [...]

Your program is using iscntrl() in the "C" locale. What you are discovering
is that in NetBSD the "C" locale apparently has ISO-8859-1 encoding, whereas
in the other systems you have tried it has US-ASCII or UTF-8 encoding.

In order to avoid platform dependent behaviour, use
  isascii (c) && iscntrl (c)
instead of just
  iscntrl (c).
Or set the the locale explicitly to "en_US.UTF-8", if that's what you need.

Additionally, your code above has undefined behaviour on platforms where
'char' is signed. Per POSIX and ISO C, you must cast the 'char' argument
to 'unsigned char' before passing it to any of the <ctype.h> functions:
  iscntrl ( (unsigned char) buf[i] )

Bruno



More information about the tlbuild mailing list.