On Sun, Nov 23, 2003 at 04:14:08PM +0200, Enache Adrian wrote:
> $ cc close.c -o close && ./close
> 0
> 0
> 
> $ cc close.c -lc_r -o close && ./close
> 0
> 25
> 
> $ cat close.c
> #include <errno.h>
> main()
> {
>         int fd = open("/dev/null", 1);
>         printf("%d\n", errno);
>         close(fd);
>         printf("%d\n", errno);
> }
> 
> This confuses rather badly applications which assume errno is meaningful.

The application is broken.  You must only check errno if you get an
error indication from the library call.

  <URL:http://www.opengroup.org/onlinepubs/007904975/functions/errno.html>
  IEEE Std 1003.1, 2003 Edition says, in part:
  ``The value of errno should only be examined when it is indicated to
  be valid by a function's return value.''

Cheers,
-- 
Jacques Vidrine   NTT/Verio SME      FreeBSD UNIX       Heimdal
[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]
_______________________________________________
[EMAIL PROTECTED] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-current
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to