Deleted Added
full compact
cat.c (139969) cat.c (184471)
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kevin Fall.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

39#endif
40
41#ifndef lint
42#if 0
43static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
44#endif
45#endif /* not lint */
46#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Kevin Fall.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

39#endif
40
41#ifndef lint
42#if 0
43static char sccsid[] = "@(#)cat.c 8.2 (Berkeley) 4/27/95";
44#endif
45#endif /* not lint */
46#include <sys/cdefs.h>
47__FBSDID("$FreeBSD: head/bin/cat/cat.c 139969 2005-01-10 08:39:26Z imp $");
47__FBSDID("$FreeBSD: head/bin/cat/cat.c 184471 2008-10-30 14:05:57Z ivoras $");
48
49#include <sys/param.h>
50#include <sys/stat.h>
51#ifndef NO_UDOM_SUPPORT
52#include <sys/socket.h>
53#include <sys/un.h>
54#include <errno.h>
55#endif

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

72static void scanfiles(char *argv[], int cooked);
73static void cook_cat(FILE *);
74static void raw_cat(int);
75
76#ifndef NO_UDOM_SUPPORT
77static int udom_open(const char *path, int flags);
78#endif
79
48
49#include <sys/param.h>
50#include <sys/stat.h>
51#ifndef NO_UDOM_SUPPORT
52#include <sys/socket.h>
53#include <sys/un.h>
54#include <errno.h>
55#endif

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

72static void scanfiles(char *argv[], int cooked);
73static void cook_cat(FILE *);
74static void raw_cat(int);
75
76#ifndef NO_UDOM_SUPPORT
77static int udom_open(const char *path, int flags);
78#endif
79
80/* Memory strategy threshold, in pages: if physmem is larger then this, use a
81 * large buffer */
82#define PHYSPAGES_THRESHOLD (32*1024)
83
84/* Maximum buffer size in bytes - do not allow it to grow larger than this */
85#define BUFSIZE_MAX (2*1024*1024)
86
87/* Small (default) buffer size in bytes. It's inefficient for this to be
88 * smaller than MAXPHYS */
89#define BUFSIZE_SMALL (MAXPHYS)
90
80int
81main(int argc, char *argv[])
82{
83 int ch;
84
85 setlocale(LC_CTYPE, "");
86
87 while ((ch = getopt(argc, argv, "benstuv")) != -1)

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

242 static size_t bsize;
243 static char *buf = NULL;
244 struct stat sbuf;
245
246 wfd = fileno(stdout);
247 if (buf == NULL) {
248 if (fstat(wfd, &sbuf))
249 err(1, "%s", filename);
91int
92main(int argc, char *argv[])
93{
94 int ch;
95
96 setlocale(LC_CTYPE, "");
97
98 while ((ch = getopt(argc, argv, "benstuv")) != -1)

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

253 static size_t bsize;
254 static char *buf = NULL;
255 struct stat sbuf;
256
257 wfd = fileno(stdout);
258 if (buf == NULL) {
259 if (fstat(wfd, &sbuf))
260 err(1, "%s", filename);
250 bsize = MAX(sbuf.st_blksize, 1024);
261 if (S_ISREG(sbuf.st_mode)) {
262 /* If there's plenty of RAM, use a large copy buffer */
263 if (sysconf(_SC_PHYS_PAGES) > PHYSPAGES_THRESHOLD)
264 bsize = MIN(BUFSIZE_MAX, MAXPHYS*8);
265 else
266 bsize = BUFSIZE_SMALL;
267 } else
268 bsize = MAX(sbuf.st_blksize,
269 (blksize_t)sysconf(_SC_PAGESIZE));
251 if ((buf = malloc(bsize)) == NULL)
270 if ((buf = malloc(bsize)) == NULL)
252 err(1, "buffer");
271 err(1, "malloc() failure of IO buffer");
253 }
254 while ((nr = read(rfd, buf, bsize)) > 0)
255 for (off = 0; nr; nr -= nw, off += nw)
256 if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
257 err(1, "stdout");
258 if (nr < 0) {
259 warn("%s", filename);
260 rval = 1;

--- 54 unchanged lines hidden ---
272 }
273 while ((nr = read(rfd, buf, bsize)) > 0)
274 for (off = 0; nr; nr -= nw, off += nw)
275 if ((nw = write(wfd, buf + off, (size_t)nr)) < 0)
276 err(1, "stdout");
277 if (nr < 0) {
278 warn("%s", filename);
279 rval = 1;

--- 54 unchanged lines hidden ---