Module Name:    src
Committed By:   pooka
Date:           Tue Sep  8 21:34:57 UTC 2009

Modified Files:
        src/include: util.h
        src/lib/libutil: opendisk.c

Log Message:
Add opendisk1(), which functions like opendisk(), but takes a function
pointer to the routine to be used for open().


To generate a diff of this commit:
cvs rdiff -u -r1.51 -r1.52 src/include/util.h
cvs rdiff -u -r1.10 -r1.11 src/lib/libutil/opendisk.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/util.h
diff -u src/include/util.h:1.51 src/include/util.h:1.52
--- src/include/util.h:1.51	Wed May 13 02:50:32 2009
+++ src/include/util.h	Tue Sep  8 21:34:57 2009
@@ -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__

Index: src/lib/libutil/opendisk.c
diff -u src/lib/libutil/opendisk.c:1.10 src/lib/libutil/opendisk.c:1.11
--- src/lib/libutil/opendisk.c:1.10	Mon Apr 28 20:23:03 2008
+++ src/lib/libutil/opendisk.c	Tue Sep  8 21:34:57 2009
@@ -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);
+}

Reply via email to