From f4166e2dd7a4d9be95f160e19303ddeeb5d27ab4 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 23 Dec 2015 08:57:48 +0000 Subject: prefer rb_syserr_fail * file.c, io.c, util.c: prefer rb_syserr_fail with saved errno over setting errno then call rb_sys_fail, not to be clobbered potentially and to reduce thread local errno accesses. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53264 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- util.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'util.c') diff --git a/util.c b/util.c index 89dec0d19b..95ac2b09b5 100644 --- a/util.c +++ b/util.c @@ -507,9 +507,10 @@ ruby_getcwd(void) char *buf = xmalloc(size); while (!getcwd(buf, size)) { - if (errno != ERANGE) { + int e = errno; + if (e != ERANGE) { xfree(buf); - rb_sys_fail("getcwd"); + rb_syserr_fail(e, "getcwd"); } size *= 2; buf = xrealloc(buf, size); @@ -527,8 +528,9 @@ ruby_getcwd(void) char *buf = xmalloc(PATH_MAX+1); if (!getwd(buf)) { + int e = errno; xfree(buf); - rb_sys_fail("getwd"); + rb_syserr_fail(e, "getwd"); } #endif return buf; -- cgit v1.2.1