| 1 | //===--- Linux specialization of the File data structure ------------------===// |
| 2 | // |
| 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
| 9 | #include "hdr/types/off_t.h" |
| 10 | #include "src/__support/File/file.h" |
| 11 | #include "src/__support/macros/config.h" |
| 12 | |
| 13 | namespace LIBC_NAMESPACE_DECL { |
| 14 | |
| 15 | FileIOResult linux_file_write(File *, const void *, size_t); |
| 16 | FileIOResult linux_file_read(File *, void *, size_t); |
| 17 | ErrorOr<off_t> linux_file_seek(File *, off_t, int); |
| 18 | int linux_file_close(File *); |
| 19 | |
| 20 | class LinuxFile : public File { |
| 21 | int fd; |
| 22 | |
| 23 | public: |
| 24 | constexpr LinuxFile(int file_descriptor, uint8_t *buffer, size_t buffer_size, |
| 25 | int buffer_mode, bool owned, File::ModeFlags modeflags) |
| 26 | : File(&linux_file_write, &linux_file_read, &linux_file_seek, |
| 27 | &linux_file_close, buffer, buffer_size, buffer_mode, owned, |
| 28 | modeflags), |
| 29 | fd(file_descriptor) {} |
| 30 | |
| 31 | int get_fd() const { return fd; } |
| 32 | }; |
| 33 | |
| 34 | // Create a File object and associate it with a fd. |
| 35 | ErrorOr<LinuxFile *> create_file_from_fd(int fd, const char *mode); |
| 36 | |
| 37 | } // namespace LIBC_NAMESPACE_DECL |
| 38 | |