SysStat.cpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2016-present Facebook, Inc.
  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. #include <folly/portability/SysStat.h>
  17. #ifdef _WIN32
  18. #include <folly/portability/Windows.h>
  19. extern "C" {
  20. int chmod(char const* fn, int am) {
  21. return _chmod(fn, am);
  22. }
  23. int fchmod(int fd, mode_t mode) {
  24. HANDLE h = (HANDLE)_get_osfhandle(fd);
  25. if (h == INVALID_HANDLE_VALUE) {
  26. return -1;
  27. }
  28. FILE_ATTRIBUTE_TAG_INFO attr{};
  29. if (!GetFileInformationByHandleEx(
  30. h, FileAttributeTagInfo, &attr, sizeof(attr))) {
  31. return -1;
  32. }
  33. if (mode & _S_IWRITE) {
  34. attr.FileAttributes &= ~FILE_ATTRIBUTE_READONLY;
  35. } else {
  36. attr.FileAttributes |= FILE_ATTRIBUTE_READONLY;
  37. }
  38. if (!SetFileInformationByHandle(
  39. h, FileAttributeTagInfo, &attr, sizeof(attr))) {
  40. return -1;
  41. }
  42. return 0;
  43. }
  44. // Just return the result of a normal stat for now
  45. int lstat(const char* path, struct stat* st) {
  46. return stat(path, st);
  47. }
  48. int mkdir(const char* fn, int /* mode */) {
  49. return _mkdir(fn);
  50. }
  51. int umask(int md) {
  52. return _umask(md);
  53. }
  54. }
  55. #endif