OSDN Git Service

Add VC++ Project files for PuTTY DLL without exported functions.
[ffftp/ffftp.git] / putty / UNIX / UXGEN.C
1 /*\r
2  * uxgen.c: Unix implementation of get_heavy_noise() from cmdgen.c.\r
3  */\r
4 \r
5 #include <stdio.h>\r
6 #include <fcntl.h>\r
7 #include <unistd.h>\r
8 \r
9 #include "putty.h"\r
10 \r
11 char *get_random_data(int len)\r
12 {\r
13     char *buf = snewn(len, char);\r
14     int fd;\r
15     int ngot, ret;\r
16 \r
17     fd = open("/dev/random", O_RDONLY);\r
18     if (fd < 0) {\r
19         sfree(buf);\r
20         perror("puttygen: unable to open /dev/random");\r
21         return NULL;\r
22     }\r
23 \r
24     ngot = 0;\r
25     while (ngot < len) {\r
26         ret = read(fd, buf+ngot, len-ngot);\r
27         if (ret < 0) {\r
28             close(fd);\r
29             perror("puttygen: unable to read /dev/random");\r
30             return NULL;\r
31         }\r
32         ngot += ret;\r
33     }\r
34 \r
35     close(fd);\r
36 \r
37     return buf;\r
38 }\r