OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
heavyai_fs.h
Go to the documentation of this file.
1 /*
2  * Copyright 2022 HEAVY.AI, 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 #include <cstddef>
20 #include <cstdint>
21 #include <cstdio>
22 
23 #ifndef _WIN32
24 #include <fcntl.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #endif // not _WIN32
28 
29 namespace heavyai {
30 
31 size_t file_size(const int fd);
32 
33 void* checked_mmap(const int fd, const size_t sz);
34 
35 void checked_munmap(void* addr, size_t length);
36 
37 int msync(void* addr, size_t length, bool async);
38 
39 int fsync(int fd);
40 
41 int open(const char* path, int flags, int mode);
42 
43 void close(const int fd);
44 
45 ::FILE* fopen(const char* filename, const char* mode);
46 
47 ::FILE* popen(const char* command, const char* type);
48 
49 int32_t pclose(::FILE* fh);
50 
51 int get_page_size();
52 
53 int32_t ftruncate(const int32_t fd, int64_t length);
54 
55 #ifndef _WIN32
56 // Signal-safe versions of low-level posix functions. Won't fail w/EINTR.
57 int safe_open(const char* path, int flags, mode_t mode) noexcept;
58 int safe_close(int fd) noexcept;
59 int safe_fcntl(int fd, int cmd, struct flock* fl) noexcept;
60 ssize_t safe_read(const int fd, void* buffer, const size_t buffer_size) noexcept;
61 ssize_t safe_write(const int fd, const void* buffer, const size_t buffer_size) noexcept;
62 int32_t safe_ftruncate(const int32_t fd, int64_t length) noexcept;
63 #endif // not _WIN32
64 
65 } // namespace heavyai
int safe_open(const char *path, int flags, mode_t mode) noexcept
Definition: heavyai_fs.cpp:90
int32_t pclose(::FILE *fh)
Definition: heavyai_fs.cpp:82
::FILE * popen(const char *command, const char *type)
Definition: heavyai_fs.cpp:78
ssize_t safe_read(const int fd, void *buffer, const size_t buffer_size) noexcept
Definition: heavyai_fs.cpp:123
ssize_t safe_write(const int fd, const void *buffer, const size_t buffer_size) noexcept
Definition: heavyai_fs.cpp:144
future< Result > async(Fn &&fn, Args &&...args)
int open(const char *path, int flags, int mode)
Definition: heavyai_fs.cpp:66
::FILE * fopen(const char *filename, const char *mode)
Definition: heavyai_fs.cpp:74
int msync(void *addr, size_t length, bool async)
Definition: heavyai_fs.cpp:57
int32_t safe_ftruncate(const int32_t fd, int64_t length) noexcept
Definition: heavyai_fs.cpp:162
int fsync(int fd)
Definition: heavyai_fs.cpp:62
void checked_munmap(void *addr, size_t length)
Definition: heavyai_fs.cpp:53
int32_t ftruncate(const int32_t fd, int64_t length)
Definition: heavyai_fs.cpp:86
void close(const int fd)
Definition: heavyai_fs.cpp:70
int safe_fcntl(int fd, int cmd, struct flock *fl) noexcept
Definition: heavyai_fs.cpp:112
int safe_close(int fd) noexcept
Definition: heavyai_fs.cpp:101
int get_page_size()
Definition: heavyai_fs.cpp:29
size_t file_size(const int fd)
Definition: heavyai_fs.cpp:33
void * checked_mmap(const int fd, const size_t sz)
Definition: heavyai_fs.cpp:40