Unistd.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #pragma once
  17. #ifndef _WIN32
  18. #include <unistd.h>
  19. #else
  20. #include <cstdint>
  21. #include <sys/locking.h> // @manual
  22. #include <folly/portability/SysTypes.h>
  23. // This is different from the normal headers because there are a few cases,
  24. // such as close(), where we need to override the definition of an existing
  25. // function. To avoid conflicts at link time, everything here is in a namespace
  26. // which is then used globally.
  27. #define _SC_PAGESIZE 1
  28. #define _SC_PAGE_SIZE _SC_PAGESIZE
  29. #define _SC_NPROCESSORS_ONLN 2
  30. #define _SC_NPROCESSORS_CONF 2
  31. // Windows doesn't define these, but these are the correct values
  32. // for Windows.
  33. #define STDIN_FILENO 0
  34. #define STDOUT_FILENO 1
  35. #define STDERR_FILENO 2
  36. // Windows is weird and doesn't actually defined these
  37. // for the parameters to access, so we have to do it ourselves -_-...
  38. #define F_OK 0
  39. #define X_OK F_OK
  40. #define W_OK 2
  41. #define R_OK 4
  42. #define RW_OK 6
  43. #define F_LOCK _LK_LOCK
  44. #define F_ULOCK _LK_UNLCK
  45. namespace folly {
  46. namespace portability {
  47. namespace unistd {
  48. int access(char const* fn, int am);
  49. int chdir(const char* path);
  50. int close(int fh);
  51. int dup(int fh);
  52. int dup2(int fhs, int fhd);
  53. int fsync(int fd);
  54. int ftruncate(int fd, off_t len);
  55. char* getcwd(char* buf, int sz);
  56. int getdtablesize();
  57. int getgid();
  58. pid_t getpid();
  59. pid_t getppid();
  60. int getuid();
  61. int isatty(int fh);
  62. int lockf(int fd, int cmd, off_t len);
  63. off_t lseek(int fh, off_t off, int orig);
  64. ssize_t read(int fh, void* buf, size_t mcc);
  65. int rmdir(const char* path);
  66. int pipe(int pth[2]);
  67. ssize_t pread(int fd, void* buf, size_t count, off_t offset);
  68. ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset);
  69. ssize_t readlink(const char* path, char* buf, size_t buflen);
  70. void* sbrk(intptr_t i);
  71. unsigned int sleep(unsigned int seconds);
  72. long sysconf(int tp);
  73. int truncate(const char* path, off_t len);
  74. int usleep(unsigned int ms);
  75. ssize_t write(int fh, void const* buf, size_t count);
  76. } // namespace unistd
  77. } // namespace portability
  78. } // namespace folly
  79. /* using override */ using namespace folly::portability::unistd;
  80. #endif