(root)/
Linux-PAM-1.5.3/
libpam/
pam_modutil_ioloop.c
       1  /*
       2   * $Id$
       3   *
       4   * These functions provides common methods for ensure a complete read or
       5   * write occurs. It handles EINTR and partial read/write returns.
       6   */
       7  
       8  #include "pam_modutil_private.h"
       9  
      10  #include <unistd.h>
      11  #include <errno.h>
      12  
      13  int
      14  pam_modutil_read(int fd, char *buffer, int count)
      15  {
      16         int block, offset = 0;
      17  
      18         while (count > 0) {
      19                 block = read(fd, &buffer[offset], count);
      20  
      21                 if (block < 0) {
      22                         if (errno == EINTR) continue;
      23                         return block;
      24                 }
      25                 if (block == 0) return offset;
      26  
      27                 offset += block;
      28                 count -= block;
      29         }
      30  
      31         return offset;
      32  }
      33  
      34  int
      35  pam_modutil_write(int fd, const char *buffer, int count)
      36  {
      37         int block, offset = 0;
      38  
      39         while (count > 0) {
      40                 block = write(fd, &buffer[offset], count);
      41  
      42                 if (block < 0) {
      43                         if (errno == EINTR) continue;
      44                         return block;
      45                 }
      46                 if (block == 0) return offset;
      47  
      48                 offset += block;
      49                 count -= block;
      50         }
      51  
      52         return offset;
      53  }