[syslinux] [PATCH 3/3] COM32/stat(): preset ret and move zeroing errno
Gene Cumm
gene.cumm at gmail.com
Thu Mar 5 18:50:21 PST 2009
From: Gene Cumm <gene.cumm at gmail.com>
COM32/stat(): preset ret and move zeroing errno
Signed-off-by: Gene Cumm <gene.cumm at gmail.com>
---
Depends on string of patches this week
diff --git a/com32/lib/sys/stat.c b/com32/lib/sys/stat.c
index d1b2629..da55e0c 100644
--- a/com32/lib/sys/stat.c
+++ b/com32/lib/sys/stat.c
@@ -28,7 +28,9 @@
/*
* stat.c
*
- * Very trivial stat emulation by using open(), fstat(), close()
+ * Very trivial stat emulation by using open(), then either fstat() and
+ * close() or opendir() and closedir(). Probably more expensive than it
+ * should be.
*/
#include <sys/stat.h>
@@ -41,32 +43,32 @@
int stat(const char *pathname, struct stat *buf)
{
- int fd, status, ret;
+ int fd, status, ret = -1;
+ /* int terr; */
DIR *d;
mode_t st_mode;
fd = open(pathname, O_RDONLY);
if (fd != -1){
status = fstat(fd, buf);
+ /* terr = errno; */ /* FIXME:should fstat()'s error be
+ preserved over close()'s error? */
close(fd);
+ /* errno = terr; */
ret = 0;
} else {
if ((errno == 0) || (errno == ENOENT)) {
- errno = 0;
st_mode = (S_IFDIR | S_IRUSR | S_IXUSR);
/* | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)
- */
+ */ /* FIXME: Should these modes be included? */
d = opendir(pathname);
if (d != NULL) {
+ errno = 0; /* No real error occurred */
buf->st_size = 0;
buf->st_mode = st_mode;
closedir(d);
ret = 0;
- } else {
- ret = -1; /* Preserve errno */
}
- } else {
- ret = -1; /* Preserve errno */
}
}
return ret;
More information about the Syslinux
mailing list