186d7f5d3SJohn Marino /* $NetBSD: lvm-wrappers.c,v 1.1.1.2 2009/02/18 11:17:18 haad Exp $ */
286d7f5d3SJohn Marino
386d7f5d3SJohn Marino /*
486d7f5d3SJohn Marino * Copyright (C) 2006 Red Hat, Inc. All rights reserved.
586d7f5d3SJohn Marino *
686d7f5d3SJohn Marino * This file is part of LVM2.
786d7f5d3SJohn Marino *
886d7f5d3SJohn Marino * This copyrighted material is made available to anyone wishing to use,
986d7f5d3SJohn Marino * modify, copy, or redistribute it subject to the terms and conditions
1086d7f5d3SJohn Marino * of the GNU Lesser General Public License v.2.1.
1186d7f5d3SJohn Marino *
1286d7f5d3SJohn Marino * You should have received a copy of the GNU Lesser General Public License
1386d7f5d3SJohn Marino * along with this program; if not, write to the Free Software Foundation,
1486d7f5d3SJohn Marino * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
1586d7f5d3SJohn Marino */
1686d7f5d3SJohn Marino
1786d7f5d3SJohn Marino #include "lib.h"
1886d7f5d3SJohn Marino
1986d7f5d3SJohn Marino #include <unistd.h>
2086d7f5d3SJohn Marino #include <fcntl.h>
2186d7f5d3SJohn Marino
lvm_getpagesize(void)2286d7f5d3SJohn Marino int lvm_getpagesize(void)
2386d7f5d3SJohn Marino {
2486d7f5d3SJohn Marino return getpagesize();
2586d7f5d3SJohn Marino }
2686d7f5d3SJohn Marino
read_urandom(void * buf,size_t len)2786d7f5d3SJohn Marino int read_urandom(void *buf, size_t len)
2886d7f5d3SJohn Marino {
2986d7f5d3SJohn Marino int fd;
3086d7f5d3SJohn Marino
3186d7f5d3SJohn Marino /* FIXME: we should stat here, and handle other cases */
3286d7f5d3SJohn Marino /* FIXME: use common _io() routine's open/read/close */
3386d7f5d3SJohn Marino if ((fd = open("/dev/urandom", O_RDONLY)) < 0) {
3486d7f5d3SJohn Marino log_sys_error("open", "read_urandom: /dev/urandom");
3586d7f5d3SJohn Marino return 0;
3686d7f5d3SJohn Marino }
3786d7f5d3SJohn Marino
3886d7f5d3SJohn Marino if (read(fd, buf, len) != (ssize_t) len) {
3986d7f5d3SJohn Marino log_sys_error("read", "read_urandom: /dev/urandom");
4086d7f5d3SJohn Marino if (close(fd))
4186d7f5d3SJohn Marino stack;
4286d7f5d3SJohn Marino return 0;
4386d7f5d3SJohn Marino }
4486d7f5d3SJohn Marino
4586d7f5d3SJohn Marino if (close(fd))
4686d7f5d3SJohn Marino stack;
4786d7f5d3SJohn Marino
4886d7f5d3SJohn Marino return 1;
4986d7f5d3SJohn Marino }
5086d7f5d3SJohn Marino
51