[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFE] function to read a file descriptor
From: |
Debarshi Ray |
Subject: |
[RFE] function to read a file descriptor |
Date: |
Mon, 18 Aug 2008 20:44:36 +0530 |
I was wondering whether gnulib has a function to safely read or recv
from a file desctiptor. I could not find one, and have had to hack
them up on numerous occasions. Here is one such version I wrote while
implementing a feature for GNU Inetutils:
size_t
recvbuf (int sockfd, void **buffer, size_t *size)
{
size_t count = 0;
size_t nread;
if (*buffer == NULL)
*size = BUFSIZ;
for (;;)
{
*buffer = realloc (*buffer, *size);
nread = recv (sockfd, *buffer + count, BUFSIZ, 0);
if (nread == -1)
error (EXIT_FAILURE, errno, "recv");
count += nread;
if (nread < BUFSIZ)
break;
else
*size += BUFSIZ;
}
return count;
}
Comments?
Happy hacking,
Debarshi
- [RFE] function to read a file descriptor,
Debarshi Ray <=
- Re: [RFE] function to read a file descriptor, Bruno Haible, 2008/08/18
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/18
- Re: [RFE] function to read a file descriptor, Ralf Wildenhues, 2008/08/19
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/19
- Re: [RFE] function to read a file descriptor, Ralf Wildenhues, 2008/08/20
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/20
- Re: [RFE] function to read a file descriptor, Bruno Haible, 2008/08/20
- Re: [RFE] function to read a file descriptor, Debarshi Ray, 2008/08/21
- Re: [RFE] function to read a file descriptor, Bruno Haible, 2008/08/21