• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 #pragma once
18 
19 #include <sys/stat.h>
20 #include <sys/types.h>
21 #include <unistd.h>
22 
23 #if defined(_WIN32)
24 // stat is broken on Win32: stat on a path with a trailing slash or backslash will always fail with
25 // ENOENT.
26 int adb_stat(const char* path, struct adb_stat* buf);
27 
28 // We later define a macro mapping 'stat' to 'adb_stat'. This causes:
29 //   struct stat s;
30 //   stat(filename, &s);
31 // To turn into the following:
32 //   struct adb_stat s;
33 //   adb_stat(filename, &s);
34 // To get this to work, we need to make 'struct adb_stat' the same as
35 // 'struct stat'. Note that this definition of 'struct adb_stat' uses the
36 // *current* macro definition of stat, so it may actually be inheriting from
37 // struct _stat32i64 (or some other remapping).
38 struct adb_stat : public stat {};
39 
40 #undef stat
41 #define stat adb_stat
42 
43 // Windows doesn't have lstat.
44 #define lstat adb_stat
45 
46 // mingw doesn't define S_IFLNK or S_ISLNK.
47 #define S_IFLNK 0120000
48 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK)
49 
50 // mingw defines S_IFBLK to a different value from bionic.
51 #undef S_IFBLK
52 #define S_IFBLK 0060000
53 #undef S_ISBLK
54 #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK)
55 #endif
56 
57 // Make sure that host file mode values match the ones on the device.
58 static_assert(S_IFMT == 00170000, "");
59 static_assert(S_IFLNK == 0120000, "");
60 static_assert(S_IFREG == 0100000, "");
61 static_assert(S_IFBLK == 0060000, "");
62 static_assert(S_IFDIR == 0040000, "");
63 static_assert(S_IFCHR == 0020000, "");
64