#include <sys/types.h>
#include <netdb.h>
+#include <poll.h>
+
#if HAVE_NETINET_IN_H
# include <netinet/in.h>
#endif
return (strdup (static_buffer));
/* Allocate a buffer large enough to hold the string. */
- alloc_buffer = malloc (alloc_buffer_size);
+ alloc_buffer = calloc (1, alloc_buffer_size);
if (alloc_buffer == NULL)
return (NULL);
- memset (alloc_buffer, 0, alloc_buffer_size);
/* Print again into this new buffer. */
va_start (ap, format);
/* Do not use `strdup' here, because it's not specified in POSIX. It's
* ``only'' an XSI extension. */
sz = strlen (s) + 1;
- r = (char *) malloc (sizeof (char) * sz);
+ r = malloc (sz);
if (r == NULL)
{
ERROR ("sstrdup: Out of memory.");
const char *ptr;
size_t nleft;
ssize_t status;
+ struct pollfd pfd;
ptr = (const char *) buf;
nleft = count;
+
+ /* checking for closed peer connection */
+ pfd.fd = fd;
+ pfd.events = POLLIN | POLLHUP;
+ pfd.revents = 0;
+ if (poll(&pfd, 1, 0) > 0) {
+ char buffer[32];
+ if (recv(fd, buffer, sizeof(buffer), MSG_PEEK | MSG_DONTWAIT) == 0) {
+ // if recv returns zero (even though poll() said there is data to be read),
+ // that means the connection has been closed
+ return -1;
+ }
+ }
while (nleft > 0)
{
if (buffer_size < 3)
return (EINVAL);
- temp = (char *) malloc (buffer_size);
+ temp = calloc (1, buffer_size);
if (temp == NULL)
return (ENOMEM);
- memset (temp, 0, buffer_size);
temp[0] = '"';
j = 1;
char *ptr;
char *saveptr;
+ if ((buffer == NULL) || (vl == NULL) || (ds == NULL))
+ return EINVAL;
+
i = 0;
dummy = buffer;
saveptr = NULL;