version 1.19, 2009/10/27 23:59:44 |
version 1.20, 2015/07/22 16:37:04 |
|
|
return (0); |
return (0); |
} |
} |
|
|
typedef struct bf { |
#define BSZ (128 * 1024) |
|
struct bf { |
struct bf *next; |
struct bf *next; |
struct bf *prev; |
struct bf *prev; |
size_t len; |
size_t len; |
char *l; |
char l[BSZ]; |
} BF; |
}; |
|
|
/* |
/* |
* r_buf -- display a non-regular file in reverse order by line. |
* r_buf -- display a non-regular file in reverse order by line. |
|
|
static void |
static void |
r_buf(FILE *fp) |
r_buf(FILE *fp) |
{ |
{ |
BF *mark, *tr, *tl = NULL; |
struct bf *mark, *tr, *tl = NULL; |
int ch; |
int ch; |
size_t len, llen; |
size_t len, llen; |
char *p; |
char *p; |
off_t enomem; |
off_t enomem; |
|
|
#define BSZ (128 * 1024) |
|
for (mark = NULL, enomem = 0;;) { |
for (mark = NULL, enomem = 0;;) { |
/* |
/* |
* Allocate a new block and link it into place in a doubly |
* Allocate a new block and link it into place in a doubly |
* linked list. If out of memory, toss the LRU block and |
* linked list. If out of memory, toss the LRU block and |
* keep going. |
* keep going. |
*/ |
*/ |
if (enomem || (tl = malloc(sizeof(BF))) == NULL || |
if (enomem || (tl = malloc(sizeof(*tl))) == NULL) { |
(tl->l = malloc(BSZ)) == NULL) { |
|
if (!mark) |
if (!mark) |
err(1, NULL); |
err(1, NULL); |
tl = enomem ? tl->next : mark; |
tl = enomem ? tl->next : mark; |
|
|
while ((tl = tl->next)->len) { |
while ((tl = tl->next)->len) { |
WR(tl->l, tl->len); |
WR(tl->l, tl->len); |
tl->len = 0; |
tl->len = 0; |
|
} |
|
|
|
tl->prev->next = NULL; |
|
while (tl != NULL) { |
|
tr = tl->next; |
|
free(tl); |
|
tl = tr; |
} |
} |
} |
} |