diff options
| author | Franklin Wei <frankhwei536@gmail.com> | 2014-07-14 16:37:17 -0400 |
|---|---|---|
| committer | Franklin Wei <frankhwei536@gmail.com> | 2014-07-14 16:37:17 -0400 |
| commit | 573db59c564e28da0f21c4e9f43b5aaa86fb337e (patch) | |
| tree | e42f723e93ebd44cdccb4d242ed9bad69061bef4 /util.c | |
| parent | 79bd2194539aa559078de9afb1500a2e754ee501 (diff) | |
| download | wargames-server-573db59c564e28da0f21c4e9f43b5aaa86fb337e.zip wargames-server-573db59c564e28da0f21c4e9f43b5aaa86fb337e.tar.gz wargames-server-573db59c564e28da0f21c4e9f43b5aaa86fb337e.tar.bz2 wargames-server-573db59c564e28da0f21c4e9f43b5aaa86fb337e.tar.xz | |
Working code ;D
Diffstat (limited to 'util.c')
| -rw-r--r-- | util.c | 24 |
1 files changed, 11 insertions, 13 deletions
@@ -66,18 +66,16 @@ void refresh(void) int getnstr(char* buf, int max) { printf("reading...\n"); - memset(buf, 0, sizeof(buf)); - int back=0; - char c=0; - do { - read(pipes[out_fd][0], &c, 1); - if(c!='\n') - { - - buf[back]=c; - ++back; - } - } - while(back<max && c!='\n'); + memset(buf, 0, max); + int ret=read(pipes[out_fd][0], buf, max); + if(ret!=0) + { + printf("last char is 0x%02x\n", buf[strlen(buf)-1]); + /* remove the newline */ + buf[strlen(buf)-2]='\0'; + } + printf("got string \"%s\"\n", buf); + if(ret<0) + return ERR; return OK; } |