Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 30 Apr 2015 20:47:34 +0000 (UTC)
From:      Mariusz Zaborski <oshogbo@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r282282 - in head/sys: kern sys
Message-ID:  <201504302047.t3UKlY1m044643@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: oshogbo
Date: Thu Apr 30 20:47:33 2015
New Revision: 282282
URL: https://svnweb.freebsd.org/changeset/base/282282

Log:
  Rename macros to use prefix ERRNO. Add macro ERRNO_SET. Now
  ERRNO_{RESTORE/SAVE} must by used together, additional variable is not
  needed. Always use ERRNO_{SAVE/RESTORE/SET} macros.
  
  Approved by:	pjd (mentor)

Modified:
  head/sys/kern/subr_nvlist.c
  head/sys/kern/subr_nvpair.c
  head/sys/sys/nv_impl.h

Modified: head/sys/kern/subr_nvlist.c
==============================================================================
--- head/sys/kern/subr_nvlist.c	Thu Apr 30 19:23:50 2015	(r282281)
+++ head/sys/kern/subr_nvlist.c	Thu Apr 30 20:47:33 2015	(r282282)
@@ -142,12 +142,11 @@ void
 nvlist_destroy(nvlist_t *nvl)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (nvl == NULL)
 		return;
 
-	SAVE_ERRNO(serrno);
+	ERRNO_SAVE();
 
 	NVLIST_ASSERT(nvl);
 
@@ -158,7 +157,7 @@ nvlist_destroy(nvlist_t *nvl)
 	nvl->nvl_magic = 0;
 	nv_free(nvl);
 
-	RESTORE_ERRNO(serrno);
+	ERRNO_RESTORE();
 }
 
 void
@@ -264,7 +263,7 @@ nvlist_find(const nvlist_t *nvl, int typ
 	}
 
 	if (nvp == NULL)
-		RESTORE_ERRNO(ENOENT);
+		ERRNO_SET(ENOENT);
 
 	return (nvp);
 }
@@ -307,7 +306,7 @@ nvlist_clone(const nvlist_t *nvl)
 	NVLIST_ASSERT(nvl);
 
 	if (nvl->nvl_error != 0) {
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return (NULL);
 	}
 
@@ -596,7 +595,7 @@ nvlist_xpack(const nvlist_t *nvl, int64_
 	NVLIST_ASSERT(nvl);
 
 	if (nvl->nvl_error != 0) {
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return (NULL);
 	}
 
@@ -686,12 +685,12 @@ nvlist_pack(const nvlist_t *nvl, size_t 
 	NVLIST_ASSERT(nvl);
 
 	if (nvl->nvl_error != 0) {
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return (NULL);
 	}
 
 	if (nvlist_ndescriptors(nvl) > 0) {
-		RESTORE_ERRNO(EOPNOTSUPP);
+		ERRNO_SET(EOPNOTSUPP);
 		return (NULL);
 	}
 
@@ -703,11 +702,11 @@ nvlist_check_header(struct nvlist_header
 {
 
 	if (nvlhdrp->nvlh_magic != NVLIST_HEADER_MAGIC) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (false);
 	}
 	if ((nvlhdrp->nvlh_flags & ~NV_FLAG_ALL_MASK) != 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (false);
 	}
 #if BYTE_ORDER == BIG_ENDIAN
@@ -759,7 +758,7 @@ nvlist_unpack_header(nvlist_t *nvl, cons
 
 	return (ptr);
 failed:
-	RESTORE_ERRNO(EINVAL);
+	ERRNO_SET(EINVAL);
 	return (NULL);
 }
 
@@ -853,10 +852,10 @@ nvlist_send(int sock, const nvlist_t *nv
 	int *fds;
 	void *data;
 	int64_t fdidx;
-	int serrno, ret;
+	int ret;
 
 	if (nvlist_error(nvl) != 0) {
-		errno = nvlist_error(nvl);
+		ERRNO_SET(nvlist_error(nvl));
 		return (-1);
 	}
 
@@ -882,10 +881,10 @@ nvlist_send(int sock, const nvlist_t *nv
 
 	ret = 0;
 out:
-	serrno = errno;
+	ERRNO_SAVE();
 	free(fds);
 	free(data);
-	errno = serrno;
+	ERRNO_RESTORE();
 	return (ret);
 }
 
@@ -896,7 +895,7 @@ nvlist_recv(int sock)
 	nvlist_t *nvl, *ret;
 	unsigned char *buf;
 	size_t nfds, size, i;
-	int serrno, *fds;
+	int *fds;
 
 	if (buf_recv(sock, &nvlhdr, sizeof(nvlhdr)) == -1)
 		return (NULL);
@@ -929,19 +928,19 @@ nvlist_recv(int sock)
 
 	nvl = nvlist_xunpack(buf, size, fds, nfds);
 	if (nvl == NULL) {
-		SAVE_ERRNO(serrno);
+		ERRNO_SAVE();
 		for (i = 0; i < nfds; i++)
 			close(fds[i]);
-		RESTORE_ERRNO(serrno);
+		ERRNO_RESTORE();
 		goto out;
 	}
 
 	ret = nvl;
 out:
-	serrno = errno;
+	ERRNO_SAVE();
 	free(buf);
 	free(fds);
-	errno = serrno;
+	ERRNO_RESTORE();
 
 	return (ret);
 }
@@ -1054,19 +1053,19 @@ nvlist_add_nvpair(nvlist_t *nvl, const n
 	NVPAIR_ASSERT(nvp);
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 	if (nvlist_exists(nvl, nvpair_name(nvp))) {
 		nvl->nvl_error = EEXIST;
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	newnvp = nvpair_clone(nvp);
 	if (newnvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
@@ -1090,14 +1089,14 @@ nvlist_add_stringv(nvlist_t *nvl, const 
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_stringv(name, valuefmt, valueap);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1109,14 +1108,14 @@ nvlist_add_null(nvlist_t *nvl, const cha
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_null(name);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1128,14 +1127,14 @@ nvlist_add_bool(nvlist_t *nvl, const cha
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_bool(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1147,14 +1146,14 @@ nvlist_add_number(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_number(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1166,14 +1165,14 @@ nvlist_add_string(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_string(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1185,14 +1184,14 @@ nvlist_add_nvlist(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_nvlist(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1224,14 +1223,14 @@ nvlist_add_binary(nvlist_t *nvl, const c
 	nvpair_t *nvp;
 
 	if (nvlist_error(nvl) != 0) {
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_create_binary(name, value, size);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1246,13 +1245,13 @@ nvlist_move_nvpair(nvlist_t *nvl, nvpair
 
 	if (nvlist_error(nvl) != 0) {
 		nvpair_free(nvp);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 	if (nvlist_exists(nvl, nvpair_name(nvp))) {
 		nvpair_free(nvp);
 		nvl->nvl_error = EEXIST;
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 		return;
 	}
 
@@ -1266,14 +1265,14 @@ nvlist_move_string(nvlist_t *nvl, const 
 
 	if (nvlist_error(nvl) != 0) {
 		nv_free(value);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_string(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1287,14 +1286,14 @@ nvlist_move_nvlist(nvlist_t *nvl, const 
 	if (nvlist_error(nvl) != 0) {
 		if (value != NULL && nvlist_get_nvpair_parent(value) != NULL)
 			nvlist_destroy(value);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_nvlist(name, value);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}
@@ -1308,15 +1307,17 @@ nvlist_move_descriptor(nvlist_t *nvl, co
 
 	if (nvlist_error(nvl) != 0) {
 		close(value);
-		errno = nvlist_error(nvl);
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_descriptor(name, value);
-	if (nvp == NULL)
-		nvl->nvl_error = errno = (errno != 0 ? errno : ENOMEM);
-	else
+	if (nvp == NULL) {
+		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
+		ERRNO_SET(nvl->nvl_error);
+	} else {
 		nvlist_move_nvpair(nvl, nvp);
+	}
 }
 #endif
 
@@ -1327,14 +1328,14 @@ nvlist_move_binary(nvlist_t *nvl, const 
 
 	if (nvlist_error(nvl) != 0) {
 		nv_free(value);
-		RESTORE_ERRNO(nvlist_error(nvl));
+		ERRNO_SET(nvlist_error(nvl));
 		return;
 	}
 
 	nvp = nvpair_move_binary(name, value, size);
 	if (nvp == NULL) {
 		nvl->nvl_error = ERRNO_OR_DEFAULT(ENOMEM);
-		RESTORE_ERRNO(nvl->nvl_error);
+		ERRNO_SET(nvl->nvl_error);
 	} else {
 		nvlist_move_nvpair(nvl, nvp);
 	}

Modified: head/sys/kern/subr_nvpair.c
==============================================================================
--- head/sys/kern/subr_nvpair.c	Thu Apr 30 19:23:50 2015	(r282281)
+++ head/sys/kern/subr_nvpair.c	Thu Apr 30 20:47:33 2015	(r282282)
@@ -468,7 +468,7 @@ nvpair_unpack_header(bool isbe, nvpair_t
 
 	return (ptr);
 failed:
-	RESTORE_ERRNO(EINVAL);
+	ERRNO_SET(EINVAL);
 	return (NULL);
 }
 
@@ -480,7 +480,7 @@ nvpair_unpack_null(bool isbe __unused, n
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NULL);
 
 	if (nvp->nvp_datasize != 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -496,11 +496,11 @@ nvpair_unpack_bool(bool isbe __unused, n
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BOOL);
 
 	if (nvp->nvp_datasize != sizeof(value)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 	if (*leftp < sizeof(value)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -509,7 +509,7 @@ nvpair_unpack_bool(bool isbe __unused, n
 	*leftp -= sizeof(value);
 
 	if (value != 0 && value != 1) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -526,11 +526,11 @@ nvpair_unpack_number(bool isbe, nvpair_t
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NUMBER);
 
 	if (nvp->nvp_datasize != sizeof(uint64_t)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 	if (*leftp < sizeof(uint64_t)) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -552,13 +552,13 @@ nvpair_unpack_string(bool isbe __unused,
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_STRING);
 
 	if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	if (strnlen((const char *)ptr, nvp->nvp_datasize) !=
 	    nvp->nvp_datasize - 1) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -581,7 +581,7 @@ nvpair_unpack_nvlist(bool isbe __unused,
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_NVLIST);
 
 	if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -609,11 +609,11 @@ nvpair_unpack_descriptor(bool isbe, nvpa
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_DESCRIPTOR);
 
 	if (nvp->nvp_datasize != sizeof(idx)) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 	if (*leftp < sizeof(idx)) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -623,12 +623,12 @@ nvpair_unpack_descriptor(bool isbe, nvpa
 		idx = le64dec(ptr);
 
 	if (idx < 0) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	if ((size_t)idx >= nfds) {
-		errno = EINVAL;
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -650,7 +650,7 @@ nvpair_unpack_binary(bool isbe __unused,
 	PJDLOG_ASSERT(nvp->nvp_type == NV_TYPE_BINARY);
 
 	if (*leftp < nvp->nvp_datasize || nvp->nvp_datasize == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -725,7 +725,7 @@ nvpair_allocv(const char *name, int type
 
 	namelen = strlen(name);
 	if (namelen >= NV_NAME_MAX) {
-		RESTORE_ERRNO(ENAMETOOLONG);
+		ERRNO_SET(ENAMETOOLONG);
 		return (NULL);
 	}
 
@@ -802,7 +802,7 @@ nvpair_create_string(const char *name, c
 	char *data;
 
 	if (value == NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -826,7 +826,7 @@ nvpair_create_nvlist(const char *name, c
 	nvpair_t *nvp;
 
 	if (value == NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -848,10 +848,9 @@ nvpair_t *
 nvpair_create_descriptor(const char *name, int value)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value < 0 || !fd_is_valid(value)) {
-		errno = EBADF;
+		ERRNO_SET(EBADF);
 		return (NULL);
 	}
 
@@ -862,9 +861,9 @@ nvpair_create_descriptor(const char *nam
 	nvp = nvpair_allocv(name, NV_TYPE_DESCRIPTOR, (uint64_t)value,
 	    sizeof(int64_t));
 	if (nvp == NULL) {
-		SAVE_ERRNO(serrno);
+		ERRNO_SAVE();
 		close(value);
-		RESTORE_ERRNO(serrno);
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);
@@ -878,7 +877,7 @@ nvpair_create_binary(const char *name, c
 	void *data;
 
 	if (value == NULL || size == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
@@ -899,19 +898,18 @@ nvpair_t *
 nvpair_move_string(const char *name, char *value)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value == NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	nvp = nvpair_allocv(name, NV_TYPE_STRING, (uint64_t)(uintptr_t)value,
 	    strlen(value) + 1);
 	if (nvp == NULL) {
-		SAVE_ERRNO(serrno);
+		ERRNO_SAVE();
 		nv_free(value);
-		RESTORE_ERRNO(serrno);
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);
@@ -923,12 +921,12 @@ nvpair_move_nvlist(const char *name, nvl
 	nvpair_t *nvp;
 
 	if (value == NULL || nvlist_get_nvpair_parent(value) != NULL) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	if (nvlist_error(value) != 0) {
-		RESTORE_ERRNO(nvlist_error(value));
+		ERRNO_SET(nvlist_error(value));
 		nvlist_destroy(value);
 		return (NULL);
 	}
@@ -948,19 +946,18 @@ nvpair_t *
 nvpair_move_descriptor(const char *name, int value)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value < 0 || !fd_is_valid(value)) {
-		errno = EBADF;
+		ERRNO_SET(EBADF);
 		return (NULL);
 	}
 
 	nvp = nvpair_allocv(name, NV_TYPE_DESCRIPTOR, (uint64_t)value,
 	    sizeof(int64_t));
 	if (nvp == NULL) {
-		serrno = errno;
+		ERRNO_SAVE();
 		close(value);
-		errno = serrno;
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);
@@ -971,19 +968,18 @@ nvpair_t *
 nvpair_move_binary(const char *name, void *value, size_t size)
 {
 	nvpair_t *nvp;
-	int serrno;
 
 	if (value == NULL || size == 0) {
-		RESTORE_ERRNO(EINVAL);
+		ERRNO_SET(EINVAL);
 		return (NULL);
 	}
 
 	nvp = nvpair_allocv(name, NV_TYPE_BINARY, (uint64_t)(uintptr_t)value,
 	    size);
 	if (nvp == NULL) {
-		SAVE_ERRNO(serrno);
+		ERRNO_SAVE();
 		nv_free(value);
-		RESTORE_ERRNO(serrno);
+		ERRNO_RESTORE();
 	}
 
 	return (nvp);

Modified: head/sys/sys/nv_impl.h
==============================================================================
--- head/sys/sys/nv_impl.h	Thu Apr 30 19:23:50 2015	(r282281)
+++ head/sys/sys/nv_impl.h	Thu Apr 30 20:47:33 2015	(r282282)
@@ -56,8 +56,9 @@ typedef struct nvpair nvpair_t;
 #define	nv_strdup(buf)			strdup((buf), M_NVLIST)
 #define	nv_vasprintf(ptr, ...)		vasprintf(ptr, M_NVLIST, __VA_ARGS__)
 
-#define	SAVE_ERRNO(var)			((void)(var))
-#define	RESTORE_ERRNO(var)		((void)(var))
+#define	ERRNO_SET(var)			do { } while (0)
+#define	ERRNO_SAVE()			do { do { } while(0)
+#define	ERRNO_RESTORE()			} while (0)
 
 #define	ERRNO_OR_DEFAULT(default)	(default)
 
@@ -70,8 +71,14 @@ typedef struct nvpair nvpair_t;
 #define	nv_strdup(buf)			strdup((buf))
 #define	nv_vasprintf(ptr, ...)		vasprintf(ptr, __VA_ARGS__)
 
-#define	SAVE_ERRNO(var)			(var) = errno
-#define	RESTORE_ERRNO(var)		errno = (var)
+#define	ERRNO_SET(var)			do { errno = (var); } while (0)
+#define	ERRNO_SAVE()			do {				\
+						int _serrno;		\
+									\
+						_serrno = errno
+
+#define	ERRNO_RESTORE()				errno = _serrno;	\
+					} while (0)
 
 #define	ERRNO_OR_DEFAULT(default)	(errno == 0 ? (default) : errno)
 



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201504302047.t3UKlY1m044643>