improve string pooling: saves 316 bytes in .text
This commit is contained in:
34
shf.c
34
shf.c
@@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.37 2010/08/28 16:47:11 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.38 2010/08/28 18:50:57 tg Exp $");
|
||||
|
||||
/* flags to shf_emptybuf() */
|
||||
#define EB_READSW 0x01 /* about to switch to reading */
|
||||
@@ -108,7 +108,7 @@ shf_fdopen(int fd, int sflags, struct shf *shf)
|
||||
}
|
||||
|
||||
if (!(sflags & (SHF_RD | SHF_WR)))
|
||||
internal_errorf("shf_fdopen: missing read/write");
|
||||
internal_errorf("%s: %s", "shf_fdopen", "missing read/write");
|
||||
|
||||
if (shf) {
|
||||
if (bsize) {
|
||||
@@ -165,9 +165,9 @@ shf_reopen(int fd, int sflags, struct shf *shf)
|
||||
}
|
||||
|
||||
if (!(sflags & (SHF_RD | SHF_WR)))
|
||||
internal_errorf("shf_reopen: missing read/write");
|
||||
internal_errorf("%s: %s", "shf_reopen", "missing read/write");
|
||||
if (!shf || !shf->buf || shf->bsize < bsize)
|
||||
internal_errorf("shf_reopen: bad shf/buf/bsize");
|
||||
internal_errorf("%s: %s", "shf_reopen", "bad shf/buf/bsize");
|
||||
|
||||
/* assumes shf->buf and shf->bsize already set up */
|
||||
shf->fd = fd;
|
||||
@@ -196,7 +196,7 @@ shf_sopen(char *buf, int bsize, int sflags, struct shf *shf)
|
||||
{
|
||||
/* can't have a read+write string */
|
||||
if (!(!(sflags & SHF_RD) ^ !(sflags & SHF_WR)))
|
||||
internal_errorf("shf_sopen: flags 0x%x", sflags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_sopen", sflags);
|
||||
|
||||
if (!shf) {
|
||||
shf = alloc(sizeof(struct shf), ATEMP);
|
||||
@@ -289,7 +289,7 @@ shf_flush(struct shf *shf)
|
||||
return ((shf->flags & SHF_WR) ? EOF : 0);
|
||||
|
||||
if (shf->fd < 0)
|
||||
internal_errorf("shf_flush: no fd");
|
||||
internal_errorf("%s: %s", "shf_flush", "no fd");
|
||||
|
||||
if (shf->flags & SHF_ERROR) {
|
||||
errno = shf->errno_;
|
||||
@@ -319,7 +319,7 @@ shf_emptybuf(struct shf *shf, int flags)
|
||||
int ret = 0;
|
||||
|
||||
if (!(shf->flags & SHF_STRING) && shf->fd < 0)
|
||||
internal_errorf("shf_emptybuf: no fd");
|
||||
internal_errorf("%s: %s", "shf_emptybuf", "no fd");
|
||||
|
||||
if (shf->flags & SHF_ERROR) {
|
||||
errno = shf->errno_;
|
||||
@@ -401,7 +401,7 @@ shf_fillbuf(struct shf *shf)
|
||||
return (0);
|
||||
|
||||
if (shf->fd < 0)
|
||||
internal_errorf("shf_fillbuf: no fd");
|
||||
internal_errorf("%s: %s", "shf_fillbuf", "no fd");
|
||||
|
||||
if (shf->flags & (SHF_EOF | SHF_ERROR)) {
|
||||
if (shf->flags & SHF_ERROR)
|
||||
@@ -444,10 +444,10 @@ shf_read(char *buf, int bsize, struct shf *shf)
|
||||
int ncopy;
|
||||
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("shf_read: flags %x", shf->flags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_read", shf->flags);
|
||||
|
||||
if (bsize <= 0)
|
||||
internal_errorf("shf_read: bsize %d", bsize);
|
||||
internal_errorf("%s: %s %d", "shf_write", "bsize", bsize);
|
||||
|
||||
while (bsize > 0) {
|
||||
if (shf->rnleft == 0 &&
|
||||
@@ -479,7 +479,7 @@ shf_getse(char *buf, int bsize, struct shf *shf)
|
||||
char *orig_buf = buf;
|
||||
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("shf_getse: flags %x", shf->flags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_getse", shf->flags);
|
||||
|
||||
if (bsize <= 0)
|
||||
return (NULL);
|
||||
@@ -514,7 +514,7 @@ int
|
||||
shf_getchar(struct shf *shf)
|
||||
{
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("shf_getchar: flags %x", shf->flags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_getchar", shf->flags);
|
||||
|
||||
if (shf->rnleft == 0 && (shf_fillbuf(shf) == EOF || shf->rnleft == 0))
|
||||
return (EOF);
|
||||
@@ -529,7 +529,7 @@ int
|
||||
shf_ungetc(int c, struct shf *shf)
|
||||
{
|
||||
if (!(shf->flags & SHF_RD))
|
||||
internal_errorf("shf_ungetc: flags %x", shf->flags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_ungetc", shf->flags);
|
||||
|
||||
if ((shf->flags & SHF_ERROR) || c == EOF ||
|
||||
(shf->rp == shf->buf && shf->rnleft))
|
||||
@@ -564,7 +564,7 @@ int
|
||||
shf_putchar(int c, struct shf *shf)
|
||||
{
|
||||
if (!(shf->flags & SHF_WR))
|
||||
internal_errorf("shf_putchar: flags %x", shf->flags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_putchar", shf->flags);
|
||||
|
||||
if (c == EOF)
|
||||
return (EOF);
|
||||
@@ -574,7 +574,7 @@ shf_putchar(int c, struct shf *shf)
|
||||
int n;
|
||||
|
||||
if (shf->fd < 0)
|
||||
internal_errorf("shf_putchar: no fd");
|
||||
internal_errorf("%s: %s", "shf_putchar", "no fd");
|
||||
if (shf->flags & SHF_ERROR) {
|
||||
errno = shf->errno_;
|
||||
return (EOF);
|
||||
@@ -618,10 +618,10 @@ shf_write(const char *buf, int nbytes, struct shf *shf)
|
||||
int n, ncopy, orig_nbytes = nbytes;
|
||||
|
||||
if (!(shf->flags & SHF_WR))
|
||||
internal_errorf("shf_write: flags %x", shf->flags);
|
||||
internal_errorf("%s: flags 0x%X", "shf_write", shf->flags);
|
||||
|
||||
if (nbytes < 0)
|
||||
internal_errorf("shf_write: nbytes %d", nbytes);
|
||||
internal_errorf("%s: %s %d", "shf_write", "nbytes", nbytes);
|
||||
|
||||
/* Don't buffer if buffer is empty and we're writting a large amount. */
|
||||
if ((ncopy = shf->wnleft) &&
|
||||
|
Reference in New Issue
Block a user