Deleted Added
full compact
main.c (217133) main.c (252231)
1/*-
1/*-
2 * Copyright (c) 2013 Johann 'Myrkraverk' Oskarsson.
2 * Copyright (c) 1992 Diomidis Spinellis.
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Diomidis Spinellis of Imperial College, University of London.
8 *
9 * Redistribution and use in source and binary forms, with or without

--- 17 unchanged lines hidden (view full) ---

27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
3 * Copyright (c) 1992 Diomidis Spinellis.
4 * Copyright (c) 1992, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * This code is derived from software contributed to Berkeley by
8 * Diomidis Spinellis of Imperial College, University of London.
9 *
10 * Redistribution and use in source and binary forms, with or without

--- 17 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 */
34
35#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/usr.bin/sed/main.c 217133 2011-01-08 00:03:18Z jilles $");
36__FBSDID("$FreeBSD: head/usr.bin/sed/main.c 252231 2013-06-26 04:14:19Z pfg $");
36
37#ifndef lint
38static const char copyright[] =
39"@(#) Copyright (c) 1992, 1993\n\
40 The Regents of the University of California. All rights reserved.\n";
41#endif
42
43#ifndef lint

--- 8 unchanged lines hidden (view full) ---

52#include <err.h>
53#include <errno.h>
54#include <fcntl.h>
55#include <libgen.h>
56#include <limits.h>
57#include <locale.h>
58#include <regex.h>
59#include <stddef.h>
37
38#ifndef lint
39static const char copyright[] =
40"@(#) Copyright (c) 1992, 1993\n\
41 The Regents of the University of California. All rights reserved.\n";
42#endif
43
44#ifndef lint

--- 8 unchanged lines hidden (view full) ---

53#include <err.h>
54#include <errno.h>
55#include <fcntl.h>
56#include <libgen.h>
57#include <limits.h>
58#include <locale.h>
59#include <regex.h>
60#include <stddef.h>
61#define _WITH_GETLINE
60#include <stdio.h>
61#include <stdlib.h>
62#include <string.h>
63#include <unistd.h>
64
65#include "defs.h"
66#include "extern.h"
67

--- 234 unchanged lines hidden (view full) ---

302/*
303 * Like fgets, but go through the list of files chaining them together.
304 * Set len to the length of the line.
305 */
306int
307mf_fgets(SPACE *sp, enum e_spflag spflag)
308{
309 struct stat sb;
62#include <stdio.h>
63#include <stdlib.h>
64#include <string.h>
65#include <unistd.h>
66
67#include "defs.h"
68#include "extern.h"
69

--- 234 unchanged lines hidden (view full) ---

304/*
305 * Like fgets, but go through the list of files chaining them together.
306 * Set len to the length of the line.
307 */
308int
309mf_fgets(SPACE *sp, enum e_spflag spflag)
310{
311 struct stat sb;
310 size_t len;
311 char *p;
312 ssize_t len;
313 static char *p = NULL;
314 static size_t plen = 0;
312 int c;
313 static int firstfile;
314
315 if (infile == NULL) {
316 /* stdin? */
317 if (files->fname == NULL) {
318 if (inplace != NULL)
319 errx(1, "-I or -i may not be used with stdin");

--- 99 unchanged lines hidden (view full) ---

419 rval = 1;
420 continue;
421 }
422 }
423 /*
424 * We are here only when infile is open and we still have something
425 * to read from it.
426 *
315 int c;
316 static int firstfile;
317
318 if (infile == NULL) {
319 /* stdin? */
320 if (files->fname == NULL) {
321 if (inplace != NULL)
322 errx(1, "-I or -i may not be used with stdin");

--- 99 unchanged lines hidden (view full) ---

422 rval = 1;
423 continue;
424 }
425 }
426 /*
427 * We are here only when infile is open and we still have something
428 * to read from it.
429 *
427 * Use fgetln so that we can handle essentially infinite input data.
428 * Can't use the pointer into the stdio buffer as the process space
429 * because the ungetc() can cause it to move.
430 * Use getline() so that we can handle essentially infinite input
431 * data. The p and plen are static so each invocation gives
432 * getline() the same buffer which is expanded as needed.
430 */
433 */
431 p = fgetln(infile, &len);
432 if (ferror(infile))
433 errx(1, "%s: %s", fname, strerror(errno ? errno : EIO));
434 len = getline(&p, &plen, infile);
435 if (len == -1)
436 err(1, "%s", fname);
434 if (len != 0 && p[len - 1] == '\n')
435 len--;
436 cspace(sp, p, len, spflag);
437
438 linenum++;
439
440 return (1);
441}

--- 46 unchanged lines hidden ---
437 if (len != 0 && p[len - 1] == '\n')
438 len--;
439 cspace(sp, p, len, spflag);
440
441 linenum++;
442
443 return (1);
444}

--- 46 unchanged lines hidden ---