finger

finger fortune@hhvn.uk
Log | Files | Refs | LICENSE

commit fe515ee05581b91f0728d16d31d191f77e6999a1
parent 131e099823e459a74fade5606b5efb331f8ae46a
Author: hhvn <dev@hhvn.uk>
Date:   Sun, 11 Jul 2021 18:23:37 +0100

finger.c: remove read_line and use read() directly

Diffstat:
Mfinger.c | 23++++-------------------
1 file changed, 4 insertions(+), 19 deletions(-)

diff --git a/finger.c b/finger.c @@ -43,27 +43,11 @@ die(const int exitc, const char *format, ...) { exit(exitc); } -int -read_line(int fd, char *dest, size_t len) { - size_t i = 0; - char c = 0; - - do { - if (read(fd, &c, sizeof(char)) != sizeof(char)) - return 0; - if (c != '\r') - dest[i++] = c; - } while (c != '\n' && i < len); - - dest[i-1] = '\0'; - return 1; -} - void finger(char *user, char *host, char *port, int w) { struct addrinfo hints; struct addrinfo *ai; - char buf[1024]; + char buf; int sret, sock; memset(&hints, 0, sizeof(hints)); @@ -85,8 +69,9 @@ finger(char *user, char *host, char *port, int w) { printf("[%s@%s:%s]\n", user, host, port); dprintf(sock, "%s\r\n", user); - while (read_line(sock, buf, sizeof(buf)) != 0) - printf("%s\n", buf); + while (read(sock, &buf, sizeof(char)) != 0) + if (buf != '\r') + printf("%c", buf); printf("\n"); /* add extra newline */ }