Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Add opendisk1(), which functions like opendisk(), but takes ...
details: https://anonhg.NetBSD.org/src/rev/e75fdace8c5d
branches: trunk
changeset: 747301:e75fdace8c5d
user: pooka <pooka%NetBSD.org@localhost>
date: Tue Sep 08 21:34:57 2009 +0000
description:
Add opendisk1(), which functions like opendisk(), but takes a function
pointer to the routine to be used for open().
diffstat:
include/util.h | 4 +++-
lib/libutil/opendisk.c | 32 ++++++++++++++++++++++++--------
2 files changed, 27 insertions(+), 9 deletions(-)
diffs (93 lines):
diff -r 382cb80ba83d -r e75fdace8c5d include/util.h
--- a/include/util.h Tue Sep 08 21:14:33 2009 +0000
+++ b/include/util.h Tue Sep 08 21:34:57 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: util.h,v 1.51 2009/05/13 02:50:32 pgoyette Exp $ */
+/* $NetBSD: util.h,v 1.52 2009/09/08 21:34:57 pooka Exp $ */
/*-
* Copyright (c) 1995
@@ -82,6 +82,8 @@
void logwtmp(const char *, const char *, const char *);
void logwtmpx(const char *, const char *, const char *, int, int);
int opendisk(const char *, int, char *, size_t, int);
+int opendisk1(const char *, int, char *, size_t, int,
+ int (*)(const char *, int, mode_t));
int openpty(int *, int *, char *, struct termios *,
struct winsize *);
#ifndef __LIBC12_SOURCE__
diff -r 382cb80ba83d -r e75fdace8c5d lib/libutil/opendisk.c
--- a/lib/libutil/opendisk.c Tue Sep 08 21:14:33 2009 +0000
+++ b/lib/libutil/opendisk.c Tue Sep 08 21:34:57 2009 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: opendisk.c,v 1.10 2008/04/28 20:23:03 martin Exp $ */
+/* $NetBSD: opendisk.c,v 1.11 2009/09/08 21:34:57 pooka Exp $ */
/*-
* Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: opendisk.c,v 1.10 2008/04/28 20:23:03 martin Exp $");
+__RCSID("$NetBSD: opendisk.c,v 1.11 2009/09/08 21:34:57 pooka Exp $");
#endif
#include <sys/param.h>
@@ -44,8 +44,9 @@
#include <stdio.h>
#include <string.h>
-int
-opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked)
+static int
+__opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked,
+ int (*ofn)(const char *, int, mode_t))
{
int f, rawpart;
@@ -64,12 +65,12 @@
if (rawpart < 0)
return (-1); /* sysctl(3) in getrawpartition sets errno */
- f = open(buf, flags);
+ f = ofn(buf, flags, 0);
if (f != -1 || errno != ENOENT)
return (f);
snprintf(buf, buflen, "%s%c", path, 'a' + rawpart);
- f = open(buf, flags);
+ f = ofn(buf, flags, 0);
if (f != -1 || errno != ENOENT)
return (f);
@@ -77,12 +78,27 @@
return (-1);
snprintf(buf, buflen, "%s%s%s", _PATH_DEV, iscooked ? "" : "r", path);
- f = open(buf, flags);
+ f = ofn(buf, flags, 0);
if (f != -1 || errno != ENOENT)
return (f);
snprintf(buf, buflen, "%s%s%s%c", _PATH_DEV, iscooked ? "" : "r", path,
'a' + rawpart);
- f = open(buf, flags);
+ f = ofn(buf, flags, 0);
return (f);
}
+
+int
+opendisk(const char *path, int flags, char *buf, size_t buflen, int iscooked)
+{
+
+ return __opendisk(path, flags, buf, buflen, iscooked, (void *)open);
+}
+
+int
+opendisk1(const char *path, int flags, char *buf, size_t buflen, int iscooked,
+ int (*ofn)(const char *, int, mode_t))
+{
+
+ return __opendisk(path, flags, buf, buflen, iscooked, ofn);
+}
Home |
Main Index |
Thread Index |
Old Index