Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.unix.programmer > #13627

How to check for error with write(2)

From Steve Keller <keller.steve@gmx.de>
Newsgroups comp.unix.programmer
Subject How to check for error with write(2)
Date 2021-12-16 18:58 +0100
Organization Aioe.org NNTP Server
Message-ID <spfuo5$lb0$1@gioia.aioe.org> (permalink)

Show all headers | View raw


A write() system call can return successfully and even the following
close() syscall may not return an error, even if there was an error
like EFBIG (File too large).

        if ((fd = creat(name, 0666)) < 0) {
                perror(name);
                exit(1);
        }
        while (have_more_data) {
                if (write(fd, buffer, count) < 0) {
                        perror("write");
                        exit(1);
                }
        }
        if (close(fd) < 0) {
                perror("close");
                exit(1);
        }

This may complete successfully, e.g. when EFBIG occurs in the last
write() syscall before the loop ends.

So what is the best way to check for errors with write()?

Steve

Back to comp.unix.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

How to check for error with write(2) Steve Keller <keller.steve@gmx.de> - 2021-12-16 18:58 +0100
  Re: How to check for error with write(2) scott@slp53.sl.home (Scott Lurndal) - 2021-12-16 18:26 +0000
    Re: How to check for error with write(2) Geoff Clare <geoff@clare.See-My-Signature.invalid> - 2021-12-20 13:52 +0000
  Re: How to check for error with write(2) Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2021-12-16 18:49 +0000
    Re: How to check for error with write(2) Rainer Weikusat <rweikusat@talktalk.net> - 2021-12-16 19:00 +0000
  Re: How to check for error with write(2) Rainer Weikusat <rweikusat@talktalk.net> - 2021-12-16 19:06 +0000
  Re: How to check for error with write(2) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-12-16 22:34 +0000
    Re: How to check for error with write(2) Steve Keller <keller.steve@gmx.de> - 2021-12-17 04:38 +0100
      Re: How to check for error with write(2) Rainer Weikusat <rweikusat@talktalk.net> - 2021-12-17 15:14 +0000
      Re: How to check for error with write(2) Jorgen Grahn <grahn+nntp@snipabacken.se> - 2021-12-18 10:25 +0000
  Re: How to check for error with write(2) Philip Guenther <guenther@gmail.com> - 2021-12-16 15:04 -0800
    Re: How to check for error with write(2) Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2021-12-16 20:10 -0700
    Re: How to check for error with write(2) Steve Keller <keller.steve@gmx.de> - 2021-12-17 04:35 +0100
      Re: How to check for error with write(2) Philip Guenther <guenther@gmail.com> - 2021-12-18 14:58 -0800
        Re: How to check for error with write(2) scott@slp53.sl.home (Scott Lurndal) - 2021-12-19 16:07 +0000

csiph-web