Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/diff/diffreg_new.c
| Show All 27 Lines | |||||
| #include <stdbool.h> | #include <stdbool.h> | ||||
| #include <stdint.h> | #include <stdint.h> | ||||
| #include <stdio.h> | #include <stdio.h> | ||||
| #include <stdlib.h> | #include <stdlib.h> | ||||
| #include <string.h> | #include <string.h> | ||||
| #include <time.h> | #include <time.h> | ||||
| #include <unistd.h> | #include <unistd.h> | ||||
| #include "pr.h" | |||||
| #include "diff.h" | #include "diff.h" | ||||
| #include <arraylist.h> | #include <arraylist.h> | ||||
| #include <diff_main.h> | #include <diff_main.h> | ||||
| #include <diff_output.h> | #include <diff_output.h> | ||||
| const char *format_label(const char *, struct stat *); | const char *format_label(const char *, struct stat *); | ||||
| enum diffreg_algo { | enum diffreg_algo { | ||||
| ▲ Show 20 Lines • Show All 97 Lines • ▼ Show 20 Lines | format_label(const char *oldlabel, struct stat *stb) | ||||
| return newlabel; | return newlabel; | ||||
| } | } | ||||
| int | int | ||||
| diffreg_new(char *file1, char *file2, int flags, int capsicum) | diffreg_new(char *file1, char *file2, int flags, int capsicum) | ||||
| { | { | ||||
| char *str1, *str2; | char *str1, *str2; | ||||
| FILE *f1, *f2; | FILE *f1, *f2; | ||||
| struct pr *pr = NULL; | |||||
| struct stat st1, st2; | struct stat st1, st2; | ||||
| struct diff_input_info info; | struct diff_input_info info; | ||||
| struct diff_data left = {}, right = {}; | struct diff_data left = {}, right = {}; | ||||
| struct diff_result *result = NULL; | struct diff_result *result = NULL; | ||||
| bool force_text, have_binary; | bool force_text, have_binary; | ||||
| int rc, atomizer_flags, rflags, diff_flags = 0; | int rc, atomizer_flags, rflags, diff_flags = 0; | ||||
| int context_lines = diff_context; | int context_lines = diff_context; | ||||
| const struct diff_config *cfg; | const struct diff_config *cfg; | ||||
| Show All 16 Lines | diffreg_new(char *file1, char *file2, int flags, int capsicum) | ||||
| case DIFFREG_ALGO_NONE: | case DIFFREG_ALGO_NONE: | ||||
| cfg = &diff_config_no_algo; | cfg = &diff_config_no_algo; | ||||
| break; | break; | ||||
| } | } | ||||
| f1 = openfile(file1, &str1, &st1); | f1 = openfile(file1, &str1, &st1); | ||||
| f2 = openfile(file2, &str2, &st2); | f2 = openfile(file2, &str2, &st2); | ||||
| if (flags & D_PAGINATION) | |||||
| pr = start_pr(file1, file2); | |||||
| if (capsicum) { | if (capsicum) { | ||||
| cap_rights_init(&rights_ro, CAP_READ, CAP_FSTAT, CAP_SEEK); | cap_rights_init(&rights_ro, CAP_READ, CAP_FSTAT, CAP_SEEK); | ||||
| if (caph_rights_limit(fileno(f1), &rights_ro) < 0) | if (caph_rights_limit(fileno(f1), &rights_ro) < 0) | ||||
| err(2, "unable to limit rights on: %s", file1); | err(2, "unable to limit rights on: %s", file1); | ||||
| if (caph_rights_limit(fileno(f2), &rights_ro) < 0) | if (caph_rights_limit(fileno(f2), &rights_ro) < 0) | ||||
| err(2, "unable to limit rights on: %s", file2); | err(2, "unable to limit rights on: %s", file2); | ||||
| if (fileno(f1) == STDIN_FILENO || fileno(f2) == STDIN_FILENO) { | if (fileno(f1) == STDIN_FILENO || fileno(f2) == STDIN_FILENO) { | ||||
| /* stdin has already been limited */ | /* stdin has already been limited */ | ||||
| ▲ Show 20 Lines • Show All 77 Lines • ▼ Show 20 Lines | diffreg_new(char *file1, char *file2, int flags, int capsicum) | ||||
| if (rc != DIFF_RC_OK) { | if (rc != DIFF_RC_OK) { | ||||
| rc = D_ERROR; | rc = D_ERROR; | ||||
| status |= 2; | status |= 2; | ||||
| } else { | } else { | ||||
| rc = D_DIFFER; | rc = D_DIFFER; | ||||
| status |= 1; | status |= 1; | ||||
| } | } | ||||
| done: | done: | ||||
| if (pr != NULL) | |||||
| stop_pr(pr); | |||||
| diff_result_free(result); | diff_result_free(result); | ||||
| diff_data_free(&left); | diff_data_free(&left); | ||||
| diff_data_free(&right); | diff_data_free(&right); | ||||
| #ifndef DIFF_NO_MMAP | #ifndef DIFF_NO_MMAP | ||||
| if (str1) | if (str1) | ||||
| munmap(str1, st1.st_size); | munmap(str1, st1.st_size); | ||||
| if (str2) | if (str2) | ||||
| munmap(str2, st2.st_size); | munmap(str2, st2.st_size); | ||||
| ▲ Show 20 Lines • Show All 54 Lines • Show Last 20 Lines | |||||