diff options
author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-10 13:34:19 +0000 |
---|---|---|
committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2005-10-10 13:34:19 +0000 |
commit | 554a9ff7eaf60bcb960a5f0670a9ed74db2f3292 (patch) | |
tree | 667f8f9942cddc4a8d0ce87373ebdb0912d6d564 | |
parent | 54cb5c6af35e09cb759b76390aa920f394e2488b (diff) | |
download | busybox-w32-554a9ff7eaf60bcb960a5f0670a9ed74db2f3292.tar.gz busybox-w32-554a9ff7eaf60bcb960a5f0670a9ed74db2f3292.tar.bz2 busybox-w32-554a9ff7eaf60bcb960a5f0670a9ed74db2f3292.zip |
- 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.
-rw-r--r-- | editors/patch.c | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/editors/patch.c b/editors/patch.c index 980c37f40..f28395397 100644 --- a/editors/patch.c +++ b/editors/patch.c | |||
@@ -3,21 +3,7 @@ | |||
3 | * busybox patch applet to handle the unified diff format. | 3 | * busybox patch applet to handle the unified diff format. |
4 | * Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au> | 4 | * Copyright (C) 2003 Glenn McGrath <bug1@iinet.net.au> |
5 | * | 5 | * |
6 | * This program is free software; you can redistribute it and/or modify | 6 | * Licensed under the GPL v2, see the file LICENSE in this tarball. |
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
19 | * | ||
20 | * | ||
21 | * | 7 | * |
22 | * This applet is written to work with patches generated by GNU diff, | 8 | * This applet is written to work with patches generated by GNU diff, |
23 | * where there is equivalent functionality busybox patch shall behave | 9 | * where there is equivalent functionality busybox patch shall behave |
@@ -113,16 +99,15 @@ extern int patch_main(int argc, char **argv) | |||
113 | char *p, *i; | 99 | char *p, *i; |
114 | ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i); | 100 | ret = bb_getopt_ulflags(argc, argv, "p:i:", &p, &i); |
115 | if (ret & 1) | 101 | if (ret & 1) |
116 | patch_level = bb_xgetularg10_bnd(p, -1, USHRT_MAX); | 102 | patch_level = atoi(p); |
117 | if (ret & 2) { | 103 | if (ret & 2) { |
118 | patch_file = bb_xfopen(i, "r"); | 104 | patch_file = bb_xfopen(i, "r"); |
105 | } else { | ||
106 | patch_file = stdin; | ||
119 | } | 107 | } |
120 | ret = 0; | 108 | ret = 0; |
121 | } | 109 | } |
122 | 110 | ||
123 | if (!patch_file) | ||
124 | patch_file = stdin; | ||
125 | |||
126 | patch_line = bb_get_line_from_file(patch_file); | 111 | patch_line = bb_get_line_from_file(patch_file); |
127 | while (patch_line) { | 112 | while (patch_line) { |
128 | FILE *src_stream; | 113 | FILE *src_stream; |
@@ -174,7 +159,8 @@ extern int patch_main(int argc, char **argv) | |||
174 | strcpy(backup_filename, new_filename); | 159 | strcpy(backup_filename, new_filename); |
175 | strcat(backup_filename, ".orig"); | 160 | strcat(backup_filename, ".orig"); |
176 | if (rename(new_filename, backup_filename) == -1) { | 161 | if (rename(new_filename, backup_filename) == -1) { |
177 | bb_perror_msg_and_die("Couldnt create file %s", backup_filename); | 162 | bb_perror_msg_and_die("Couldnt create file %s", |
163 | backup_filename); | ||
178 | } | 164 | } |
179 | dst_stream = bb_xfopen(new_filename, "w"); | 165 | dst_stream = bb_xfopen(new_filename, "w"); |
180 | } | 166 | } |