2 * Copyright 2017 Facebook, Inc.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <folly/portability/SysStat.h>
20 #include <folly/portability/Windows.h>
23 int chmod(char const* fn, int am) {
24 return _chmod(fn, am);
27 int fchmod(int fd, mode_t mode) {
28 HANDLE h = (HANDLE)_get_osfhandle(fd);
29 if (h == INVALID_HANDLE_VALUE) {
33 FILE_ATTRIBUTE_TAG_INFO attr{};
34 if (!GetFileInformationByHandleEx(
35 h, FileAttributeTagInfo, &attr, sizeof(attr))) {
39 if (mode & _S_IWRITE) {
40 attr.FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
42 attr.FileAttributes |= FILE_ATTRIBUTE_READONLY;
45 if (!SetFileInformationByHandle(
46 h, FileAttributeTagInfo, &attr, sizeof(attr))) {
53 // Just return the result of a normal stat for now
54 int lstat(const char* path, struct stat* st) {
55 return stat(path, st);
58 int mkdir(const char* fn, int /* mode */) {