| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
#pragma once |
| 3 |
|
| 4 |
#include "shared-forward.h" |
| 5 |
#include "list.h" |
| 6 |
|
| 7 |
typedef enum OpenFileFlag { |
| 8 |
OPENFILE_READ_ONLY = 1 << 0, |
| 9 |
OPENFILE_APPEND = 1 << 1, |
| 10 |
OPENFILE_TRUNCATE = 1 << 2, |
| 11 |
OPENFILE_GRACEFUL = 1 << 3, |
| 12 |
_OPENFILE_MAX, |
| 13 |
_OPENFILE_INVALID = -EINVAL, |
| 14 |
_OPENFILE_MASK_PUBLIC = OPENFILE_READ_ONLY | OPENFILE_APPEND | OPENFILE_TRUNCATE | OPENFILE_GRACEFUL, |
| 15 |
} OpenFileFlag; |
| 16 |
|
| 17 |
typedef struct OpenFile { |
| 18 |
char *path; |
| 19 |
char *fdname; |
| 20 |
OpenFileFlag flags; |
| 21 |
LIST_FIELDS(struct OpenFile, open_files); |
| 22 |
} OpenFile; |
| 23 |
|
| 24 |
int open_file_parse(const char *v, OpenFile **ret); |
| 25 |
|
| 26 |
int open_file_validate(const OpenFile *of); |
| 27 |
|
| 28 |
int open_file_to_string(const OpenFile *of, char **ret); |
| 29 |
|
| 30 |
OpenFile* open_file_free(OpenFile *of); |
| 31 |
DEFINE_TRIVIAL_CLEANUP_FUNC(OpenFile*, open_file_free); |
| 32 |
|
| 33 |
static inline void open_file_free_many(OpenFile **head) { |
| 34 |
LIST_CLEAR(open_files, *ASSERT_PTR(head), open_file_free); |
| 35 |
} |
| 36 |
|
| 37 |
DECLARE_STRING_TABLE_LOOKUP(open_file_flags, OpenFileFlag); |