- int fd;
- struct stat statbuf;
- FILE *fp;
-
- if (mode[0] == 'w' || mode[0] == 'a')
- {
- errno = EISDIR;
- return NULL;
- }
-
- fd = open (filename, O_RDONLY);
- if (fd < 0)
- return NULL;
-
- if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
- {
- errno = ENOTDIR;
- return NULL;
- }
-
- fp = fdopen (fd, mode);
- if (fp == NULL)
- {
- int saved_errno = errno;
- close (fd);
- errno = saved_errno;
- }
- return fp;
+ int fd;
+ struct stat statbuf;
+ FILE *fp;
+
+ if (mode[0] == 'w' || mode[0] == 'a')
+ {
+ errno = EISDIR;
+ return NULL;
+ }
+
+ fd = open (filename, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ if (fstat (fd, &statbuf) >= 0 && !S_ISDIR (statbuf.st_mode))
+ {
+ close (fd);
+ errno = ENOTDIR;
+ return NULL;
+ }
+
+ fp = fdopen (fd, mode);
+ if (fp == NULL)
+ {
+ int saved_errno = errno;
+ close (fd);
+ errno = saved_errno;
+ }
+ return fp;