Fix console warnings on Linux

develop
lethosor 2014-08-09 18:40:33 -04:00
parent fc24d24ccc
commit e71fc0455c
1 changed files with 12 additions and 8 deletions

@ -62,7 +62,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// George Vulov for MacOSX // George Vulov for MacOSX
#ifndef __LINUX__ #ifndef __LINUX__
#define TEMP_FAILURE_RETRY(expr) \ #define TMP_FAILURE_RETRY(expr) \
({ long int _res; \ ({ long int _res; \
do _res = (long int) (expr); \ do _res = (long int) (expr); \
while (_res == -1L && errno == EINTR); \ while (_res == -1L && errno == EINTR); \
@ -155,7 +155,7 @@ namespace DFHack
FD_ZERO(&descriptor_set); FD_ZERO(&descriptor_set);
FD_SET(STDIN_FILENO, &descriptor_set); FD_SET(STDIN_FILENO, &descriptor_set);
FD_SET(exit_pipe[0], &descriptor_set); FD_SET(exit_pipe[0], &descriptor_set);
int ret = TEMP_FAILURE_RETRY( int ret = TMP_FAILURE_RETRY(
select (FD_SETSIZE,&descriptor_set, NULL, NULL, NULL) select (FD_SETSIZE,&descriptor_set, NULL, NULL, NULL)
); );
if(ret == -1) if(ret == -1)
@ -165,7 +165,7 @@ namespace DFHack
if (FD_ISSET(STDIN_FILENO, &descriptor_set)) if (FD_ISSET(STDIN_FILENO, &descriptor_set))
{ {
// read byte from stdin // read byte from stdin
ret = TEMP_FAILURE_RETRY( ret = TMP_FAILURE_RETRY(
read(STDIN_FILENO, &out, 1) read(STDIN_FILENO, &out, 1)
); );
if(ret == -1) if(ret == -1)
@ -245,7 +245,8 @@ namespace DFHack
if(rawmode) if(rawmode)
{ {
const char * clr = "\033c\033[3J\033[H"; const char * clr = "\033c\033[3J\033[H";
::write(STDIN_FILENO,clr,strlen(clr)); if (::write(STDIN_FILENO,clr,strlen(clr)) == -1)
;
} }
else else
{ {
@ -264,12 +265,13 @@ namespace DFHack
void color(Console::color_value index) void color(Console::color_value index)
{ {
if(!rawmode) if(!rawmode)
fprintf(dfout_C,getANSIColor(index)); fprintf(dfout_C, "%s", getANSIColor(index));
else else
{ {
const char * colstr = getANSIColor(index); const char * colstr = getANSIColor(index);
int lstr = strlen(colstr); int lstr = strlen(colstr);
::write(STDIN_FILENO,colstr,lstr); if (::write(STDIN_FILENO,colstr,lstr) == -1)
;
} }
} }
/// Reset color to default /// Reset color to default
@ -715,7 +717,8 @@ bool Console::init(bool sharing)
inited = false; inited = false;
return false; return false;
} }
freopen("stdout.log", "w", stdout); if (!freopen("stdout.log", "w", stdout))
;
d = new Private(); d = new Private();
// make our own weird streams so our IO isn't redirected // make our own weird streams so our IO isn't redirected
d->dfout_C = fopen("/dev/tty", "w"); d->dfout_C = fopen("/dev/tty", "w");
@ -723,7 +726,8 @@ bool Console::init(bool sharing)
clear(); clear();
d->supported_terminal = !isUnsupportedTerm() && isatty(STDIN_FILENO); d->supported_terminal = !isUnsupportedTerm() && isatty(STDIN_FILENO);
// init the exit mechanism // init the exit mechanism
pipe(d->exit_pipe); if (pipe(d->exit_pipe) == -1)
;
FD_ZERO(&d->descriptor_set); FD_ZERO(&d->descriptor_set);
FD_SET(STDIN_FILENO, &d->descriptor_set); FD_SET(STDIN_FILENO, &d->descriptor_set);
FD_SET(d->exit_pipe[0], &d->descriptor_set); FD_SET(d->exit_pipe[0], &d->descriptor_set);