aboutsummaryrefslogtreecommitdiff
path: root/shell/msh.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-02-20 22:23:24 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-02-20 22:23:24 +0000
commite376d454bb70ed41bbc3eb0358d37fa30c94358d (patch)
treeeb53c600dcde841a7617a19f819ae3e9cfe7fd84 /shell/msh.c
parentae86a338b89c1339588226cb2298e1785aaa7b90 (diff)
downloadbusybox-w32-e376d454bb70ed41bbc3eb0358d37fa30c94358d.tar.gz
busybox-w32-e376d454bb70ed41bbc3eb0358d37fa30c94358d.tar.bz2
busybox-w32-e376d454bb70ed41bbc3eb0358d37fa30c94358d.zip
libbb: introduce and use nonblock_safe_read(). Yay!
Our shells are immune from this nasty O_NONBLOCK now! function old new delta nonblock_safe_read - 78 +78 file_get 276 295 +19 generateMTFValues 428 435 +7 read_line_input 1776 1772 -4 preadbuffer 543 450 -93 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 2/2 up/down: 104/-97) Total: 7 bytes text data bss dec hex filename 615190 715 23924 639829 9c355 busybox_old 615168 715 23924 639807 9c33f busybox_unstripped
Diffstat (limited to 'shell/msh.c')
-rw-r--r--shell/msh.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/shell/msh.c b/shell/msh.c
index fd287f16e..917b08a1e 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -42,6 +42,7 @@
42# define xmalloc(size) malloc(size) 42# define xmalloc(size) malloc(size)
43# define msh_main(argc,argv) main(argc,argv) 43# define msh_main(argc,argv) main(argc,argv)
44# define safe_read(fd,buf,count) read(fd,buf,count) 44# define safe_read(fd,buf,count) read(fd,buf,count)
45# define nonblock_safe_read(fd,buf,count) read(fd,buf,count)
45# define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1]) 46# define NOT_LONE_DASH(s) ((s)[0] != '-' || (s)[1])
46# define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1]) 47# define LONE_CHAR(s,c) ((s)[0] == (c) && !(s)[1])
47# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) 48# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
@@ -3376,7 +3377,7 @@ static int doread(struct op *t)
3376 } 3377 }
3377 for (wp = t->words + 1; *wp; wp++) { 3378 for (wp = t->words + 1; *wp; wp++) {
3378 for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) { 3379 for (cp = global_env.linep; !nl && cp < elinep - 1; cp++) {
3379 nb = read(0, cp, sizeof(*cp)); 3380 nb = nonblock_safe_read(0, cp, sizeof(*cp));
3380 if (nb != sizeof(*cp)) 3381 if (nb != sizeof(*cp))
3381 break; 3382 break;
3382 nl = (*cp == '\n'); 3383 nl = (*cp == '\n');
@@ -4799,7 +4800,7 @@ static int filechar(struct ioarg *ap)
4799 if (i) 4800 if (i)
4800 lseek(ap->afile, ap->afpos, SEEK_SET); 4801 lseek(ap->afile, ap->afpos, SEEK_SET);
4801 4802
4802 i = safe_read(ap->afile, bp->buf, sizeof(bp->buf)); 4803 i = nonblock_safe_read(ap->afile, bp->buf, sizeof(bp->buf));
4803 if (i <= 0) { 4804 if (i <= 0) {
4804 closef(ap->afile); 4805 closef(ap->afile);
4805 return 0; 4806 return 0;
@@ -4830,7 +4831,7 @@ static int filechar(struct ioarg *ap)
4830 return c; 4831 return c;
4831 } 4832 }
4832#endif 4833#endif
4833 i = safe_read(ap->afile, &c, sizeof(c)); 4834 i = nonblock_safe_read(ap->afile, &c, sizeof(c));
4834 return i == sizeof(c) ? (c & 0x7f) : (closef(ap->afile), 0); 4835 return i == sizeof(c) ? (c & 0x7f) : (closef(ap->afile), 0);
4835} 4836}
4836 4837
@@ -4841,7 +4842,7 @@ static int herechar(struct ioarg *ap)
4841{ 4842{
4842 char c; 4843 char c;
4843 4844
4844 if (read(ap->afile, &c, sizeof(c)) != sizeof(c)) { 4845 if (nonblock_safe_read(ap->afile, &c, sizeof(c)) != sizeof(c)) {
4845 close(ap->afile); 4846 close(ap->afile);
4846 c = '\0'; 4847 c = '\0';
4847 } 4848 }