aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2014-07-14 16:37:17 -0400
committerFranklin Wei <frankhwei536@gmail.com>2014-07-14 16:37:17 -0400
commit573db59c564e28da0f21c4e9f43b5aaa86fb337e (patch)
treee42f723e93ebd44cdccb4d242ed9bad69061bef4 /util.c
parent79bd2194539aa559078de9afb1500a2e754ee501 (diff)
downloadwargames-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.c24
1 files changed, 11 insertions, 13 deletions
diff --git a/util.c b/util.c
index ea3ab01..b44d0f2 100644
--- a/util.c
+++ b/util.c
@@ -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;
}