ref: b4146b0364b0e4a6bc1f3923262ac8b6e52c0ef8
parent: 712fcc55cd95148faefb531d9c19cd870725bb96
author: Alex Musolino <alex@musolino.id.au>
date: Thu May 22 06:04:54 EDT 2025
remove copy-pasted code in skipto function
--- a/bin/paste.c
+++ b/bin/paste.c
@@ -163,44 +163,6 @@
}
static int
-skipto(char *marker)
-{
- int c, i, buflen;
- char *buf;
-
- buflen = strlen(marker);
- buf = malloc(buflen);
-
- for(i = 0; i < buflen; i++){
- c = Bgetc(stdin);
- if(c < 0){
- free(buf);
- return -1;
- }
- buf[i] = c;
- }
-
- i = 0;
- for(;;){
-//fprint(2, "buf[%d:] = %.*s\n", i, buflen-i, buf+i);
-//fprint(2, "buf[:%d] = %.*s\n", i, i, buf);
- if(memcmp(buf+i, marker, buflen-i) == 0)
- if(memcmp(buf, marker+buflen-i, i) == 0){
- free(buf);
- return 1;
- }
-
- c = Bgetc(stdin);
- if(c < 0){
- free(buf);
- return -1;
- }
- buf[i] = c;
- i = (i+1)%buflen;
- }
-}
-
-static int
copydata(Biobuf *out, char *marker)
{
int c, i, buflen;
@@ -246,6 +208,12 @@
return -1;
}
+static int
+skipto(char *marker)
+{
+ return copydata(nil, marker);
+}
+
enum{
KeyMax = 256,
ValueMax = 1024,
@@ -491,7 +459,7 @@
free(target);
target = smprint("/uploads/%s/", strrchr(dir, '/')+1);
}
- }else if(copydata(nil, mark) < 0){
+ }else if(skipto(mark) < 0){
fprint(2, "unexpected EOF\n");
error(400, "Bad Request");
exits(0);
--
⑨