Date: Sat, 4 Mar 2017 21:32:23 +0000 (UTC) From: Baptiste Daroussin <bapt@FreeBSD.org> To: src-committers@freebsd.org, svn-src-user@freebsd.org Subject: svn commit: r314680 - user/bapt/diff Message-ID: <201703042132.v24LWNY4083669@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: bapt Date: Sat Mar 4 21:32:23 2017 New Revision: 314680 URL: https://svnweb.freebsd.org/changeset/base/314680 Log: Remove code that seems to be useless diff(1) was trying to open the non regular file and copy it to a temporary file. the code will already anyway read it. Modified: user/bapt/diff/diffreg.c Modified: user/bapt/diff/diffreg.c ============================================================================== --- user/bapt/diff/diffreg.c Sat Mar 4 21:06:40 2017 (r314679) +++ user/bapt/diff/diffreg.c Sat Mar 4 21:32:23 2017 (r314680) @@ -194,7 +194,6 @@ struct context_vec { }; #define diff_output printf -static FILE *opentemp(const char *); static void output(char *, FILE *, char *, FILE *, int); static void check(FILE *, FILE *, int); static void range(int, int, const char *); @@ -334,14 +333,7 @@ diffreg(char *file1, char *file2, int fl if (flags & D_EMPTY1) f1 = fopen(_PATH_DEVNULL, "r"); else { - if (!S_ISREG(stb1.st_mode)) { - if ((f1 = opentemp(file1)) == NULL || - fstat(fileno(f1), &stb1) < 0) { - warn("%s", file1); - status |= 2; - goto closem; - } - } else if (strcmp(file1, "-") == 0) + if (strcmp(file1, "-") == 0) f1 = stdin; else f1 = fopen(file1, "r"); @@ -355,14 +347,7 @@ diffreg(char *file1, char *file2, int fl if (flags & D_EMPTY2) f2 = fopen(_PATH_DEVNULL, "r"); else { - if (!S_ISREG(stb2.st_mode)) { - if ((f2 = opentemp(file2)) == NULL || - fstat(fileno(f2), &stb2) < 0) { - warn("%s", file2); - status |= 2; - goto closem; - } - } else if (strcmp(file2, "-") == 0) + if (strcmp(file2, "-") == 0) f2 = stdin; else f2 = fopen(file2, "r"); @@ -549,37 +534,6 @@ files_differ(FILE *f1, FILE *f2, int fla } } -static FILE * -opentemp(const char *path) -{ - char buf[BUFSIZ], tempfile[PATH_MAX]; - ssize_t nread; - int ifd, ofd; - - if (strcmp(path, "-") == 0) - ifd = STDIN_FILENO; - else if ((ifd = open(path, O_RDONLY, 0644)) < 0) - return (NULL); - - (void)strlcpy(tempfile, _PATH_TMP "/diff.XXXXXXXX", sizeof(tempfile)); - - if ((ofd = mkstemp(tempfile)) < 0) { - close(ifd); - return (NULL); - } - unlink(tempfile); - while ((nread = read(ifd, buf, BUFSIZ)) > 0) { - if (write(ofd, buf, nread) != nread) { - close(ifd); - close(ofd); - return (NULL); - } - } - close(ifd); - lseek(ofd, (off_t)0, SEEK_SET); - return (fdopen(ofd, "r")); -} - char * splice(char *dir, char *path) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201703042132.v24LWNY4083669>