Back to index

nagios-plugins  1.4.16
Defines | Functions
safe-read.c File Reference
#include <config.h>
#include "safe-read.h"
#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#include "safe-write.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Defines

#define IS_EINTR(x)   0
#define safe_rw   safe_read
#define rw   read
#define const   /* empty */

Functions

size_t safe_rw (int fd, void const *buf, size_t count)

Define Documentation

#define const   /* empty */

Definition at line 49 of file safe-read.c.

#define IS_EINTR (   x)    0

Definition at line 37 of file safe-read.c.

#define rw   read

Definition at line 47 of file safe-read.c.

#define safe_rw   safe_read

Definition at line 46 of file safe-read.c.


Function Documentation

size_t safe_rw ( int  fd,
void const buf,
size_t  count 
)

Definition at line 56 of file safe-read.c.

{
  /* Work around a bug in Tru64 5.1.  Attempting to read more than
     INT_MAX bytes fails with errno == EINVAL.  See
     <http://lists.gnu.org/archive/html/bug-gnu-utils/2002-04/msg00010.html>.
     When decreasing COUNT, keep it block-aligned.  */
  enum { BUGGY_READ_MAXIMUM = INT_MAX & ~8191 };

  for (;;)
    {
      ssize_t result = rw (fd, buf, count);

      if (0 <= result)
        return result;
      else if (IS_EINTR (errno))
        continue;
      else if (errno == EINVAL && BUGGY_READ_MAXIMUM < count)
        count = BUGGY_READ_MAXIMUM;
      else
        return result;
    }
}