amiga-whois/sgetln.c

32 lines
537 B
C

/*
* Written by Carsten Larsen.
* Public domain.
*/
#include "config.h"
char sgetln_buf[512];
char* sgetln(int sd, size_t *len) {
int res;
char in;
char *p;
int count = 0;
memset(&sgetln_buf, 0, sizeof(sgetln_buf));
p = (char*)&sgetln_buf;
while((res = recv(sd, &in, sizeof(char), 0))) {
*p++ = in;
count++;
if (in == '\n' || count == sizeof(sgetln_buf) - 1) {
*len = count;
return (char*)&sgetln_buf;
}
}
*len = 0;
return NULL;
}