aboutsummaryrefslogtreecommitdiff
path: root/games
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2006-04-14 17:32:27 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2006-04-14 17:32:27 +0000
commit1107d0af309779049db322ab1155408c6927dc28 (patch)
treedd52439a6bc64218d130b47e75695ba18d43155b /games
parent1fe5a490abf151e7c917ce9944435052b6bfc575 (diff)
downloadsrc-1107d0af309779049db322ab1155408c6927dc28.tar.gz
src-1107d0af309779049db322ab1155408c6927dc28.zip
Notes
Diffstat (limited to 'games')
-rw-r--r--games/random/random.c4
-rw-r--r--games/random/randomize_fd.c15
2 files changed, 11 insertions, 8 deletions
diff --git a/games/random/random.c b/games/random/random.c
index 62c83ba75294..b7b732a521da 100644
--- a/games/random/random.c
+++ b/games/random/random.c
@@ -54,6 +54,7 @@ __FBSDID("$FreeBSD$");
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
+#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -84,6 +85,9 @@ main(int argc, char *argv[])
random_type = RANDOM_TYPE_UNSET;
random_exit = randomize_lines = random_type = unbuffer_output = 0;
unique_output = 1;
+
+ (void)setlocale(LC_CTYPE, "");
+
while ((ch = getopt(argc, argv, "ef:hlruUw")) != -1)
switch (ch) {
case 'e':
diff --git a/games/random/randomize_fd.c b/games/random/randomize_fd.c
index 33588b14c6cd..b60c53c90e4e 100644
--- a/games/random/randomize_fd.c
+++ b/games/random/randomize_fd.c
@@ -93,7 +93,7 @@ rand_node_append(struct rand_node *n)
int
randomize_fd(int fd, int type, int unique, double denom)
{
- u_char *buf, *p;
+ u_char *buf;
u_int numnode, j, selected, slen;
struct rand_node *n, *prev;
int bufleft, eof, fndstr, ret;
@@ -148,30 +148,29 @@ randomize_fd(int fd, int type, int unique, double denom)
fndstr = 0;
}
} else {
- p = (u_char *)realloc(buf, buflen * 2);
- if (p == NULL)
+ buflen *= 2;
+ buf = (u_char *)realloc(buf, buflen);
+ if (buf == NULL)
err(1, "realloc");
- buf = p;
if (!eof) {
- len = read(fd, &buf[i], buflen);
+ len = read(fd, &buf[i], buflen - i);
if (len == -1)
err(1, "read");
else if (len == 0) {
eof++;
break;
} else if (len < (ssize_t)(buflen - i))
- buflen = (size_t)len;
+ buflen = i + (size_t)len;
bufleft = (int)len;
}
- buflen *= 2;
}
}
if ((type == RANDOM_TYPE_LINES && buf[i] == '\n') ||
- (type == RANDOM_TYPE_WORDS && isspace((int)buf[i])) ||
+ (type == RANDOM_TYPE_WORDS && isspace(buf[i])) ||
(eof && i == buflen - 1)) {
make_token:
n = rand_node_allocate();