diff options
author | Matheus Izvekov <mizvekov@gmail.com> | 2010-01-18 22:21:40 -0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-01-20 02:46:01 +0100 |
commit | 404f14407c52a994c039dadf7b00df8eb6953d8a (patch) | |
tree | a24cfcbadb2b3eea4dcde4ca6493a3a3e83bc118 | |
parent | 4de4cb6b9ba294b47ffbaa8646f7ebe4cb8db3c9 (diff) | |
download | busybox-w32-404f14407c52a994c039dadf7b00df8eb6953d8a.tar.gz busybox-w32-404f14407c52a994c039dadf7b00df8eb6953d8a.tar.bz2 busybox-w32-404f14407c52a994c039dadf7b00df8eb6953d8a.zip |
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>
-rw-r--r-- | editors/diff.c | 27 |
1 files changed, 11 insertions, 16 deletions
diff --git a/editors/diff.c b/editors/diff.c index 7429b411a..b7a13871a 100644 --- a/editors/diff.c +++ b/editors/diff.c | |||
@@ -432,7 +432,7 @@ static NOINLINE int *create_J(FILE_and_pos_t ft[2], int nlen[2], off_t *ix[2]) | |||
432 | token_t tok; | 432 | token_t tok; |
433 | size_t sz = 100; | 433 | size_t sz = 100; |
434 | nfile[i] = xmalloc((sz + 3) * sizeof(nfile[i][0])); | 434 | nfile[i] = xmalloc((sz + 3) * sizeof(nfile[i][0])); |
435 | seek_ft(&ft[i], 0); | 435 | fseeko(ft[i].ft_fp, 0, SEEK_SET); /* ft gets here without the correct position */ |
436 | 436 | ||
437 | nlen[i] = 0; | 437 | nlen[i] = 0; |
438 | /* We could zalloc nfile, but then zalloc starts showing in gprof at ~1% */ | 438 | /* We could zalloc nfile, but then zalloc starts showing in gprof at ~1% */ |
@@ -571,10 +571,11 @@ struct context_vec { | |||
571 | int d; /* end line in new file */ | 571 | int d; /* end line in new file */ |
572 | }; | 572 | }; |
573 | 573 | ||
574 | static bool diff(FILE_and_pos_t ft[2], char *file[2]) | 574 | static bool diff(FILE* fp[2], char *file[2]) |
575 | { | 575 | { |
576 | int nlen[2]; | 576 | int nlen[2]; |
577 | off_t *ix[2]; | 577 | off_t *ix[2]; |
578 | FILE_and_pos_t ft[2] = { { fp[0] }, { fp[1] } }; | ||
578 | int *J = create_J(ft, nlen, ix); | 579 | int *J = create_J(ft, nlen, ix); |
579 | 580 | ||
580 | bool anychange = false; | 581 | bool anychange = false; |
@@ -670,7 +671,7 @@ static bool diff(FILE_and_pos_t ft[2], char *file[2]) | |||
670 | 671 | ||
671 | static int diffreg(char *file[2]) | 672 | static int diffreg(char *file[2]) |
672 | { | 673 | { |
673 | FILE_and_pos_t ft[2]; | 674 | FILE *fp[2]; |
674 | bool binary = false, differ = false; | 675 | bool binary = false, differ = false; |
675 | int status = STATUS_SAME; | 676 | int status = STATUS_SAME; |
676 | 677 | ||
@@ -681,23 +682,19 @@ static int diffreg(char *file[2]) | |||
681 | /* Our diff implementation is using seek. | 682 | /* Our diff implementation is using seek. |
682 | * When we meet non-seekable file, we must make a temp copy. | 683 | * When we meet non-seekable file, we must make a temp copy. |
683 | */ | 684 | */ |
684 | ft[i].ft_pos = 0; | ||
685 | if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { | 685 | if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { |
686 | char name[] = "/tmp/difXXXXXX"; | 686 | char name[] = "/tmp/difXXXXXX"; |
687 | int fd_tmp = mkstemp(name); | 687 | int fd_tmp = mkstemp(name); |
688 | if (fd_tmp < 0) | 688 | if (fd_tmp < 0) |
689 | bb_perror_msg_and_die("mkstemp"); | 689 | bb_perror_msg_and_die("mkstemp"); |
690 | unlink(name); | 690 | unlink(name); |
691 | ft[i].ft_pos = bb_copyfd_eof(fd, fd_tmp); | 691 | if (bb_copyfd_eof(fd, fd_tmp) < 0) |
692 | /* error message is printed by bb_copyfd_eof */ | ||
693 | if (ft[i].ft_pos < 0) | ||
694 | xfunc_die(); | 692 | xfunc_die(); |
695 | fstat(fd, &stb[i]); | ||
696 | if (fd) /* Prevents closing of stdin */ | 693 | if (fd) /* Prevents closing of stdin */ |
697 | close(fd); | 694 | close(fd); |
698 | fd = fd_tmp; | 695 | fd = fd_tmp; |
699 | } | 696 | } |
700 | ft[i].ft_fp = fdopen(fd, "r"); | 697 | fp[i] = fdopen(fd, "r"); |
701 | } | 698 | } |
702 | 699 | ||
703 | while (1) { | 700 | while (1) { |
@@ -705,10 +702,8 @@ static int diffreg(char *file[2]) | |||
705 | char *const buf0 = bb_common_bufsiz1; | 702 | char *const buf0 = bb_common_bufsiz1; |
706 | char *const buf1 = buf0 + sz; | 703 | char *const buf1 = buf0 + sz; |
707 | int i, j; | 704 | int i, j; |
708 | i = fread(buf0, 1, sz, ft[0].ft_fp); | 705 | i = fread(buf0, 1, sz, fp[0]); |
709 | ft[0].ft_pos += i; | 706 | j = fread(buf1, 1, sz, fp[1]); |
710 | j = fread(buf1, 1, sz, ft[1].ft_fp); | ||
711 | ft[1].ft_pos += j; | ||
712 | if (i != j) { | 707 | if (i != j) { |
713 | differ = true; | 708 | differ = true; |
714 | i = MIN(i, j); | 709 | i = MIN(i, j); |
@@ -725,14 +720,14 @@ static int diffreg(char *file[2]) | |||
725 | if (differ) { | 720 | if (differ) { |
726 | if (binary && !(option_mask32 & FLAG(a))) | 721 | if (binary && !(option_mask32 & FLAG(a))) |
727 | status = STATUS_BINARY; | 722 | status = STATUS_BINARY; |
728 | else if (diff(ft, file)) | 723 | else if (diff(fp, file)) |
729 | status = STATUS_DIFFER; | 724 | status = STATUS_DIFFER; |
730 | } | 725 | } |
731 | if (status != STATUS_SAME) | 726 | if (status != STATUS_SAME) |
732 | exit_status |= 1; | 727 | exit_status |= 1; |
733 | 728 | ||
734 | fclose_if_not_stdin(ft[0].ft_fp); | 729 | fclose_if_not_stdin(fp[0]); |
735 | fclose_if_not_stdin(ft[1].ft_fp); | 730 | fclose_if_not_stdin(fp[1]); |
736 | 731 | ||
737 | return status; | 732 | return status; |
738 | } | 733 | } |