1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
Index: src/shar.c
===================================================================
RCS file: /home/ke/cvsroot/sharutils/src/shar.c,v
retrieving revision 1.22
diff -u -r1.22 shar.c
--- src/shar.c 2 Dec 2002 20:52:10 -0000 1.22
+++ src/shar.c 15 May 2004 09:13:16 -0000
@@ -255,11 +255,11 @@
/* Position for first file in the shar file. */
static off_t first_file_position;
-/* Base for output filename. FIXME: No fix limit in GNU... */
-static char output_base_name[50];
+/* Base for output filename. */
+static char *output_base_name;
-/* Actual output filename. FIXME: No fix limit in GNU... */
-static char output_filename[50];
+/* Actual output filename. */
+static char *output_filename;
static char *submitter_address = NULL;
@@ -1727,7 +1727,12 @@
static void
open_output ()
{
- sprintf (output_filename, output_base_name, ++part_number);
+ size_t l;
+ l = strlen(output_base_name) + 128;
+ if (output_filename)
+ free(output_filename);
+ output_filename = xmalloc(l);
+ snprintf(output_filename, l, output_base_name, ++part_number);
output = fopen (output_filename, "w");
if (!output)
error (EXIT_FAILURE, errno, _("Opening `%s'"), output_filename);
@@ -1907,6 +1912,42 @@
file_size_limit = lim;
}
+
+char *parse_output_base_name(char *arg)
+{
+ int c;
+ int hadarg = 0;
+ char *fmt, *p;
+
+ for (p = arg ; (c = *p++) != 0; )
+ {
+ if (c != '%')
+ continue;
+ c = *p++;
+ if (c == '%')
+ continue;
+ if (hadarg)
+ return 0;
+ while (c != 0 && strchr("#0+- 'I", c) != 0)
+ c = *p++;
+ while (c != 0 && c >= '0' && c <= '9')
+ c = *p++;
+ if (c == '.')
+ c = *p++;
+ while (c != 0 && c >= '0' && c <= '9')
+ c = *p++;
+ if (c == 0 || strchr("diouxX", c) == 0)
+ return 0;
+ hadarg = 1;
+ }
+ fmt = xmalloc(strlen(arg) + (hadarg ? 1 : 6));
+ strcpy(fmt, arg);
+ if (!hadarg)
+ strcat(fmt, ".%02d");
+ return fmt;
+}
+
+
/*---.
| ? |
`---*/
@@ -2047,9 +2088,14 @@
break;
case 'o':
- strcpy (output_base_name, optarg);
- if (!strchr (output_base_name, '%'))
- strcat (output_base_name, ".%02d");
+ if (output_base_name)
+ free (output_base_name);
+ output_base_name = parse_output_base_name(optarg);
+ if (!output_base_name)
+ {
+ fprintf (stderr, _("illegal output prefix\n"));
+ exit (EXIT_FAILURE);
+ }
part_number = 0;
open_output ();
break;
|