diff options
Diffstat (limited to 'userspace')
| -rw-r--r-- | userspace/cat.c | 14 | ||||
| -rw-r--r-- | userspace/err.c | 9 | ||||
| -rw-r--r-- | userspace/foolshell.c | 21 |
3 files changed, 33 insertions, 11 deletions
diff --git a/userspace/cat.c b/userspace/cat.c index a371397..8980546 100644 --- a/userspace/cat.c +++ b/userspace/cat.c @@ -2,16 +2,14 @@ int main() { - FILE *f = fopen("README", "r"); - if (f == NULL) - { - perror("unable to open file"); - return 1; - } - puts("open success"); - fclose(f); + char buf[256]; + + while(has_data_waiting(2)){ + fread(buf,1,5,stderr); // read stderr; + printf("[%s]\n",buf); + } return 0; } diff --git a/userspace/err.c b/userspace/err.c new file mode 100644 index 0000000..b8dc8ed --- /dev/null +++ b/userspace/err.c @@ -0,0 +1,9 @@ +#include <stdio.h> + +int main() +{ + char buf[]="errrrrrro\n"; + printf("writing some err\n"); + fwrite(buf,1,10,stderr); // write stderr; + return 0; +} diff --git a/userspace/foolshell.c b/userspace/foolshell.c index a502f47..7247871 100644 --- a/userspace/foolshell.c +++ b/userspace/foolshell.c @@ -71,11 +71,27 @@ int main(int argc, char **argv) //char *buf=malloc(256); char *buf=calloc(sizeof(char),256); + printf("setvbuf returned %i\n",setvbuf(stdin,NULL,_IONBF,0)); + while(1) { prompt(); - fgets(buf,255,stdin); - buf[strlen(buf)-1]=0; // remove \n + int bl=0; + + while(1) + { + char c=fgetc(stdin); + putc(c,stdout); + if(c=='\n')break; + + + buf[bl]=c; + buf[bl+1]='\0'; + bl++; + } + + //fgets(buf,255,stdin); + //buf[strlen(buf)-1]=0; // remove \n process(buf); } @@ -125,7 +141,6 @@ char **tokenize(char *buf) int process(char *buf) { - char **token=tokenize(buf); char *command=token[0]; // puts(command); |
