=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/sed/process.c,v retrieving revision 1.32 retrieving revision 1.33 diff -c -r1.32 -r1.33 *** src/usr.bin/sed/process.c 2017/02/22 14:09:09 1.32 --- src/usr.bin/sed/process.c 2017/12/13 16:06:34 1.33 *************** *** 1,4 **** ! /* $OpenBSD: process.c,v 1.32 2017/02/22 14:09:09 tom Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. --- 1,4 ---- ! /* $OpenBSD: process.c,v 1.33 2017/12/13 16:06:34 millert Exp $ */ /*- * Copyright (c) 1992 Diomidis Spinellis. *************** *** 67,73 **** static int substitute(struct s_command *); struct s_appends *appends; /* Array of pointers to strings to append. */ ! static int appendx; /* Index into appends array. */ size_t appendnum; /* Size of appends array. */ static int lastaddr; /* Set by applies if last address of a range. */ --- 67,73 ---- static int substitute(struct s_command *); struct s_appends *appends; /* Array of pointers to strings to append. */ ! static size_t appendx; /* Index into appends array. */ size_t appendnum; /* Size of appends array. */ static int lastaddr; /* Set by applies if last address of a range. */ *************** *** 227,233 **** DEFFILEMODE)) == -1) error(FATAL, "%s: %s", cp->t, strerror(errno)); ! if (write(cp->u.fd, ps, psl) != psl || write(cp->u.fd, "\n", 1) != 1) error(FATAL, "%s: %s", cp->t, strerror(errno)); --- 227,233 ---- DEFFILEMODE)) == -1) error(FATAL, "%s: %s", cp->t, strerror(errno)); ! if ((size_t)write(cp->u.fd, ps, psl) != psl || write(cp->u.fd, "\n", 1) != 1) error(FATAL, "%s: %s", cp->t, strerror(errno)); *************** *** 334,340 **** regex_t *re; regoff_t slen; int n, lastempty; ! size_t le = 0; char *s; s = ps; --- 334,340 ---- regex_t *re; regoff_t slen; int n, lastempty; ! regoff_t le = 0; char *s; s = ps; *************** *** 428,434 **** if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); ! if (write(cp->u.s->wfd, ps, psl) != psl || write(cp->u.s->wfd, "\n", 1) != 1) error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); } --- 428,434 ---- if (cp->u.s->wfd == -1 && (cp->u.s->wfd = open(cp->u.s->wfile, O_WRONLY|O_APPEND|O_CREAT|O_TRUNC, DEFFILEMODE)) == -1) error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); ! if ((size_t)write(cp->u.s->wfd, ps, psl) != psl || write(cp->u.s->wfd, "\n", 1) != 1) error(FATAL, "%s: %s", cp->u.s->wfile, strerror(errno)); } *************** *** 443,455 **** flush_appends(void) { FILE *f; ! int count, i; char buf[8 * 1024]; ! for (i = 0; i < appendx; i++) ! switch (appends[i].type) { case AP_STRING: ! fwrite(appends[i].s, sizeof(char), appends[i].len, outfile); break; case AP_FILE: --- 443,455 ---- flush_appends(void) { FILE *f; ! size_t count, idx; char buf[8 * 1024]; ! for (idx = 0; idx < appendx; idx++) ! switch (appends[idx].type) { case AP_STRING: ! fwrite(appends[idx].s, sizeof(char), appends[idx].len, outfile); break; case AP_FILE: *************** *** 461,467 **** * would be truly bizarre, but possible. It's probably * not that big a performance win, anyhow. */ ! if ((f = fopen(appends[i].s, "r")) == NULL) break; while ((count = fread(buf, sizeof(char), sizeof(buf), f))) (void)fwrite(buf, sizeof(char), count, outfile); --- 461,467 ---- * would be truly bizarre, but possible. It's probably * not that big a performance win, anyhow. */ ! if ((f = fopen(appends[idx].s, "r")) == NULL) break; while ((count = fread(buf, sizeof(char), sizeof(buf), f))) (void)fwrite(buf, sizeof(char), count, outfile);