Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 584987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:57:20+00:00 2026-05-13T14:57:20+00:00

In the man page for the system call write(2) – ssize_t write(int fd, const

  • 0

In the man page for the system call write(2) –

ssize_t write(int fd, const void *buf, size_t count);

it says the following:

Return Value

On success, the number of bytes
written are returned (zero indicates
nothing was written). On error, -1 is
returned, and errno is set
appropriately. If count is zero and
the file descriptor refers to a
regular file, 0 may be returned, or an
error could be detected. For a special
file, the results are not portable.

I would interpret this to mean that returning 0 simply means that nothing was written, for whatever arbitrary reason.

However, Stevens in UNP treats a return value of 0 as a fatal error when dealing with a file descriptor that is a TCP socket ( this is wrapped by another function which calls exit(1) on a short count ):

ssize_t /* Write "n" bytes to a descriptor. */
writen(int fd, const void *vptr, size_t n)
{
    size_t      nleft;
    ssize_t     nwritten;
    const char  *ptr;

    ptr = vptr;
    nleft = n;
    while (nleft > 0) {
        if ( (nwritten = write(fd, ptr, nleft)) <= 0) {
            if (nwritten < 0 && errno == EINTR)
                nwritten = 0;       /* and call write() again */
            else
                return(-1);         /* error */
        }

        nleft -= nwritten;
        ptr   += nwritten;
    }
    return(n);
}

He only treats 0 as a legit return value if the errno indicates that the call to write was interrupted by the process receiving a signal.

Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:57:21+00:00Added an answer on May 13, 2026 at 2:57 pm

    Stevens probably does this to catch old implementations of
    write() that behaved differently. For instance, the Single Unix Spec
    says (http://www.opengroup.org/onlinepubs/000095399/functions/write.html)

    Where this volume of IEEE Std
    1003.1-2001 requires -1 to be returned and errno set to [EAGAIN], most
    historical implementations return zero

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The man page for the splice system call says that splice may fail and
After reading the mkdir(2) man page for the Unix system call with that name,
Reading through the man page of the Linux system call sendfile , I am
I have a doubt regarding the backlog value in listen system call. From man
If a file is opened using the following command: FILE *f1=fopen(test.dat,a+); The man page
From the man page on git-merge, there are a number of merge strategies you
From the XDrawString man page it seems that it aceepts signed 32 bit x
I'm looking at the poll() man page , and it tells me the behavior
The clone() system call on Linux takes a parameter pointing to the stack for
I've been reading its man page but haven't yet been successful in figuring out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.