]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pmdk/src/windows/include/unistd.h
1 /* SPDX-License-Identifier: BSD-3-Clause */
2 /* Copyright 2015-2020, Intel Corporation */
5 * unistd.h -- compatibility layer for POSIX operating system API
13 #define _SC_PAGESIZE 0
14 #define _SC_NPROCESSORS_ONLN 1
18 #define X_OK 00 /* execute permission doesn't exist on Windows */
22 * sysconf -- get configuration information at run time
35 case _SC_NPROCESSORS_ONLN
:
36 for (int i
= 0; i
< GetActiveProcessorGroupCount(); i
++) {
37 ret
+= GetActiveProcessorCount(i
);
47 #define getpid _getpid
50 * pread -- read from a file descriptor at given offset
53 pread(int fd
, void *buf
, size_t count
, os_off_t offset
)
55 __int64 position
= _lseeki64(fd
, 0, SEEK_CUR
);
56 _lseeki64(fd
, offset
, SEEK_SET
);
57 int ret
= _read(fd
, buf
, (unsigned)count
);
58 _lseeki64(fd
, position
, SEEK_SET
);
63 * pwrite -- write to a file descriptor at given offset
66 pwrite(int fd
, const void *buf
, size_t count
, os_off_t offset
)
68 __int64 position
= _lseeki64(fd
, 0, SEEK_CUR
);
69 _lseeki64(fd
, offset
, SEEK_SET
);
70 int ret
= _write(fd
, buf
, (unsigned)count
);
71 _lseeki64(fd
, position
, SEEK_SET
);
75 #define S_ISBLK(x) 0 /* BLK devices not exist on Windows */
78 * basename -- parse pathname and return filename component
83 char fname
[_MAX_FNAME
];
85 _splitpath(path
, NULL
, NULL
, fname
, ext
);
87 sprintf(path
, "%s%s", fname
, ext
);
93 * dirname -- parse pathname and return directory component
101 size_t len
= strlen(path
);
105 char *end
= path
+ len
;
107 /* strip trailing forslashes and backslashes */
108 while ((--end
) > path
) {
109 if (*end
!= '\\' && *end
!= '/') {
116 while ((--end
) > path
) {
117 if (*end
== '\\' || *end
== '/') {
125 /* handle edge cases */
126 } else if (*end
== '\\' || *end
== '/') {
136 #endif /* UNISTD_H */