b64/input.c
2025-06-12 11:32:47 +02:00

32 lines
705 B
C

#include "input.h"
#define PADDING '='
int
readb(FILE *fptr, unsigned char *buf, int bufsize)
{
int read;
int total;
unsigned char *begin;
unsigned char *end;
unsigned char *left;
unsigned char *right;
read = total = 0;
begin = left = buf;
while (total < bufsize && (read = fread(left, sizeof(*left), bufsize-total, fptr))) {
total += read;
end = buf + total;
for (right = left; right < end; ++right)
if (*right != '\n')
*left++ = *right;
total -= right - left;
}
if (left > begin) {
for (--left; *left == PADDING; --left)
;
++left;
}
return left-begin;
}