File: rand.c

package info (click to toggle)
libdumbnet 1.18.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,768 kB
  • sloc: ansic: 11,563; sh: 4,203; python: 261; makefile: 92
file content (33 lines) | stat: -rw-r--r-- 506 bytes parent folder | download | duplicates (2)
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
// stripped down from tests/dnet/rand.c

#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <dumbnet.h>

int
main(int argc, char *argv[])
{
	rand_t *r;
	int len;
	u_char *p;
	
	if ((len = atoi(argv[1])) == 0)
		err(1, "length");

	if ((p = malloc(len)) == NULL)
		err(1, "malloc");

	if ((r = rand_open()) == NULL)
		err(1, "rand_init");

	if (rand_get(r, p, len) < 0)
		err(1, "rand_get");
	
	if (write(STDOUT_FILENO, p, len) != len)
		err(1, "write");
	
	return (0);
}