Deleted Added
full compact
read.c (17341) read.c (17825)
1/*-
2 * Copyright (c) 1991, 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 * Edward Sze-Tyan Wang.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

64 off_t off;
65{
66 register int ch, len, tlen;
67 register char *ep, *p, *t;
68 int wrap;
69 char *sp;
70
71 if ((sp = p = malloc(off)) == NULL)
1/*-
2 * Copyright (c) 1991, 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 * Edward Sze-Tyan Wang.
7 *
8 * Redistribution and use in source and binary forms, with or without

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

64 off_t off;
65{
66 register int ch, len, tlen;
67 register char *ep, *p, *t;
68 int wrap;
69 char *sp;
70
71 if ((sp = p = malloc(off)) == NULL)
72 err(1, "%s", strerror(errno));
72 err(1, "malloc");
73
74 for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF;) {
75 *p = ch;
76 if (++p == ep) {
77 wrap = 1;
78 p = sp;
79 }
80 }

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

137 char *l;
138 } *lines;
139 register int ch;
140 register char *p;
141 int blen, cnt, recno, wrap;
142 char *sp;
143
144 if ((lines = malloc(off * sizeof(*lines))) == NULL)
73
74 for (wrap = 0, ep = p + off; (ch = getc(fp)) != EOF;) {
75 *p = ch;
76 if (++p == ep) {
77 wrap = 1;
78 p = sp;
79 }
80 }

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

137 char *l;
138 } *lines;
139 register int ch;
140 register char *p;
141 int blen, cnt, recno, wrap;
142 char *sp;
143
144 if ((lines = malloc(off * sizeof(*lines))) == NULL)
145 err(1, "%s", strerror(errno));
145 err(1, "malloc");
146 bzero(lines, off * sizeof(*lines));
147 sp = NULL;
148 blen = cnt = recno = wrap = 0;
149
150 while ((ch = getc(fp)) != EOF) {
151 if (++cnt > blen) {
152 if ((sp = realloc(sp, blen += 1024)) == NULL)
146 bzero(lines, off * sizeof(*lines));
147 sp = NULL;
148 blen = cnt = recno = wrap = 0;
149
150 while ((ch = getc(fp)) != EOF) {
151 if (++cnt > blen) {
152 if ((sp = realloc(sp, blen += 1024)) == NULL)
153 err(1, "%s", strerror(errno));
153 err(1, "realloc");
154 p = sp + cnt - 1;
155 }
156 *p++ = ch;
157 if (ch == '\n') {
158 if (lines[recno].blen < cnt) {
159 lines[recno].blen = cnt + 256;
160 if ((lines[recno].l = realloc(lines[recno].l,
161 lines[recno].blen)) == NULL)
154 p = sp + cnt - 1;
155 }
156 *p++ = ch;
157 if (ch == '\n') {
158 if (lines[recno].blen < cnt) {
159 lines[recno].blen = cnt + 256;
160 if ((lines[recno].l = realloc(lines[recno].l,
161 lines[recno].blen)) == NULL)
162 err(1, "%s", strerror(errno));
162 err(1, "realloc");
163 }
164 bcopy(sp, lines[recno].l, lines[recno].len = cnt);
165 cnt = 0;
166 p = sp;
167 if (++recno == off) {
168 wrap = 1;
169 recno = 0;
170 }

--- 30 unchanged lines hidden ---
163 }
164 bcopy(sp, lines[recno].l, lines[recno].len = cnt);
165 cnt = 0;
166 p = sp;
167 if (++recno == off) {
168 wrap = 1;
169 recno = 0;
170 }

--- 30 unchanged lines hidden ---