mm(1): fix full file handling

This commit is contained in:
dtb 2024-02-26 09:02:58 -07:00
parent 395205d4c6
commit d74bc715cf
Signed by: trinity
GPG Key ID: 31FF85CCB6DC7641

View File

@ -23,7 +23,8 @@
#include <stdlib.h> /* free(3), realloc(3) */
#include <string.h> /* strcmp(3), strerror(3) */
#include <unistd.h> /* getopt(3) */
#if !defined EX_OSERR || !defined EX_USAGE
#if !defined EX_IOERR || !defined EX_OK || !defined EX_OSERR \
|| !defined EX_USAGE
# include <sysexits.h>
#endif
extern int errno;
@ -192,7 +193,7 @@ int main(int argc, char *argv[]){
setvbuf(files[1].files[i++], NULL, _IONBF, 0));
}
retval = 0;
retval = EX_OK;
/* Actual program loop. */
for(i = 0; i < files[0].s; ++i) /* iterate ins */
@ -200,16 +201,16 @@ int main(int argc, char *argv[]){
for(j = 0; j < files[1].s; ++j) /* iterate outs */
if(putc(c, files[1].files[j]) == EOF){
/* notebook's full */
retval = 1;
retval = EX_IOERR;
if(fclose(files[1].files[j]) == EOF)
fprintf(stderr, "%s: %s: %s\n",
program_name, files[1].names[j], strerror(errno));
/* massage out the tense muscle */
for(k = j; k < files[1].s - 1; ++k){
for(k = j--; k < files[1].s - 1; ++k){
files[1].files[k] = files[1].files[k+1];
files[1].names[k] = files[1].names[k+1];
}
if(--files[i].s == 0)
if(--files[1].s == 0)
terminate;
}