mirror of
https://github.com/dhewm/dhewm3.git
synced 2025-01-18 23:42:26 +00:00
Fix -Wunused-result warnings
ignoring return value of Implement some error checking. Use [put|get]char in the posix tty code for ease of use.
This commit is contained in:
parent
09f3aa0568
commit
2556a3923f
3 changed files with 46 additions and 45 deletions
|
@ -1102,7 +1102,8 @@ static int unzlocal_getShort (FILE* fin, uLong *pX)
|
|||
{
|
||||
short v;
|
||||
|
||||
fread( &v, sizeof(v), 1, fin );
|
||||
if (fread( &v, sizeof(v), 1, fin ) != 1)
|
||||
return UNZ_ERRNO;
|
||||
|
||||
*pX = LittleShort( v);
|
||||
return UNZ_OK;
|
||||
|
@ -1131,7 +1132,8 @@ static int unzlocal_getLong (FILE *fin, uLong *pX)
|
|||
{
|
||||
int v;
|
||||
|
||||
fread( &v, sizeof(v), 1, fin );
|
||||
if (fread( &v, sizeof(v), 1, fin ) != 1)
|
||||
return UNZ_ERRNO;
|
||||
|
||||
*pX = LittleLong( v);
|
||||
return UNZ_OK;
|
||||
|
|
|
@ -383,12 +383,13 @@ void Sys_DoStartProcess( const char *exeName, bool dofork ) {
|
|||
if ( dofork ) {
|
||||
switch ( fork() ) {
|
||||
case -1:
|
||||
// main thread
|
||||
printf( "fork failed: %s\n", strerror( errno ) );
|
||||
break;
|
||||
case 0:
|
||||
if ( use_system ) {
|
||||
printf( "system %s\n", exeName );
|
||||
system( exeName );
|
||||
if (system( exeName ) == -1)
|
||||
printf( "system failed: %s\n", strerror( errno ) );
|
||||
_exit( 0 );
|
||||
} else {
|
||||
printf( "execl %s\n", exeName );
|
||||
|
@ -397,12 +398,16 @@ void Sys_DoStartProcess( const char *exeName, bool dofork ) {
|
|||
_exit( -1 );
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
if ( use_system ) {
|
||||
printf( "system %s\n", exeName );
|
||||
system( exeName );
|
||||
sleep( 1 ); // on some systems I've seen that starting the new process and exiting this one should not be too close
|
||||
if (system( exeName ) == -1)
|
||||
printf( "system failed: %s\n", strerror( errno ) );
|
||||
else
|
||||
sleep( 1 ); // on some systems I've seen that starting the new process and exiting this one should not be too close
|
||||
} else {
|
||||
printf( "execl %s\n", exeName );
|
||||
execl( exeName, exeName, NULL );
|
||||
|
|
|
@ -337,8 +337,10 @@ Posix_Cwd
|
|||
const char *Posix_Cwd( void ) {
|
||||
static char cwd[MAX_OSPATH];
|
||||
|
||||
getcwd( cwd, sizeof( cwd ) - 1 );
|
||||
cwd[MAX_OSPATH-1] = 0;
|
||||
if (getcwd( cwd, sizeof( cwd ) - 1 ))
|
||||
cwd[MAX_OSPATH-1] = 0;
|
||||
else
|
||||
cwd[0] = 0;
|
||||
|
||||
return cwd;
|
||||
}
|
||||
|
@ -633,24 +635,19 @@ terminal support utilities
|
|||
*/
|
||||
|
||||
void tty_Del() {
|
||||
char key;
|
||||
key = '\b';
|
||||
write( STDOUT_FILENO, &key, 1 );
|
||||
key = ' ';
|
||||
write( STDOUT_FILENO, &key, 1 );
|
||||
key = '\b';
|
||||
write( STDOUT_FILENO, &key, 1 );
|
||||
putchar('\b');
|
||||
putchar(' ');
|
||||
putchar('\b');
|
||||
}
|
||||
|
||||
void tty_Left() {
|
||||
char key = '\b';
|
||||
write( STDOUT_FILENO, &key, 1 );
|
||||
putchar('\b');
|
||||
}
|
||||
|
||||
void tty_Right() {
|
||||
char key = 27;
|
||||
write( STDOUT_FILENO, &key, 1 );
|
||||
write( STDOUT_FILENO, "[C", 2 );
|
||||
putchar(27);
|
||||
putchar('[');
|
||||
putchar('C');
|
||||
}
|
||||
|
||||
// clear the display of the line currently edited
|
||||
|
@ -688,20 +685,25 @@ void tty_Show() {
|
|||
input_hide--;
|
||||
if ( input_hide == 0 ) {
|
||||
char *buf = input_field.GetBuffer();
|
||||
if ( buf[0] ) {
|
||||
write( STDOUT_FILENO, buf, strlen( buf ) );
|
||||
int back = strlen( buf ) - input_field.GetCursor();
|
||||
while ( back > 0 ) {
|
||||
tty_Left();
|
||||
back--;
|
||||
}
|
||||
size_t len = strlen(buf);
|
||||
if ( len < 1 )
|
||||
return;
|
||||
|
||||
len = write( STDOUT_FILENO, buf, len );
|
||||
if ( len < 1 )
|
||||
return;
|
||||
|
||||
len -= input_field.GetCursor();
|
||||
while ( len > 0 ) {
|
||||
tty_Left();
|
||||
len--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tty_FlushIn() {
|
||||
char key;
|
||||
while ( read(0, &key, 1) != -1 ) {
|
||||
while ( ( key = getchar() ) != EOF ) {
|
||||
Sys_Printf( "'%d' ", key );
|
||||
}
|
||||
Sys_Printf( "\n" );
|
||||
|
@ -716,10 +718,9 @@ Return NULL if a complete line is not ready.
|
|||
*/
|
||||
char *Posix_ConsoleInput( void ) {
|
||||
if ( tty_enabled ) {
|
||||
int ret;
|
||||
char key;
|
||||
bool hidden = false;
|
||||
while ( ( ret = read( STDIN_FILENO, &key, 1 ) ) > 0 ) {
|
||||
while ( ( key = getchar() ) != EOF ) {
|
||||
if ( !hidden ) {
|
||||
tty_Hide();
|
||||
hidden = true;
|
||||
|
@ -739,7 +740,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
idStr::Copynz( input_ret, input_field.GetBuffer(), sizeof( input_ret ) );
|
||||
assert( hidden );
|
||||
tty_Show();
|
||||
write( STDOUT_FILENO, &key, 1 );
|
||||
putchar(key);
|
||||
input_field.Clear();
|
||||
if ( history_count < COMMAND_HISTORY ) {
|
||||
history[ history_count ] = input_ret;
|
||||
|
@ -756,8 +757,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
break;
|
||||
case 27: {
|
||||
// enter escape sequence mode
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 ) {
|
||||
if ( ( key = getchar() ) == EOF ) {
|
||||
Sys_Printf( "dropping sequence: '27' " );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
@ -766,8 +766,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
}
|
||||
switch ( key ) {
|
||||
case 79:
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 ) {
|
||||
if ( ( key = getchar() ) == EOF ) {
|
||||
Sys_Printf( "dropping sequence: '27' '79' " );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
@ -792,8 +791,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
}
|
||||
break;
|
||||
case 91: {
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 ) {
|
||||
if ( ( key = getchar() ) == EOF ) {
|
||||
Sys_Printf( "dropping sequence: '27' '91' " );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
@ -802,8 +800,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
}
|
||||
switch ( key ) {
|
||||
case 49: {
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 || key != 126 ) {
|
||||
if ( ( key = getchar() ) == EOF || key != 126 ) {
|
||||
Sys_Printf( "dropping sequence: '27' '91' '49' '%d' ", key );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
@ -815,8 +812,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
break;
|
||||
}
|
||||
case 50: {
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 || key != 126 ) {
|
||||
if ( ( key = getchar() ) == EOF || key != 126 ) {
|
||||
Sys_Printf( "dropping sequence: '27' '91' '50' '%d' ", key );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
@ -828,8 +824,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
break;
|
||||
}
|
||||
case 52: {
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 || key != 126 ) {
|
||||
if ( ( key = getchar() ) == EOF || key != 126 ) {
|
||||
Sys_Printf( "dropping sequence: '27' '91' '52' '%d' ", key );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
@ -841,8 +836,7 @@ char *Posix_ConsoleInput( void ) {
|
|||
break;
|
||||
}
|
||||
case 51: {
|
||||
ret = read( STDIN_FILENO, &key, 1 );
|
||||
if ( ret <= 0 ) {
|
||||
if ( ( key = getchar() ) == EOF ) {
|
||||
Sys_Printf( "dropping sequence: '27' '91' '51' " );
|
||||
tty_FlushIn();
|
||||
assert( hidden );
|
||||
|
|
Loading…
Reference in a new issue