Add pip abstraction for sock

This commit is contained in:
2023-01-25 22:52:14 +01:00
parent e721e542f3
commit 299e726341
5 changed files with 92 additions and 40 deletions

View File

@ -383,3 +383,19 @@ long ftelll(FILE *file) {
return -1;
return lines + 1;
}
long parse_chunk_header(const char *buf, size_t len, size_t *ret_len) {
for (int i = 0; i < len; i++) {
char ch = buf[i];
if (ch == '\r') {
continue;
} else if (ch == '\n' && i > 1 && buf[i - 1] == '\r') {
if (ret_len != NULL) *ret_len = i + 1;
return strtol(buf, NULL, 16);
} else if (!((ch >= '0' && ch <= '9') || (ch >= 'a' && ch <= 'f') || (ch >= 'A' && ch <= 'F'))) {
errno = EPROTO;
return -1;
}
}
return -1;
}