Module Name:    src
Committed By:   pooka
Date:           Thu Feb 18 12:21:28 UTC 2010

Modified Files:
        src/sys/rump/librump/rumpuser: rumpuser.c

Log Message:
Allow NULL as size and file type pointers.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/sys/rump/librump/rumpuser/rumpuser.c

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

Modified files:

Index: src/sys/rump/librump/rumpuser/rumpuser.c
diff -u src/sys/rump/librump/rumpuser/rumpuser.c:1.47 src/sys/rump/librump/rumpuser/rumpuser.c:1.48
--- src/sys/rump/librump/rumpuser/rumpuser.c:1.47	Tue Dec  8 08:18:24 2009
+++ src/sys/rump/librump/rumpuser/rumpuser.c	Thu Feb 18 12:21:28 2010
@@ -1,4 +1,4 @@
-/*	$NetBSD: rumpuser.c,v 1.47 2009/12/08 08:18:24 stacktic Exp $	*/
+/*	$NetBSD: rumpuser.c,v 1.48 2010/02/18 12:21:28 pooka Exp $	*/
 
 /*
  * Copyright (c) 2007 Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.47 2009/12/08 08:18:24 stacktic Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.48 2010/02/18 12:21:28 pooka Exp $");
 #endif /* !lint */
 
 /* thank the maker for this */
@@ -69,10 +69,11 @@
 #include "rumpuser_int.h"
 
 int
-rumpuser_getfileinfo(const char *path, uint64_t *size, int *ft, int *error)
+rumpuser_getfileinfo(const char *path, uint64_t *sizep, int *ftp, int *error)
 {
 	struct stat sb;
-	int needsdev = 0;
+	uint64_t size;
+	int needsdev = 0, rv = 0, ft;
 
 	if (stat(path, &sb) == -1) {
 		*error = errno;
@@ -81,26 +82,26 @@
 
 	switch (sb.st_mode & S_IFMT) {
 	case S_IFDIR:
-		*ft = RUMPUSER_FT_DIR;
+		ft = RUMPUSER_FT_DIR;
 		break;
 	case S_IFREG:
-		*ft = RUMPUSER_FT_REG;
+		ft = RUMPUSER_FT_REG;
 		break;
 	case S_IFBLK:
-		*ft = RUMPUSER_FT_BLK;
+		ft = RUMPUSER_FT_BLK;
 		needsdev = 1;
 		break;
 	case S_IFCHR:
-		*ft = RUMPUSER_FT_CHR;
+		ft = RUMPUSER_FT_CHR;
 		needsdev = 1;
 		break;
 	default:
-		*ft = RUMPUSER_FT_OTHER;
+		ft = RUMPUSER_FT_OTHER;
 		break;
 	}
 
 	if (!needsdev) {
-		*size = sb.st_size;
+		size = sb.st_size;
 	} else {
 		/*
 		 * Welcome to the jungle.  Of course querying the kernel
@@ -123,19 +124,21 @@
 		fd = open(path, O_RDONLY);
 		if (fd == -1) {
 			*error = errno;
-			return -1;
+			rv = -1;
+			goto out;
 		}
 
 		off = lseek(fd, 0, SEEK_END);
 		close(fd);
 		if (off != 0) {
-			*size = off;
-			return 0;
+			size = off;
+			goto out;
 		}
 		fprintf(stderr, "error: device size query not implemented on "
 		    "this platform\n");
 		*error = EOPNOTSUPP;
-		return -1;
+		rv = -1;
+		goto out;
 #else
 		struct disklabel lab;
 		struct partition *parta;
@@ -144,21 +147,29 @@
 		fd = open(path, O_RDONLY);
 		if (fd == -1) {
 			*error = errno;
-			return -1;
+			rv = -1;
+			goto out;
 		}
 
 		if (ioctl(fd, DIOCGDINFO, &lab) == -1) {
 			*error = errno;
-			return -1;
+			rv = -1;
+			goto out;
 		}
 		close(fd);
 
 		parta = &lab.d_partitions[DISKPART(sb.st_rdev)];
-		*size = (uint64_t)lab.d_secsize * parta->p_size;
+		size = (uint64_t)lab.d_secsize * parta->p_size;
 #endif /* __NetBSD__ */
 	}
 
-	return 0;
+ out:
+	if (rv == 0 && sizep)
+		*sizep = size;
+	if (rv == 0 && ftp)
+		*ftp = ft;
+
+	return rv;
 }
 
 int

Reply via email to