src/server/server.c
static int handle_termination( void ){
	char buffer[ 2 ];
	static const size_t buffersize = sizeof( buffer ) / sizeof( buffer[ 0 ] );
	int toTerminate = 0; // Must be initialized to zero

	printf( "Server it to be terminated. Are you sure? [y/n] " );
	fflush( stdout );

	errno = 0;
	fgets( buffer, buffersize, stdin );
	if ( feof( stdin ) ){
		error( "stdin at EOF.\nExiting now...\n" );
		// Return here cause discardline() will be called later and we are at eof now
		return ( 1 );
	}
	else if ( ferror( stdin ) ){
		error( "Error with stdin (%s).\nExiting now...\n", strerror( errno ) );
		// Return here cause discardline() will be called later and stdin is in error now
		return ( 1 );
	}
	else if ( !strcmp( buffer, "y" ) ){
		// Do not return here to call discardline() later
		toTerminate = 1;
	}
	else if ( !strcmp( buffer, "n" ) ){
		// Do not return here to call discardline() later
		 toTerminate = 0;
	}
	else{
		// Do not return here to call discardline() later
		printf( "Invalid character. Continuing now...\n" );
		fflush( stdout );
		toTerminate = 0;
	}

	discardline( stdin );

	// Do not terminate
	return ( toTerminate );
}
// Ask user if server is to be terminated or not
Ask user if server is to be terminated or not
Ask user if server is to be terminated or not
static int handle_termination( void ){
	char buffer[ 2 ];
	static const size_t buffersize = sizeof( buffer ) / sizeof( buffer[ 0 ] );
	int toTerminate = 0; 
	printf( "Server it to be terminated. Are you sure? [y/n] " );
	fflush( stdout );
	errno = 0;
	fgets( buffer, buffersize, stdin );
	if ( feof( stdin ) ){
		error( "stdin at EOF.\nExiting now...\n" );
		return ( 1 );
	}
	else if ( ferror( stdin ) ){
		error( "Error with stdin (%s).\nExiting now...\n", strerror( errno ) );
		return ( 1 );
	}
	else if ( !strcmp( buffer, "y" ) ){
		toTerminate = 1;
	}
	else if ( !strcmp( buffer, "n" ) ){
		 toTerminate = 0;
	}
	else{
		printf( "Invalid character. Continuing now...\n" );
		fflush( stdout );
		toTerminate = 0;
	}
	discardline( stdin );
	return ( toTerminate );
}
static int handle_termination ( void ) { char buffer [ 2 ] ; static const size_t buffersize = sizeof ( buffer ) / sizeof ( buffer [ 0 ] ) ; int toTerminate = 0 ; printf ( " " ) ; fflush ( stdout ) ; errno = 0 ; fgets ( buffer , buffersize , stdin ) ; if ( feof ( stdin ) ) { error ( " \n \n " ) ; return ( 1 ) ; } else if ( ferror ( stdin ) ) { error ( " \n \n " , strerror ( errno ) ) ; return ( 1 ) ; } else if ( ! strcmp ( buffer , " " ) ) { toTerminate = 1 ; } else if ( ! strcmp ( buffer , " " ) ) { toTerminate = 0 ; } else { printf ( " \n " ) ; fflush ( stdout ) ; toTerminate = 0 ; } discardline ( stdin ) ; return ( toTerminate ) ; }
Ask user if server is to be terminated or not
Ask user if server is to be terminated or not
// Must be initialized to zero // Return here cause discardline() will be called later and we are at eof now // Return here cause discardline() will be called later and stdin is in error now // Do not return here to call discardline() later // Do not return here to call discardline() later // Do not return here to call discardline() later // Do not terminate