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