Introduction
Introduction Statistics Contact Development Disclaimer Help
Improve a little getrawitem - sacc - sacc(omys), simple console gopher client
git clone git://bitreich.org/sacc/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65…
Log
Files
Refs
Tags
LICENSE
---
commit c89fcb00443d7f4f49a9766d4aba82a1f7059826
parent 153d2f1c774d180d75308fa1c7afce11e4fc522a
Author: Quentin Rameau <[email protected]>
Date: Thu, 22 Jun 2017 17:13:24 +0200
Improve a little getrawitem
Diffstat:
M sacc.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
---
diff --git a/sacc.c b/sacc.c
@@ -220,30 +220,29 @@ molddiritem(char *raw)
char *
getrawitem(int sock)
{
- char *item, *buf;
- size_t is, bs, ns;
+ char *raw, *buf;
+ size_t bn, bs;
ssize_t n;
- is = bs = BUFSIZ;
- item = buf = xmalloc(BUFSIZ+1);
+ raw = buf = NULL;
+ bn = bs = n = 0;
- while ((n = read(sock, buf, bs)) > 0) {
+ do {
bs -= n;
buf += n;
- if (bs <= 0) {
- ns = is + BUFSIZ;
- item = xreallocarray(item, ns+1, 1);
- is = ns;
- buf = item + is-BUFSIZ;
+ if (bs <= 1) {
+ raw = xreallocarray(raw, ++bn, BUFSIZ);
+ buf = raw + (bn-1) * BUFSIZ;
bs = BUFSIZ;
}
- }
+ } while ((n = read(sock, buf, bs)) > 0);
+
if (n < 0)
die("Can't read socket: %s", strerror(errno));
*buf = '\0';
- return item;
+ return raw;
}
int
You are viewing proxied material from bitreich.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.