The function had just one caller and a name that didn't explain much.
Let's make it static and rename for clarity.
While at it, the only caller was not doing error handling correctly
— the function would potentially return a negative error value which
wasn't handled. In practice this couldn't happen, but let's remove
this ambiguity.
char **saved_argv = NULL;
static int saved_in_initrd = -1;
-int prot_from_flags(int flags) {
-
- switch (flags & O_ACCMODE) {
-
- case O_RDONLY:
- return PROT_READ;
-
- case O_WRONLY:
- return PROT_WRITE;
-
- case O_RDWR:
- return PROT_READ|PROT_WRITE;
-
- default:
- return -EINVAL;
- }
-}
-
bool in_initrd(void) {
int r;
const char *e;
saved_argv = argv;
}
-int prot_from_flags(int flags) _const_;
-
bool in_initrd(void);
void in_initrd_force(bool value);
# pragma GCC diagnostic ignored "-Waddress-of-packed-member"
#endif
+static int mmap_prot_from_open_flags(int flags) {
+ switch (flags & O_ACCMODE) {
+ case O_RDONLY:
+ return PROT_READ;
+ case O_WRONLY:
+ return PROT_WRITE;
+ case O_RDWR:
+ return PROT_READ|PROT_WRITE;
+ default:
+ assert_not_reached();
+ }
+}
+
int journal_file_tail_end_by_pread(JournalFile *f, uint64_t *ret_offset) {
uint64_t p;
int r;
newly_created = f->last_stat.st_size == 0 && journal_file_writable(f);
}
- f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, prot_from_flags(open_flags));
+ f->cache_fd = mmap_cache_add_fd(mmap_cache, f->fd, mmap_prot_from_open_flags(open_flags));
if (!f->cache_fd) {
r = -ENOMEM;
goto fail;