-
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#define _GNU_SOURCE | ||
#include <dlfcn.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
|
||
static void init(void) __attribute__((constructor)); | ||
|
||
static int (*orig_open)(const char *path, int flags, mode_t mode); | ||
|
||
/* | ||
* Constructor. | ||
* | ||
* Save pointer to the original open function. | ||
*/ | ||
static void init(void) { | ||
orig_open = dlsym(RTLD_NEXT, "open"); | ||
} | ||
|
||
/* | ||
* Wrapper for the open function. | ||
* | ||
* If we are opening an MKV file, override the mode. | ||
*/ | ||
int open(const char *path, int flags, mode_t mode) { | ||
char *dot = strrchr(path, '.'); | ||
if (dot && strcmp(dot, ".mkv") == 0) { | ||
return orig_open(path, flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); | ||
} | ||
else { | ||
return orig_open(path, flags, mode); | ||
} | ||
} |