From: Junio C Hamano Date: Tue, 04 Aug 2015 21:03:15 GMT Subject: Re: [PATCH] git_open_noatime: return with errno=0 on success Message-ID: In-Reply-To: <20150804082429.GA22271@musxeris015.imu.intel.com> Clemens Buchacher writes: > diff --git a/sha1_file.c b/sha1_file.c > index 77cd81d..62b7ad6 100644 > --- a/sha1_file.c > +++ b/sha1_file.c > @@ -1453,6 +1453,7 @@ int git_open_noatime(const char *name) > static int sha1_file_open_flag = O_NOATIME; > > for (;;) { > + errno = 0; > int fd = open(name, O_RDONLY | sha1_file_open_flag); Please avoid decl-after-stmt, which this codebase does not accept. > if (fd >= 0) > return fd; More importantly, is this the right place to clear errno? I would agree it is a good idea to clear it after seeing the first open fail due to lack of O_NOATIME before trying open for the second time, iow, more like this? sha1_file.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sha1_file.c b/sha1_file.c index 1cee438..bf2f229 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1467,6 +1467,7 @@ int git_open_noatime(const char *name) /* Might the failure be due to O_NOATIME? */ if (errno != ENOENT && sha1_file_open_flag) { + errno = 0; sha1_file_open_flag = 0; continue; }