git » libfiu » commit fef533c

preload/posix: Do not hard-code the number of possible errnos

author Alberto Bertogli
2009-07-15 16:33:02 UTC
committer Alberto Bertogli
2009-07-15 16:33:02 UTC
parent c9e3d59c54bede9e1b8388b4e67b5592cd1b6b82

preload/posix: Do not hard-code the number of possible errnos

Since the errnos vary from platform to platform, do not use a hardcoded
number but derive it from the size of valid_errnos.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

preload/posix/codegen.h +3 -2
preload/posix/generate +2 -3
preload/posix/modules/posix.custom.c +1 -1

diff --git a/preload/posix/codegen.h b/preload/posix/codegen.h
index 04d00ee..66ece82 100644
--- a/preload/posix/codegen.h
+++ b/preload/posix/codegen.h
@@ -117,13 +117,14 @@ extern int __thread _fiu_called;
 /* Generates the body of the function for functions that affect errno. The
  * return value is hardcoded. Assumes int valid_errnos[] exist was properly
  * defined. */
-#define mkwrap_body_errno(FIU_NAME, FAIL_RET, NVERRNOS) \
+#define mkwrap_body_errno(FIU_NAME, FAIL_RET) \
 								\
 		fstatus = fiu_fail(FIU_NAME);			\
 		if (fstatus != 0) {				\
 			void *finfo = fiu_failinfo();		\
 			if (finfo == NULL) {			\
-				errno = valid_errnos[random() % NVERRNOS]; \
+				errno = valid_errnos[random() % \
+					sizeof(valid_errnos) / sizeof(int)]; \
 			} else {				\
 				errno = (long) finfo;		\
 			}					\
diff --git a/preload/posix/generate b/preload/posix/generate
index b5a3989..c61ddd2 100755
--- a/preload/posix/generate
+++ b/preload/posix/generate
@@ -109,9 +109,8 @@ class Function:
 			# be explicit 
 			self.write_valid_errnos(f)
 
-			f.write('mkwrap_body_errno("%s", %s, %d)\n' % \
-					(self.fiu_name, self.on_error,
-						len(self.valid_errnos)) )
+			f.write('mkwrap_body_errno("%s", %s)\n' % \
+					(self.fiu_name, self.on_error) )
 		elif self.on_error is not None:
 			f.write('mkwrap_body_hardcoded("%s", %s)\n' % \
 					(self.fiu_name, self.on_error) )
diff --git a/preload/posix/modules/posix.custom.c b/preload/posix/modules/posix.custom.c
index 55329fa..5de0599 100644
--- a/preload/posix/modules/posix.custom.c
+++ b/preload/posix/modules/posix.custom.c
@@ -61,7 +61,7 @@ int open(const char *pathname, int flags, ...)
 	 * set mode to something */
 
 	int valid_errnos[] = { EACCES, EFAULT, EFBIG, EOVERFLOW, ELOOP, EMFILE, ENAMETOOLONG, ENFILE, ENOENT, ENOMEM, ENOSPC, ENOTDIR, EROFS };
-mkwrap_body_errno("posix/io/oc/open", -1, 13)
+mkwrap_body_errno("posix/io/oc/open", -1)
 mkwrap_bottom(open, (pathname, flags, mode))