libtransistor
A userland library for the Nintendo Switch
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
fd.h
Go to the documentation of this file.
1 
8 #pragma once
9 
10 #ifdef __cplusplus
11 extern "C" {
12 #endif
13 
14 #include<libtransistor/types.h>
15 
16 #include <sys/types.h>
17 #include <stdint.h>
18 
19 typedef struct trn_file_t trn_file_t;
20 
25 typedef struct {
26  result_t (*seek) (void *data, off_t offset, int whence, off_t *out);
27  result_t (*read) (void *data, void *buf, size_t size, size_t *bytes_read);
28  result_t (*write) (void *data, const void *buf, size_t size, size_t *bytes_written);
29  //result_t (*flush) (void *data);
30 
31  // Release data, and file_operations if it was allocated.
32  result_t (*release) (trn_file_t *file);
34 
38 struct trn_file_t {
39  _Atomic(int) refcount;
40  trn_file_ops_t *ops;
41  void *data;
42 };
43 
50 int fd_create_file(trn_file_ops_t *fops, void *data);
51 
57 trn_file_t *fd_file_get(int fd);
58 
63 
67 int fd_close(int fd);
68 
69 // Duplicates oldfd, and all its associated locks, into newfd. Newfd is closed
70 // if necessary
76 int fd_dup2(int oldfd, int newfd);
77 
78 #ifdef __cplusplus
79 }
80 #endif
int fd_create_file(trn_file_ops_t *fops, void *data)
Create a file from fops and data.
Various system types.
void fd_file_put(trn_file_t *file)
Decrease the fd_file refcount, and release it if this is the last one.
int fd_dup2(int oldfd, int newfd)
Duplicates oldfd, and all its associated locks, into newfd.
Definition: fd.h:38
uint32_t result_t
Function result.
Definition: types.h:51
int fd_close(int fd)
Close the file descriptor.
Definition: fd.h:25
trn_file_t * fd_file_get(int fd)
Get the file structure from a given fd, and increment its rc.