Path: utzoo!attcan!uunet!munnari!otc!metro!ipso!runx!brucee From: brucee@runx.ips.oz (Bruce Evans) Newsgroups: comp.os.minix Subject: Bugs in 'strn' library functions Message-ID: <1518@runx.ips.oz> Date: 15 May 88 13:43:25 GMT Organization: RUNX Un*x Timeshare. Sydney, Australia. Lines: 41 The 'strn' functions in the Minix 1.2 library *all* diverge from the V7 standard. I think that means they are broken. strncpy( char *t, char *s, int n ) ------- Supposed to copy *exactly* n characters, truncating or *null padding* as necessary. The target need *not* be null-terminated. Actually copies at most (n + 1) characters and doesn't null pad more than once. Always null terminates the string, thereby copying 1 too many in some cases. Treats zero counts as 64K and negative counts as unsigned. (I've always thought counts should be unsigned, but that's not the standard). strncat( char *t, char *s, int n ) ------- Supposed to copy *at most* n characters. The target need *not* be null-terminated. Always null terminates the string, thereby copying 1 too many in some cases. Treats zero count correctly but negative counts as unsigned. strncmp( char *s1, char *s2, int n ) ------- Supposed to compare at most n characters. Treats zero count as 64K and negative counts as unsigned. --- I can easily post correct versions (in C and 2+ different non-Minix assembly languages yet), but I'm more worried about the correctness of the library generally, since there is nothing much easier or better documented than strncpy. (Perhaps the precise documentation is the problem?) (:-). Bruce Evans Internet: brucee@runx.ips.oz.au UUCP: uunet!runx.ips.oz.au!brucee