• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014, The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef _StatPortable_H_
18 #define _StatPortable_H_
19 
20 #include <portability.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <sys/stat.h>
24 
25 #define __STAT64_BODY_PORTABLE \
26   unsigned long st_dev; \
27   unsigned long st_ino; \
28   unsigned long st_mode; \
29   unsigned long st_nlink; \
30   uid_t st_uid; /* 32-bit uid_t */ \
31   unsigned char padding[4]; \
32   gid_t st_gid; /* 32-bit gid_t */ \
33   unsigned char padding2[4]; \
34   unsigned long st_rdev; \
35   long st_size; \
36   long st_blksize; \
37   long st_blocks; \
38   long st_atime; \
39   unsigned long st_atime_nsec; \
40   long st_mtime; \
41   unsigned long st_mtime_nsec; \
42   long st_ctime; \
43   unsigned long st_ctime_nsec; \
44   unsigned char padding3[8];
45 
46 struct StatPortable { __STAT64_BODY_PORTABLE };
47 typedef struct StatPortable Stat64Portable;
48 
stat_n2p(struct stat * pn,struct StatPortable * pp)49 static inline void stat_n2p(struct stat* pn, struct StatPortable* pp)
50 {
51   memset(pp, '\0', sizeof(struct StatPortable));
52   pp->st_dev        = pn->st_dev;
53   pp->st_ino        = pn->st_ino;
54   pp->st_mode       = pn->st_mode;
55   pp->st_nlink      = pn->st_nlink;
56   pp->st_uid        = pn->st_uid;
57   pp->st_gid        = pn->st_gid;
58   pp->st_rdev       = pn->st_rdev;
59   pp->st_size       = pn->st_size;
60   pp->st_blksize    = pn->st_blksize;
61   pp->st_blocks     = pn->st_blocks;
62   pp->st_atime      = pn->st_atime;
63   pp->st_atime_nsec = pn->st_atime_nsec;
64   pp->st_mtime      = pn->st_mtime;
65   pp->st_mtime_nsec = pn->st_mtime_nsec;
66   pp->st_ctime      = pn->st_ctime;
67   pp->st_ctime_nsec = pn->st_ctime_nsec;
68 }
69 
WRAP(fstat)70 int WRAP(fstat)(int a, struct StatPortable* p)
71 {
72   struct stat target_stat_obj;
73   int ret = REAL(fstat)(a, &target_stat_obj);
74   stat_n2p(&target_stat_obj, p);
75   return ret;
76 }
77 
WRAP(fstat64)78 int WRAP(fstat64)(int a, Stat64Portable* p)
79 {
80   return WRAP(fstat)(a, p);
81 }
82 
WRAP(fstatat)83 int WRAP(fstatat)(int a, const char* p1, struct StatPortable* p2, int b)
84 {
85   struct stat target_stat_obj;
86   int ret = REAL(fstatat)(a, p1, &target_stat_obj, b);
87   stat_n2p(&target_stat_obj, p2);
88   return ret;
89 }
90 
WRAP(fstatat64)91 int WRAP(fstatat64)(int a, const char* b, Stat64Portable* c, int d)
92 {
93   return WRAP(fstatat)(a, b, c, d);
94 }
95 
WRAP(lstat)96 int WRAP(lstat)(const char* a, struct StatPortable* p)
97 {
98   struct stat target_stat_obj;
99   int ret = REAL(lstat)(a, &target_stat_obj);
100   stat_n2p(&target_stat_obj, p);
101   return ret;
102 }
103 
WRAP(lstat64)104 int WRAP(lstat64)(const char* a, Stat64Portable* p)
105 {
106   return WRAP(lstat)(a, p);
107 }
108 
WRAP(stat)109 int WRAP(stat)(const char* a, struct StatPortable* p)
110 {
111   struct stat target_stat_obj;
112   int ret = REAL(stat)(a, &target_stat_obj);
113   stat_n2p(&target_stat_obj, p);
114   return ret;
115 }
116 
WRAP(stat64)117 int WRAP(stat64)(const char* a, Stat64Portable* p)
118 {
119   return WRAP(stat)(a, p);
120 }
121 
122 #endif /* _StatPortable_H */
123