~csurbhi/ubuntu/maverick/e2fsprogs/e2fsprogs.fix-505719

« back to all changes in this revision

Viewing changes to lib/e2p/fgetflags.c

  • Committer: Bazaar Package Importer
  • Author(s): Matt Zimmerman
  • Date: 2004-09-19 09:43:14 UTC
  • mto: (8.1.1 lenny) (1.2.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040919094314-2tafd19i76fhu6ei
Tags: upstream-1.35
ImportĀ upstreamĀ versionĀ 1.35

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
#if HAVE_UNISTD_H
24
24
#include <unistd.h>
25
25
#endif
26
 
#if HAVE_STAT_FLAGS
 
26
#include <sys/types.h>
27
27
#include <sys/stat.h>
28
 
#else
 
28
#if HAVE_EXT2_IOCTLS
29
29
#include <fcntl.h>
30
30
#include <sys/ioctl.h>
31
31
#endif
40
40
 
41
41
int fgetflags (const char * name, unsigned long * flags)
42
42
{
43
 
#if HAVE_STAT_FLAGS
44
43
        struct stat buf;
 
44
#if HAVE_STAT_FLAGS && !(APPLE_DARWIN && HAVE_EXT2_IOCTLS)
45
45
 
46
46
        if (stat (name, &buf) == -1)
47
47
                return -1;
63
63
        return 0;
64
64
#else
65
65
#if HAVE_EXT2_IOCTLS
66
 
        int fd, r, f;
 
66
        int fd, r, f, save_errno = 0;
67
67
 
 
68
        if (!stat(name, &buf) &&
 
69
            !S_ISREG(buf.st_mode) && !S_ISDIR(buf.st_mode)) {
 
70
                goto notsupp;
 
71
        }
 
72
#if !APPLE_DARWIN
68
73
        fd = open (name, OPEN_FLAGS);
69
74
        if (fd == -1)
70
75
                return -1;
71
76
        r = ioctl (fd, EXT2_IOC_GETFLAGS, &f);
 
77
        if (r == -1)
 
78
                save_errno = errno;
72
79
        *flags = f;
73
 
 
74
80
        close (fd);
 
81
        if (save_errno)
 
82
                errno = save_errno;
75
83
        return r;
76
 
#else /* ! HAVE_EXT2_IOCTLS */
77
 
        extern int errno;
 
84
#else
 
85
   f = -1;
 
86
   save_errno = syscall(SYS_fsctl, name, EXT2_IOC_GETFLAGS, &f, 0);
 
87
   *flags = f;
 
88
   return (save_errno);
 
89
#endif
 
90
#endif /* HAVE_EXT2_IOCTLS */
 
91
#endif
 
92
notsupp:
78
93
        errno = EOPNOTSUPP;
79
94
        return -1;
80
 
#endif /* ! HAVE_EXT2_IOCTLS */
81
 
#endif
82
95
}