Josh Gao | a4f9c17 | 2016-07-28 18:09:48 -0700 | [diff] [blame^] | 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 | #endif |