aboutsummaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorFranklin Wei <frankhwei536@gmail.com>2014-07-14 17:51:16 -0400
committerFranklin Wei <frankhwei536@gmail.com>2014-07-14 17:51:16 -0400
commit7d3df37b572192b6915f5fc3ea9803b195e3a5b3 (patch)
tree0917985c5ee621acf0740d6d32d7f298b3cf7b46 /util.c
parent06e815f51fcd38653a10f391325277d3db178a4b (diff)
downloadwargames-server-7d3df37b572192b6915f5fc3ea9803b195e3a5b3.zip
wargames-server-7d3df37b572192b6915f5fc3ea9803b195e3a5b3.tar.gz
wargames-server-7d3df37b572192b6915f5fc3ea9803b195e3a5b3.tar.bz2
wargames-server-7d3df37b572192b6915f5fc3ea9803b195e3a5b3.tar.xz
Minor fixes
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/util.c b/util.c
index b44d0f2..9539b46 100644
--- a/util.c
+++ b/util.c
@@ -40,6 +40,7 @@ void print_string(const char* str) /* print string, slowly */
{
write(out_fd, &str[i], 1);
fsync(out_fd);
+ usleep(SLEEP_TIME);
++i;
}
}
@@ -58,6 +59,9 @@ void remove_punct(char* buf)
}
void clear(void)
{
+ unsigned char clear_sequence[]={ 0x1B, 'c' };
+ write(out_fd, clear_sequence, sizeof(clear_sequence));
+ fsync(out_fd);
}
void refresh(void)
{
@@ -65,16 +69,15 @@ void refresh(void)
}
int getnstr(char* buf, int max)
{
- printf("reading...\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';
+ /* prevent buffer underflow */
+ if(strlen(buf)-2>=0)
+ /* remove the newline */
+ buf[strlen(buf)-2]='\0';
}
- printf("got string \"%s\"\n", buf);
if(ret<0)
return ERR;
return OK;