ports/misc/ctm/files/patch-ctm_ctm__input.c
Stefan Eßer 4d6c49aae2 Apply changes developed by Stephen Montgomery-Smith and required to
actually use CTM to distribute FreeBSD updates. They have been further
refined by Julian H. Stacey.

These changes add support for delta numbers with more than 5 digits
and better compression formats.

Submitted by:	Stephen Montgomery-Smith, Julian H. Stacey
Approved by:	antoine (implicit)
2018-12-23 07:19:01 +00:00

59 lines
1.4 KiB
C

--- ctm/ctm_input.c.orig 2018-10-27 15:56:22 UTC
+++ ctm/ctm_input.c
@@ -63,11 +63,11 @@ Ffield(FILE *fd, MD5_CTX *ctx,u_char term)
return buf;
}
-int
+intmax_t
Fbytecnt(FILE *fd, MD5_CTX *ctx, u_char term)
{
u_char *p,*q;
- int u_chars=0;
+ intmax_t u_chars=0;
p = Ffield(fd,ctx,term);
if(!p) return -1;
@@ -101,6 +101,42 @@ Fdata(FILE *fd, int u_chars, MD5_CTX *ctx)
p[u_chars] = '\0';
return p;
}
+
+int Fforward(FILE *fd, intmax_t u_chars, MD5_CTX *ctx, FILE *fd_to)
+{
+ u_char buf[BUFSIZ];
+ intmax_t amount_read = 0;
+ int amount_to_read;
+
+ while (amount_read < u_chars) {
+ if (u_chars - amount_read >= BUFSIZ)
+ amount_to_read = BUFSIZ;
+ else
+ amount_to_read = u_chars - amount_read;
+ if(amount_to_read != fread(buf, 1, amount_to_read, fd)) {
+ Fatal("Truncated patch.");
+ return 0;
+ }
+ MD5Update(ctx,buf,amount_to_read);
+ if (fd_to != NULL) {
+ if (amount_to_read != fwrite(buf, 1, amount_to_read, fd_to)) {
+ Fatal("Write error.");
+ return 0;
+ }
+ }
+ amount_read += amount_to_read;
+ }
+
+ if(getc(fd) != '\n') {
+ if(Verbose > 3)
+ printf("FileData wasn't followed by a newline.\n");
+ Fatal("Corrupt patch.");
+ return 0;
+ }
+ MD5Update(ctx,"\n",1);
+ return 1;
+}
+
/*---------------------------------------------------------------------------*/
/* get the filename in the next field, prepend BaseDir and give back the result