- do not use bb_xgetularg10_bnd as a lower value of -1 doesn't work due to lowe
being unsigned. - minor correction: use stdin only when no file was given via -i. - use shorter boilerplate.
This commit is contained in:
parent
54cb5c6af3
commit
554a9ff7ea
@ -3,21 +3,7 @@
|
|||||||
* busybox patch applet to handle the unified diff format.
|
* busybox patch applet to handle the unified diff format.
|
||||||
* Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au>
|
* Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* Licensed under the GPL v2, see the file LICENSE in this tarball.
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* This applet is written to work with patches generated by GNU diff,
|
* This applet is written to work with patches generated by GNU diff,
|
||||||
* where there is equivalent functionality busybox patch shall behave
|
* where there is equivalent functionality busybox patch shall behave
|
||||||
@ -113,16 +99,15 @@ extern int patch_main(int argc, char **argv)
|
|||||||
char *p, *i;
|
char *p, *i;
|
||||||
ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i);
|
ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i);
|
||||||
if (ret & 1)
|
if (ret & 1)
|
||||||
patch_level = bb_xgetularg10_bnd(p, -1, USHRT_MAX);
|
patch_level = atoi(p);
|
||||||
if (ret & 2) {
|
if (ret & 2) {
|
||||||
patch_file = bb_xfopen(i, "r");
|
patch_file = bb_xfopen(i, "r");
|
||||||
|
} else {
|
||||||
|
patch_file = stdin;
|
||||||
}
|
}
|
||||||
ret = 0;
|
ret = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!patch_file)
|
|
||||||
patch_file = stdin;
|
|
||||||
|
|
||||||
patch_line = bb_get_line_from_file(patch_file);
|
patch_line = bb_get_line_from_file(patch_file);
|
||||||
while (patch_line) {
|
while (patch_line) {
|
||||||
FILE *src_stream;
|
FILE *src_stream;
|
||||||
@ -174,7 +159,8 @@ extern int patch_main(int argc, char **argv)
|
|||||||
strcpy(backup_filename, new_filename);
|
strcpy(backup_filename, new_filename);
|
||||||
strcat(backup_filename, ".orig");
|
strcat(backup_filename, ".orig");
|
||||||
if (rename(new_filename, backup_filename) == -1) {
|
if (rename(new_filename, backup_filename) == -1) {
|
||||||
bb_perror_msg_and_die("Couldnt create file %s", backup_filename);
|
bb_perror_msg_and_die("Couldnt create file %s",
|
||||||
|
backup_filename);
|
||||||
}
|
}
|
||||||
dst_stream = bb_xfopen(new_filename, "w");
|
dst_stream = bb_xfopen(new_filename, "w");
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user