Deleted Added
full compact
randomize_fd.c (288485) randomize_fd.c (299484)
1/*
2 * Copyright (C) 2003 Sean Chittenden <seanc@FreeBSD.org>
3 * 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

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
1/*
2 * Copyright (C) 2003 Sean Chittenden <seanc@FreeBSD.org>
3 * 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

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

20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27#include <sys/cdefs.h>
28__FBSDID("$FreeBSD: head/usr.bin/random/randomize_fd.c 241847 2012-10-22 03:06:59Z eadler $");
28__FBSDID("$FreeBSD: head/usr.bin/random/randomize_fd.c 299484 2016-05-11 22:04:28Z cem $");
29
30#include <sys/types.h>
31#include <sys/param.h>
32
33#include <ctype.h>
34#include <err.h>
35#include <errno.h>
36#include <stdlib.h>

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

169 }
170
171 }
172 }
173
174 if ((type == RANDOM_TYPE_LINES && buf[i] == '\n') ||
175 (type == RANDOM_TYPE_WORDS && isspace(buf[i])) ||
176 (eof && i == buflen - 1)) {
29
30#include <sys/types.h>
31#include <sys/param.h>
32
33#include <ctype.h>
34#include <err.h>
35#include <errno.h>
36#include <stdlib.h>

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

169 }
170
171 }
172 }
173
174 if ((type == RANDOM_TYPE_LINES && buf[i] == '\n') ||
175 (type == RANDOM_TYPE_WORDS && isspace(buf[i])) ||
176 (eof && i == buflen - 1)) {
177 make_token:
177make_token:
178 if (numnode == RANDOM_MAX_PLUS1) {
179 errno = EFBIG;
180 err(1, "too many delimiters");
181 }
182 numnode++;
183 n = rand_node_allocate();
184 if (-1 != (int)i) {
185 slen = i - (u_long)bufc;

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

194 bufc = i + 1;
195 }
196 rand_node_append(n);
197 fndstr = 1;
198 }
199 }
200 }
201
178 if (numnode == RANDOM_MAX_PLUS1) {
179 errno = EFBIG;
180 err(1, "too many delimiters");
181 }
182 numnode++;
183 n = rand_node_allocate();
184 if (-1 != (int)i) {
185 slen = i - (u_long)bufc;

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

194 bufc = i + 1;
195 }
196 rand_node_append(n);
197 fndstr = 1;
198 }
199 }
200 }
201
202 (void)close(fd);
202 if (fd >= 0) {
203 (void)close(fd);
204 fd = -1;
205 }
203
204 /* Necessary evil to compensate for files that don't end with a newline */
205 if (bufc != i) {
206 i--;
207 goto make_token;
208 }
209
210 free(buf);

--- 38 unchanged lines hidden ---
206
207 /* Necessary evil to compensate for files that don't end with a newline */
208 if (bufc != i) {
209 i--;
210 goto make_token;
211 }
212
213 free(buf);

--- 38 unchanged lines hidden ---