Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/librumpuser Make int *error and optional parameter (i.e....
details: https://anonhg.NetBSD.org/src/rev/a5e7de291236
branches: trunk
changeset: 758782:a5e7de291236
user: pooka <pooka%NetBSD.org@localhost>
date: Mon Nov 15 15:23:32 2010 +0000
description:
Make int *error and optional parameter (i.e. it can be NULL).
Sometimes the caller just doesn't care which errno close() might
throw.
diffstat:
lib/librumpuser/rumpuser.c | 48 +++++++++++++++++++++---------------------
lib/librumpuser/rumpuser_int.h | 12 ++++++----
lib/librumpuser/rumpuser_net.c | 12 +++++-----
3 files changed, 37 insertions(+), 35 deletions(-)
diffs (292 lines):
diff -r 965d2dd3ccbf -r a5e7de291236 lib/librumpuser/rumpuser.c
--- a/lib/librumpuser/rumpuser.c Mon Nov 15 14:40:36 2010 +0000
+++ b/lib/librumpuser/rumpuser.c Mon Nov 15 15:23:32 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser.c,v 1.9 2010/08/11 10:25:59 pooka Exp $ */
+/* $NetBSD: rumpuser.c,v 1.10 2010/11/15 15:23:32 pooka Exp $ */
/*
* Copyright (c) 2007-2010 Antti Kantee. All Rights Reserved.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser.c,v 1.9 2010/08/11 10:25:59 pooka Exp $");
+__RCSID("$NetBSD: rumpuser.c,v 1.10 2010/11/15 15:23:32 pooka Exp $");
#endif /* !lint */
/* thank the maker for this */
@@ -82,7 +82,7 @@
int needsdev = 0, rv = 0, ft;
if (stat(path, &sb) == -1) {
- *error = errno;
+ seterror(errno);
return -1;
}
@@ -129,7 +129,7 @@
fd = open(path, O_RDONLY);
if (fd == -1) {
- *error = errno;
+ seterror(errno);
rv = -1;
goto out;
}
@@ -142,7 +142,7 @@
}
fprintf(stderr, "error: device size query not implemented on "
"this platform\n");
- *error = EOPNOTSUPP;
+ sererror(EOPNOTSUPP);
rv = -1;
goto out;
#else
@@ -152,13 +152,13 @@
fd = open(path, O_RDONLY);
if (fd == -1) {
- *error = errno;
+ seterror(errno);
rv = -1;
goto out;
}
if (ioctl(fd, DIOCGDINFO, &lab) == -1) {
- *error = errno;
+ seterror(errno);
rv = -1;
goto out;
}
@@ -191,7 +191,7 @@
KLOCK_WRAP(rv = nanosleep(&rqt, &rmt));
if (rv == -1)
- *error = errno;
+ seterror(errno);
*sec = rmt.tv_sec;
*nsec = rmt.tv_nsec;
@@ -249,7 +249,7 @@
rv = mmap(prefaddr, size, prot,
MAP_ANON | MAP_ALIGNED(alignbit), -1, 0);
if (rv == MAP_FAILED) {
- *error = errno;
+ seterror(errno);
return NULL;
}
return rv;
@@ -287,11 +287,11 @@
rv = mmap(NULL, len, PROT_READ|PROT_WRITE, mmflags, fd, offset);
if (rv == MAP_FAILED) {
- *error = errno;
+ seterror(errno);
return NULL;
}
- *error = 0;
+ seterror(0);
return rv;
}
@@ -337,7 +337,7 @@
KLOCK_WRAP(rv = read(fd, data, size));
if (rv == -1)
- *error = errno;
+ seterror(errno);
return rv;
}
@@ -349,7 +349,7 @@
KLOCK_WRAP(rv = pread(fd, data, size, offset));
if (rv == -1)
- *error = errno;
+ seterror(errno);
return rv;
}
@@ -377,7 +377,7 @@
KLOCK_WRAP(rv = write(fd, data, size));
if (rv == -1)
- *error = errno;
+ seterror(errno);
return rv;
}
@@ -389,7 +389,7 @@
KLOCK_WRAP(rv = pwrite(fd, data, size, offset));
if (rv == -1)
- *error = errno;
+ seterror(errno);
return rv;
}
@@ -420,7 +420,7 @@
iovp = malloc(iovcnt * sizeof(struct iovec));
if (iovp == NULL) {
- *error = ENOMEM;
+ seterror(ENOMEM);
return -1;
}
for (i = 0; i < iovcnt; i++) {
@@ -431,7 +431,7 @@
KLOCK_WRAP(rv = readv(fd, iovp, iovcnt));
if (rv == -1)
- *error = errno;
+ seterror(errno);
free(iovp);
return rv;
@@ -447,7 +447,7 @@
iovp = malloc(iovcnt * sizeof(struct iovec));
if (iovp == NULL) {
- *error = ENOMEM;
+ seterror(ENOMEM);
return -1;
}
for (i = 0; i < iovcnt; i++) {
@@ -458,7 +458,7 @@
KLOCK_WRAP(rv = writev(fd, iovp, iovcnt));
if (rv == -1)
- *error = errno;
+ seterror(errno);
free(iovp);
return rv;
@@ -472,7 +472,7 @@
rv = gettimeofday(&tv, NULL);
if (rv == -1) {
- *error = errno;
+ seterror(errno);
return rv;
}
@@ -535,7 +535,7 @@
if (kq == -1) {
kq = kqueue();
if (kq == -1) {
- *error = errno;
+ seterror(errno);
return -1;
}
}
@@ -543,7 +543,7 @@
EV_SET(&kev, fd, EVFILT_VNODE, EV_ADD|EV_ENABLE|EV_CLEAR,
NOTE_WRITE, 0, opaque);
if (kevent(kq, &kev, 1, NULL, 0, NULL) == -1) {
- *error = errno;
+ seterror(errno);
return -1;
}
@@ -561,7 +561,7 @@
if (rv == -1) {
if (errno == EINTR)
goto again;
- *error = errno;
+ seterror(errno);
return -1;
}
@@ -598,7 +598,7 @@
}
#else
/* XXXfixme: signal numbers may not match on non-NetBSD */
- *error = EOPNOTSUPP;
+ seterror(EOPNOTSUPP);
return -1;
#endif
}
diff -r 965d2dd3ccbf -r a5e7de291236 lib/librumpuser/rumpuser_int.h
--- a/lib/librumpuser/rumpuser_int.h Mon Nov 15 14:40:36 2010 +0000
+++ b/lib/librumpuser/rumpuser_int.h Mon Nov 15 15:23:32 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_int.h,v 1.3 2010/05/18 14:58:41 pooka Exp $ */
+/* $NetBSD: rumpuser_int.h,v 1.4 2010/11/15 15:23:32 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@@ -33,6 +33,8 @@
extern kernel_unlockfn rumpuser__kunlock;
extern int rumpuser__wantthreads;
+#define seterror(value) do { if (error) *error = value;} while (/*CONSTCOND*/0)
+
#define KLOCK_WRAP(a) \
do { \
int nlocks; \
@@ -46,9 +48,9 @@
rvtype rv; \
rv = call; \
if (rv == -1) \
- *error = errno; \
+ seterror(errno); \
else \
- *error = 0; \
+ seterror(0); \
return rv; \
}
@@ -60,8 +62,8 @@
rv = call; \
rumpuser__klock(nlocks, NULL); \
if (rv == -1) \
- *error = errno; \
+ seterror(errno); \
else \
- *error = 0; \
+ seterror(0); \
return rv; \
}
diff -r 965d2dd3ccbf -r a5e7de291236 lib/librumpuser/rumpuser_net.c
--- a/lib/librumpuser/rumpuser_net.c Mon Nov 15 14:40:36 2010 +0000
+++ b/lib/librumpuser/rumpuser_net.c Mon Nov 15 15:23:32 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rumpuser_net.c,v 1.1 2010/02/26 18:54:20 pooka Exp $ */
+/* $NetBSD: rumpuser_net.c,v 1.2 2010/11/15 15:23:32 pooka Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@@ -27,7 +27,7 @@
#include <sys/cdefs.h>
#if !defined(lint)
-__RCSID("$NetBSD: rumpuser_net.c,v 1.1 2010/02/26 18:54:20 pooka Exp $");
+__RCSID("$NetBSD: rumpuser_net.c,v 1.2 2010/11/15 15:23:32 pooka Exp $");
#endif /* !lint */
#include <sys/types.h>
@@ -102,9 +102,9 @@
*lenp = slen;
if (rv == -1)
- *error = errno;
+ seterror(errno);
else
- *error = 0;
+ seterror(0);
return rv;
}
@@ -118,8 +118,8 @@
rv = setsockopt(s, level, name, data, slen);
if (rv == -1)
- *error = errno;
+ seterror(errno);
else
- *error = 0;
+ seterror(0);
return rv;
}
Home |
Main Index |
Thread Index |
Old Index