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