xref: /netbsd-src/external/gpl2/lvm2/dist/lib/misc/lvm-wrappers.c (revision bec4d750d436214708904d6a2c66f8d979761c4b)
1*bec4d750Shaad /*	$NetBSD: lvm-wrappers.c,v 1.1.1.2 2009/02/18 11:17:18 haad Exp $	*/
256a34939Shaad 
356a34939Shaad /*
456a34939Shaad  * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
556a34939Shaad  *
656a34939Shaad  * This file is part of LVM2.
756a34939Shaad  *
856a34939Shaad  * This copyrighted material is made available to anyone wishing to use,
956a34939Shaad  * modify, copy, or redistribute it subject to the terms and conditions
1056a34939Shaad  * of the GNU Lesser General Public License v.2.1.
1156a34939Shaad  *
1256a34939Shaad  * You should have received a copy of the GNU Lesser General Public License
1356a34939Shaad  * along with this program; if not, write to the Free Software Foundation,
1456a34939Shaad  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
1556a34939Shaad  */
1656a34939Shaad 
1756a34939Shaad #include "lib.h"
1856a34939Shaad 
1956a34939Shaad #include <unistd.h>
20*bec4d750Shaad #include <fcntl.h>
2156a34939Shaad 
lvm_getpagesize(void)2256a34939Shaad int lvm_getpagesize(void)
2356a34939Shaad {
2456a34939Shaad 	return getpagesize();
2556a34939Shaad }
26*bec4d750Shaad 
read_urandom(void * buf,size_t len)27*bec4d750Shaad int read_urandom(void *buf, size_t len)
28*bec4d750Shaad {
29*bec4d750Shaad 	int fd;
30*bec4d750Shaad 
31*bec4d750Shaad 	/* FIXME: we should stat here, and handle other cases */
32*bec4d750Shaad 	/* FIXME: use common _io() routine's open/read/close */
33*bec4d750Shaad 	if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
34*bec4d750Shaad 		log_sys_error("open", "read_urandom: /dev/urandom");
35*bec4d750Shaad 		return 0;
36*bec4d750Shaad 	}
37*bec4d750Shaad 
38*bec4d750Shaad 	if (read(fd, buf, len) != (ssize_t) len) {
39*bec4d750Shaad 		log_sys_error("read", "read_urandom: /dev/urandom");
40*bec4d750Shaad 		if (close(fd))
41*bec4d750Shaad 			stack;
42*bec4d750Shaad 		return 0;
43*bec4d750Shaad 	}
44*bec4d750Shaad 
45*bec4d750Shaad 	if (close(fd))
46*bec4d750Shaad 		stack;
47*bec4d750Shaad 
48*bec4d750Shaad 	return 1;
49*bec4d750Shaad }
50*bec4d750Shaad 
51