blob: ed2cf25fb04f404f94ca01ed91bef709a0864594 [file] [log] [blame]
Josh Gaoa4f9c172016-07-28 18:09:48 -07001/*
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.
26int 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).
38struct 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
Josh Gao8998a8d2016-11-18 15:17:07 -080046// 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)
Josh Gaoa4f9c172016-07-28 18:09:48 -070055#endif
Josh Gao8998a8d2016-11-18 15:17:07 -080056
57// Make sure that host file mode values match the ones on the device.
58static_assert(S_IFMT == 00170000, "");
59static_assert(S_IFLNK == 0120000, "");
60static_assert(S_IFREG == 0100000, "");
61static_assert(S_IFBLK == 0060000, "");
62static_assert(S_IFDIR == 0040000, "");
63static_assert(S_IFCHR == 0020000, "");