Back to index

glibc  2.9
Functions
write.c File Reference
#include <sysdep.h>
#include <errno.h>
#include <unistd.h>
#include <stddef.h>
#include "filedesc.h"
#include <fcntl.h>
#include <standalone.h>

Go to the source code of this file.

Functions

ssize_t __libc_write (int fd, const void *buf, size_t nbytes)

Function Documentation

ssize_t __libc_write ( int  fd,
const void *  buf,
size_t  nbytes 
)

Definition at line 32 of file write.c.

{
  int count;
  const char *data = buf;

  if (nbytes == 0)
    return 0;
  if ( !__FD_Is_valid( fd ) || !__FD_Table[ fd ].in_use )
    {
      __set_errno (EBADF);
      return -1;
    }
  if (buf == NULL)
    {
      __set_errno (EINVAL);
      return -1;
    }

  if ( !(__FD_Table[ fd ].flags & (O_WRONLY|O_RDWR)) )  /* is it writeable? */
    {
      __set_errno (EBADF);
      return -1;
    }

  /*
   *  All open file descriptors are mapped to the console.
   */

  for ( count=0 ; count != nbytes ; count++ ) {
    if ( _Console_Putc(data[ count ]) == -1 )
      return -1;
    if ( data[count] == '\n' && _Console_Putc('\r') == -1 )
      return -1;
  }

  return count;
}

Here is the call graph for this function: