Deleted Added
sdiff udiff text old ( 149345 ) new ( 149616 )
full compact
1/*
2 * Copyright (c) 1987, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 18 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/usr.bin/split/split.c 149616 2005-08-30 12:32:18Z tjr $");
36
37#ifndef lint
38static const char copyright[] =
39"@(#) Copyright (c) 1987, 1993, 1994\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif
42
43#ifndef lint

--- 39 unchanged lines hidden (view full) ---

83{
84 intmax_t bytecnti;
85 long scale;
86 int ch;
87 char *ep, *p;
88
89 setlocale(LC_ALL, "");
90
91 while ((ch = getopt(argc, argv, "0123456789a:b:l:p:")) != -1)
92 switch (ch) {
93 case '0': case '1': case '2': case '3': case '4':
94 case '5': case '6': case '7': case '8': case '9':
95 /*
96 * Undocumented kludge: split was originally designed
97 * to take a number after a dash.
98 */
99 if (numlines == 0) {
100 p = argv[optind - 1];
101 if (p[0] == '-' && p[1] == ch && !p[2])
102 numlines = strtol(++p, &ep, 10);
103 else
104 numlines =
105 strtol(argv[optind] + 1, &ep, 10);
106 if (numlines <= 0 || *ep)
107 errx(EX_USAGE,
108 "%s: illegal line count", optarg);
109 }
110 break;
111 case 'a': /* Suffix length */
112 if ((sufflen = strtol(optarg, &ep, 10)) <= 0 || *ep)
113 errx(EX_USAGE,
114 "%s: illegal suffix length", optarg);
115 break;
116 case 'b': /* Byte count. */
117 errno = 0;
118 if ((bytecnti = strtoimax(optarg, &ep, 10)) <= 0 ||

--- 24 unchanged lines hidden (view full) ---

143 "%s: illegal line count", optarg);
144 break;
145 default:
146 usage();
147 }
148 argv += optind;
149 argc -= optind;
150
151 if (*argv != NULL) { /* Input file. */
152 if (strcmp(*argv, "-") == 0)
153 ifd = STDIN_FILENO;
154 else if ((ifd = open(*argv, O_RDONLY, 0)) < 0)
155 err(EX_NOINPUT, "%s", *argv);
156 ++argv;
157 }
158 if (*argv != NULL) /* File name prefix. */
159 if (strlcpy(fname, *argv++, sizeof(fname)) >= sizeof(fname))
160 errx(EX_USAGE, "file name prefix is too long");
161 if (*argv != NULL)
162 usage();
163
164 if (strlen(fname) + (unsigned long)sufflen >= sizeof(fname))
165 errx(EX_USAGE, "suffix is too long");

--- 177 unchanged lines hidden ---