improve copy_bytes() maintenance

Remove the copy_bytes() function from files.c and util/recover.c
and place a single copy into hacklib.
This commit is contained in:
nhmall
2024-10-05 15:55:20 -04:00
parent 6f8c36df70
commit fb70aadbb5
10 changed files with 57 additions and 58 deletions

View File

@@ -230,10 +230,6 @@ staticfn void wizkit_addinv(struct obj *);
boolean proc_wizkit_line(char *buf);
void read_wizkit(void); /* in extern.h; why here too? */
staticfn FILE *fopen_sym_file(void);
#ifdef SELF_RECOVER
staticfn boolean copy_bytes(int, int);
#endif
staticfn NHFILE *viable_nhfile(NHFILE *);
/* return a file's name without its path and optionally trailing 'type' */
@@ -4452,24 +4448,6 @@ recover_savefile(void)
return TRUE;
}
boolean
copy_bytes(int ifd, int ofd)
{
char buf[BUFSIZ];
int nfrom, nto;
do {
nto = 0;
nfrom = read(ifd, buf, BUFSIZ);
/* read can return -1 */
if (nfrom >= 0 && nfrom <= BUFSIZ)
nto = write(ofd, buf, nfrom);
if (nto != nfrom || nfrom < 0)
return FALSE;
} while (nfrom == BUFSIZ);
return TRUE;
}
/* ---------- END INTERNAL RECOVER ----------- */
#endif /*SELF_RECOVER*/

View File

@@ -936,4 +936,22 @@ case_insensitive_comp(const char *s1, const char *s2)
return u1 - u2;
}
boolean
copy_bytes(int ifd, int ofd)
{
char buf[BUFSIZ];
int nfrom, nto;
do {
nto = 0;
nfrom = read(ifd, buf, BUFSIZ);
/* read can return -1 */
if (nfrom >= 0 && nfrom <= BUFSIZ)
nto = write(ofd, buf, nfrom);
if (nto != nfrom || nfrom < 0)
return FALSE;
} while (nfrom == BUFSIZ);
return TRUE;
}
/*hacklib.c*/