diff: don't use FILE_and_pos_t where it's not needed. -31 bytes
>>From 3ead41fc3cbdd904e478ff7a710f5960c8ed4288 Mon Sep 17 00:00:00 2001 From: Matheus Izvekov <mizvekov@gmail.com> Date: Mon, 18 Jan 2010 22:14:46 -0200 Subject: [PATCH] diff: don't use FILE_and_pos_t where it's not needed. -31 bytes Signed-off-by: Matheus Izvekov <mizvekov@gmail.com> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
4de4cb6b9b
commit
404f14407c
@ -432,7 +432,7 @@ static NOINLINE int *create_J(FILE_and_pos_t ft[2], int nlen[2], off_t *ix[2])
|
|||||||
token_t tok;
|
token_t tok;
|
||||||
size_t sz = 100;
|
size_t sz = 100;
|
||||||
nfile[i] = xmalloc((sz + 3) * sizeof(nfile[i][0]));
|
nfile[i] = xmalloc((sz + 3) * sizeof(nfile[i][0]));
|
||||||
seek_ft(&ft[i], 0);
|
fseeko(ft[i].ft_fp, 0, SEEK_SET); /* ft gets here without the correct position */
|
||||||
|
|
||||||
nlen[i] = 0;
|
nlen[i] = 0;
|
||||||
/* We could zalloc nfile, but then zalloc starts showing in gprof at ~1% */
|
/* We could zalloc nfile, but then zalloc starts showing in gprof at ~1% */
|
||||||
@ -571,10 +571,11 @@ struct context_vec {
|
|||||||
int d; /* end line in new file */
|
int d; /* end line in new file */
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool diff(FILE_and_pos_t ft[2], char *file[2])
|
static bool diff(FILE* fp[2], char *file[2])
|
||||||
{
|
{
|
||||||
int nlen[2];
|
int nlen[2];
|
||||||
off_t *ix[2];
|
off_t *ix[2];
|
||||||
|
FILE_and_pos_t ft[2] = { { fp[0] }, { fp[1] } };
|
||||||
int *J = create_J(ft, nlen, ix);
|
int *J = create_J(ft, nlen, ix);
|
||||||
|
|
||||||
bool anychange = false;
|
bool anychange = false;
|
||||||
@ -670,7 +671,7 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2])
|
|||||||
|
|
||||||
static int diffreg(char *file[2])
|
static int diffreg(char *file[2])
|
||||||
{
|
{
|
||||||
FILE_and_pos_t ft[2];
|
FILE *fp[2];
|
||||||
bool binary = false, differ = false;
|
bool binary = false, differ = false;
|
||||||
int status = STATUS_SAME;
|
int status = STATUS_SAME;
|
||||||
|
|
||||||
@ -681,23 +682,19 @@ static int diffreg(char *file[2])
|
|||||||
/* Our diff implementation is using seek.
|
/* Our diff implementation is using seek.
|
||||||
* When we meet non-seekable file, we must make a temp copy.
|
* When we meet non-seekable file, we must make a temp copy.
|
||||||
*/
|
*/
|
||||||
ft[i].ft_pos = 0;
|
|
||||||
if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
|
if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
|
||||||
char name[] = "/tmp/difXXXXXX";
|
char name[] = "/tmp/difXXXXXX";
|
||||||
int fd_tmp = mkstemp(name);
|
int fd_tmp = mkstemp(name);
|
||||||
if (fd_tmp < 0)
|
if (fd_tmp < 0)
|
||||||
bb_perror_msg_and_die("mkstemp");
|
bb_perror_msg_and_die("mkstemp");
|
||||||
unlink(name);
|
unlink(name);
|
||||||
ft[i].ft_pos = bb_copyfd_eof(fd, fd_tmp);
|
if (bb_copyfd_eof(fd, fd_tmp) < 0)
|
||||||
/* error message is printed by bb_copyfd_eof */
|
|
||||||
if (ft[i].ft_pos < 0)
|
|
||||||
xfunc_die();
|
xfunc_die();
|
||||||
fstat(fd, &stb[i]);
|
|
||||||
if (fd) /* Prevents closing of stdin */
|
if (fd) /* Prevents closing of stdin */
|
||||||
close(fd);
|
close(fd);
|
||||||
fd = fd_tmp;
|
fd = fd_tmp;
|
||||||
}
|
}
|
||||||
ft[i].ft_fp = fdopen(fd, "r");
|
fp[i] = fdopen(fd, "r");
|
||||||
}
|
}
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
@ -705,10 +702,8 @@ static int diffreg(char *file[2])
|
|||||||
char *const buf0 = bb_common_bufsiz1;
|
char *const buf0 = bb_common_bufsiz1;
|
||||||
char *const buf1 = buf0 + sz;
|
char *const buf1 = buf0 + sz;
|
||||||
int i, j;
|
int i, j;
|
||||||
i = fread(buf0, 1, sz, ft[0].ft_fp);
|
i = fread(buf0, 1, sz, fp[0]);
|
||||||
ft[0].ft_pos += i;
|
j = fread(buf1, 1, sz, fp[1]);
|
||||||
j = fread(buf1, 1, sz, ft[1].ft_fp);
|
|
||||||
ft[1].ft_pos += j;
|
|
||||||
if (i != j) {
|
if (i != j) {
|
||||||
differ = true;
|
differ = true;
|
||||||
i = MIN(i, j);
|
i = MIN(i, j);
|
||||||
@ -725,14 +720,14 @@ static int diffreg(char *file[2])
|
|||||||
if (differ) {
|
if (differ) {
|
||||||
if (binary && !(option_mask32 & FLAG(a)))
|
if (binary && !(option_mask32 & FLAG(a)))
|
||||||
status = STATUS_BINARY;
|
status = STATUS_BINARY;
|
||||||
else if (diff(ft, file))
|
else if (diff(fp, file))
|
||||||
status = STATUS_DIFFER;
|
status = STATUS_DIFFER;
|
||||||
}
|
}
|
||||||
if (status != STATUS_SAME)
|
if (status != STATUS_SAME)
|
||||||
exit_status |= 1;
|
exit_status |= 1;
|
||||||
|
|
||||||
fclose_if_not_stdin(ft[0].ft_fp);
|
fclose_if_not_stdin(fp[0]);
|
||||||
fclose_if_not_stdin(ft[1].ft_fp);
|
fclose_if_not_stdin(fp[1]);
|
||||||
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user