Minimal update to make it easier to increase the buffer-size lpd uses

when reading/writing spool files.  I intend to do a more elaborate
version, but I want to get this much in before 4.9-release.  As written,
this results in no change to the object code.

Submitted by:	John-Mark Gurney
Reviewed by:	/sbin/md5
MFC after:	4 days
This commit is contained in:
Garance A Drosehn 2003-08-21 03:43:48 +00:00
parent 08d63b4c8f
commit 0de95e161e
2 changed files with 20 additions and 10 deletions

View File

@ -80,6 +80,11 @@ __FBSDID("$FreeBSD$");
#define DORETURN 0 /* dofork should return "can't fork" error */
#define DOABORT 1 /* dofork should just die if fork() fails */
/*
* The buffer size to use when reading/writing spool files.
*/
#define SPL_BUFSIZ BUFSIZ
/*
* Error tokens
*/
@ -607,7 +612,7 @@ print(struct printer *pp, int format, char *file)
register char *prog;
int fi, fo;
FILE *fp;
char *av[15], buf[BUFSIZ];
char *av[15], buf[SPL_BUFSIZ];
pid_t wpid;
int p[2], retcode, stopped, wstatus, wstatus_set;
struct stat stb;
@ -637,7 +642,7 @@ print(struct printer *pp, int format, char *file)
if (pp->filters[LPF_INPUT] == NULL
&& (format == 'f' || format == 'l' || format == 'o')) {
pp->tof = 0;
while ((n = read(fi, buf, BUFSIZ)) > 0)
while ((n = read(fi, buf, SPL_BUFSIZ)) > 0)
if (write(ofd, buf, n) != n) {
(void) close(fi);
return (REPRINT);
@ -880,7 +885,7 @@ static int
sendit(struct printer *pp, char *file)
{
int dfcopies, err, i;
char *cp, last[BUFSIZ];
char *cp, last[sizeof(line)];
/*
* open control file
@ -989,7 +994,7 @@ sendfile(struct printer *pp, int type, char *file, char format, int copyreq)
int i, amt;
struct stat stb;
char *av[15], *filtcmd;
char buf[BUFSIZ], opt_c[4], opt_h[4], opt_n[4];
char buf[SPL_BUFSIZ], opt_c[4], opt_h[4], opt_n[4];
int copycnt, filtstat, narg, resp, sfd, sfres, sizerr, statrc;
statrc = lstat(file, &stb);
@ -1150,8 +1155,8 @@ sendfile(struct printer *pp, int type, char *file, char format, int copyreq)
*/
if (type == '\3')
trstat_init(pp, file, job_dfcnt);
for (i = 0; i < stb.st_size; i += BUFSIZ) {
amt = BUFSIZ;
for (i = 0; i < stb.st_size; i += SPL_BUFSIZ) {
amt = SPL_BUFSIZ;
if (i + amt > stb.st_size)
amt = stb.st_size - i;
if (sizerr == 0 && read(sfd, buf, amt) != amt)

View File

@ -72,6 +72,11 @@ __FBSDID("$FreeBSD$");
#define ack() (void) write(STDOUT_FILENO, sp, (size_t)1);
/*
* The buffer size to use when reading/writing spool files.
*/
#define SPL_BUFSIZ BUFSIZ
static char dfname[NAME_MAX]; /* data files */
static int minfree; /* keep at least minfree blocks available */
static const char *sp = "";
@ -255,7 +260,7 @@ static int
readfile(struct printer *pp, char *file, size_t size)
{
register char *cp;
char buf[BUFSIZ];
char buf[SPL_BUFSIZ];
size_t amt, i;
int err, fd, j;
@ -267,8 +272,8 @@ readfile(struct printer *pp, char *file, size_t size)
}
ack();
err = 0;
for (i = 0; i < size; i += BUFSIZ) {
amt = BUFSIZ;
for (i = 0; i < size; i += SPL_BUFSIZ) {
amt = SPL_BUFSIZ;
cp = buf;
if (i + amt > size)
amt = size - i;
@ -281,7 +286,7 @@ readfile(struct printer *pp, char *file, size_t size)
amt -= j;
cp += j;
} while (amt > 0);
amt = BUFSIZ;
amt = SPL_BUFSIZ;
if (i + amt > size)
amt = size - i;
if (write(fd, buf, amt) != (ssize_t)amt) {