diff options
author | Lukas Czerner <lczerner@redhat.com> | 2011-09-15 23:44:48 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2011-09-15 23:46:57 -0400 |
commit | c859cb1de0d624caa0779fb17d1a53766143136e (patch) | |
tree | 0cbd868dc9bcda7eeb2463535b38f34aad6587e4 /lib/ext2fs/ext2fs.h | |
parent | db8bbf27c9eeaa9c1803fb52a6cc7a60c5250c7e (diff) | |
download | e2fsprogs-c859cb1de0d624caa0779fb17d1a53766143136e.tar.gz |
e2fsprogs: create open() and stat() helpers
In many places we are using #ifdef HAVE_OPEN64 to determine if we can
use open64() but that's ugly. This commit creates two new helpers
ext2fs_open_file() for open() and ext2fs_stat() for stat(). Also we need
new typedef ext2fs_struct_stat for struct stat.
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'lib/ext2fs/ext2fs.h')
-rw-r--r-- | lib/ext2fs/ext2fs.h | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 9c0160f7..3d8c3cb4 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -585,6 +585,12 @@ typedef struct ext2_icount *ext2_icount_t; #define EXT2FS_NUM_B2C(fs, blks) (((blks) + EXT2FS_CLUSTER_MASK(fs)) >> \ (fs)->cluster_ratio_bits) +#ifdef HAVE_OPEN64 +typedef struct stat64 ext2fs_struct_stat; +#else +typedef struct stat ext2fs_struct_stat; +#endif + /* * function prototypes */ @@ -1393,6 +1399,8 @@ extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, struct ext2_inode *inode); extern unsigned int ext2fs_div_ceil(unsigned int a, unsigned int b); extern __u64 ext2fs_div64_ceil(__u64 a, __u64 b); +extern int ext2fs_open_file(const char *pathname, int flags, ...); +extern int ext2fs_stat(const char *path, ext2fs_struct_stat *buf); /* * The actual inlined functions definitions themselves... @@ -1643,6 +1651,36 @@ _INLINE_ __u64 ext2fs_div64_ceil(__u64 a, __u64 b) return ((a - 1) / b) + 1; } +_INLINE_ int ext2fs_open_file(const char *pathname, int flags, ...) +{ + va_list args; + mode_t mode; + + va_start(args, flags); + mode = va_arg(args, mode_t); + va_end(args); + + if (mode) +#ifdef HAVE_OPEN64 + return open64(pathname, flags, mode); + else + return open64(pathname, flags); +#else + return open(pathname, flags, mode); + else + return open(pathname, flags); +#endif +} + +_INLINE_ int ext2fs_stat(const char *path, ext2fs_struct_stat *buf) +{ +#ifdef HAVE_OPEN64 + return stat64(path, buf); +#else + return open(path, buf); +#endif +} + #undef _INLINE_ #endif |