diff options
Diffstat (limited to 'src/firejail/util.c')
-rw-r--r-- | src/firejail/util.c | 43 |
1 files changed, 0 insertions, 43 deletions
diff --git a/src/firejail/util.c b/src/firejail/util.c index cea2b76e3..fde180e49 100644 --- a/src/firejail/util.c +++ b/src/firejail/util.c | |||
@@ -908,49 +908,6 @@ void mkdir_attr(const char *fname, mode_t mode, uid_t uid, gid_t gid) { | |||
908 | ASSERT_PERMS(fname, uid, gid, mode); | 908 | ASSERT_PERMS(fname, uid, gid, mode); |
909 | } | 909 | } |
910 | 910 | ||
911 | char *read_text_file_or_exit(const char *fname) { | ||
912 | assert(fname); | ||
913 | |||
914 | // open file | ||
915 | int fd = open(fname, O_RDONLY); | ||
916 | if (fd == -1) { | ||
917 | fprintf(stderr, "Error: cannot read %s\n", fname); | ||
918 | exit(1); | ||
919 | } | ||
920 | |||
921 | int size = lseek(fd, 0, SEEK_END); | ||
922 | if (size == -1) | ||
923 | goto errexit; | ||
924 | if (lseek(fd, 0 , SEEK_SET) == -1) | ||
925 | goto errexit; | ||
926 | |||
927 | // allocate memory | ||
928 | char *data = malloc(size + 1); // + '\0' | ||
929 | if (data == NULL) | ||
930 | goto errexit; | ||
931 | memset(data, 0, size + 1); | ||
932 | |||
933 | // read file | ||
934 | int rd = 0; | ||
935 | while (rd < size) { | ||
936 | int rv = read(fd, (unsigned char *) data + rd, size - rd); | ||
937 | if (rv == -1) { | ||
938 | goto errexit; | ||
939 | } | ||
940 | rd += rv; | ||
941 | } | ||
942 | |||
943 | // close file | ||
944 | close(fd); | ||
945 | return data; | ||
946 | |||
947 | errexit: | ||
948 | close(fd); | ||
949 | fprintf(stderr, "Error: cannot read %s\n", fname); | ||
950 | exit(1); | ||
951 | } | ||
952 | |||
953 | |||
954 | unsigned extract_timeout(const char *str) { | 911 | unsigned extract_timeout(const char *str) { |
955 | unsigned s; | 912 | unsigned s; |
956 | unsigned m; | 913 | unsigned m; |