XROAD
xroad_file.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "xroad_string.h"
9 #include "xroad_typed_containers.h"
10 
11 #include <unistd.h>
12 #include <limits.h>
13 #include <sys/uio.h>
14 #include <fcntl.h>
15 
16 #ifdef __cplusplus
17 extern "C"
18 {
19 #endif
20 
21 typedef enum
22 {
25 
27 #define __xroad_fd_dtor__ __dtor__(xroad_cleanup_fdclose)
28 
30 static inline void xroad_cleanup_fdclose(int* pfd)
31 {
32  if (pfd && *pfd >= 0)
33  {
34  close(*pfd);
35  }
36 }
37 
39 xroad_errno_t xroad_writev_all(int fd, struct iovec* iov, size_t c);
40 
47 xroad_errno_t xroad_dir_ls(xroad_str_t path, uint32_t flags, xroad_str_hset_t* dirs);
48 
50 int xroad_file_open_and_lock(const char* name, bool create);
51 
60 int xroad_file_lock(int fd, bool exclusive, bool block);
61 
68 int xroad_file_unlock(int fd);
69 
79 int xroad_file_lock_byte(int fd, off_t offset, bool exclusive, bool block);
80 
88 int xroad_file_unlock_byte(int fd, off_t offset);
89 
93 int xroad_file_lock_byte_ofd(int fd, off_t offset, bool exclusive, bool block);
94 
98 int xroad_file_unlock_byte_ofd(int fd, off_t offset);
99 
103 const char* xroad_get_cwd(void);
104 
105 #ifdef __cplusplus
106 }
107 #endif
Definition: xroad_string.h:29
int xroad_file_unlock(int fd)
int xroad_file_lock_byte_ofd(int fd, off_t offset, bool exclusive, bool block)
xroad_errno_t xroad_writev_all(int fd, struct iovec *iov, size_t c)
Function to write all data from an array of struct iovec structures to a file descriptor.
xroad_errno_t xroad_dir_ls(xroad_str_t path, uint32_t flags, xroad_str_hset_t *dirs)
int xroad_file_unlock_byte_ofd(int fd, off_t offset)
int xroad_file_lock(int fd, bool exclusive, bool block)
int xroad_file_unlock_byte(int fd, off_t offset)
int xroad_file_open_and_lock(const char *name, bool create)
Open (possibly create) for read/write and lock a file.
int xroad_file_lock_byte(int fd, off_t offset, bool exclusive, bool block)
xroad_dir_ls_flags_t
Definition: xroad_file.h:22
@ xroad_dir_ls_flags_hidden
ls hidden (started with .)
Definition: xroad_file.h:23
const char * xroad_get_cwd(void)