Skip to content

Commit f4c01e9

Browse files
lib/, src/: Use fcopy() instead of its pattern
No changes intended. Signed-off-by: Alejandro Colomar <alx@kernel.org>
1 parent 2a53c00 commit f4c01e9

2 files changed

Lines changed: 4 additions & 20 deletions

File tree

lib/commonio.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "atoi/getnum.h"
2828
#include "commonio.h"
2929
#include "defines.h"
30+
#include "fs/copy/fcopy.h"
3031
#include "fs/mkstemp/fmkomstemp.h"
3132
#include "nscd.h"
3233
#ifdef WITH_TCB
@@ -274,7 +275,6 @@ static int create_backup (const char *name, FILE * fp)
274275
struct stat sb;
275276
struct utimbuf ub;
276277
FILE *bkfp;
277-
int c;
278278

279279
stprintf_a(tmpf, "%s.cioXXXXXX", name);
280280
if (fstat (fileno (fp), &sb) != 0) {
@@ -286,16 +286,7 @@ static int create_backup (const char *name, FILE * fp)
286286
return -1;
287287
}
288288

289-
/* TODO: faster copy, not one-char-at-a-time. --marekm */
290-
c = 0;
291-
if (fseek (fp, 0, SEEK_SET) == 0) {
292-
while ((c = getc (fp)) != EOF) {
293-
if (putc (c, bkfp) == EOF) {
294-
break;
295-
}
296-
}
297-
}
298-
if ((c != EOF) || (ferror (fp) != 0) || (fflush (bkfp) != 0)) {
289+
if (fcopy(bkfp, fp) == -1) {
299290
(void) fclose (bkfp);
300291
unlink(tmpf);
301292
return -1;

src/vipw.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#endif /* WITH_TCB */
4444
#include "shadowlog.h"
4545
#include "sssd.h"
46+
#include "fs/copy/fcopy.h"
4647
#include "fs/mkstemp/fmkomstemp.h"
4748
#include "string/sprintf/aprintf.h"
4849
#include "string/sprintf/snprintf.h"
@@ -108,21 +109,13 @@ static int create_backup_file (FILE * fp, char *backup, struct stat *sb)
108109
{
109110
struct utimbuf ub;
110111
FILE *bkfp;
111-
int c;
112112

113113
bkfp = fmkomstemp(backup, 0, 0600);
114114
if (NULL == bkfp) {
115115
return -1;
116116
}
117117

118-
c = 0;
119-
if (fseeko (fp, 0, SEEK_SET) == 0)
120-
while ((c = getc (fp)) != EOF) {
121-
if (putc (c, bkfp) == EOF) {
122-
break;
123-
}
124-
}
125-
if ((EOF != c) || (ferror (fp) != 0) || (fflush (bkfp) != 0)) {
118+
if (fcopy(bkfp, fp) == -1) {
126119
fclose (bkfp);
127120
unlink (backup);
128121
return -1;

0 commit comments

Comments
 (0)