1
0
Fork 0
pam/libpam/pam_modutil_ioloop.c
Daniel Baumann 82f0236850
Adding upstream version 1.7.0.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
2025-06-21 06:53:43 +02:00

63 lines
1.3 KiB
C

/*
* $Id$
*
* These functions provide common methods to ensure a complete read or
* write occurs. They handle EINTR and partial read/write returns.
*/
#include "pam_modutil_private.h"
#include <unistd.h>
#include <errno.h>
int
pam_modutil_read(int fd, char *buffer, int count)
{
int block, offset = 0;
if (count < 0) {
errno = EINVAL;
return -1;
}
while (count > 0) {
block = read(fd, &buffer[offset], count);
if (block < 0) {
if (errno == EINTR) continue;
return block;
}
if (block == 0) return offset;
offset += block;
count -= block;
}
return offset;
}
int
pam_modutil_write(int fd, const char *buffer, int count)
{
int block, offset = 0;
if (count < 0) {
errno = EINVAL;
return -1;
}
while (count > 0) {
block = write(fd, &buffer[offset], count);
if (block < 0) {
if (errno == EINTR) continue;
return block;
}
if (block == 0) return offset;
offset += block;
count -= block;
}
return offset;
}