tech-misc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: __attribute__((warn_unused_result)) for NetBSD?




On Sep 15, 2008, at 2:39 PM, Aleksey Cheusov wrote:

In general EBADF is meaningless on close.
Yes, EBADF is not a big problem.

Isn't it only possible to get EINTR on non-blocking I/O? Otherwise
isn't this an auto-restarted call?
AFAIK SA_RESTART is BSD-ism and is absent on many systems.


We're kinda discussing a BSD system so it's kinda relevant. I don't really care if linux didn't implement it...

Anyways, for the most part all common usages of close don't need
warnings about missing the return value that I can see.
I personally disagree. The following is much more robust approach.

void xclose (int fd)
{
        int ret;
        do {
                ret = close (fd);
        }while (ret == -1 && errno == EINTR);

        if (ret == -1){
                perror("perror failed");
                exit (1);
        }
}

The same for read(2), write(2) and many others.


You may choose to write such code. The reality is (especially for close) that code like this doesn't exist and likely has no value on systems with restartable system calls.

James



Home | Main Index | Thread Index | Old Index