Hi. I'm a newb trying to learn C99. Here's some code that I wrote. My intention is to write a Wikipedia bot that uses libcurl. I wonder if I'm going over the top on error checking, or if I'm within acceptable boundaries.
Code:
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "Internetfunctions.h"
#include "Error.h"
#define StringMax 100
static int shutdownmessage ( void )
{
int nonfatalerror = 0 ; /* = 1 for nonfatal error, -1 for fatal error. */
/* Print shutdown message. */
int printingerror = 0 ;
char* p_Message = "Bot shutting down now.\n" ;
if ( printf ( "%s", p_Message ) != strlen ( p_Message ) )
printingerror = 1 ;
if ( printingerror )
{
ErrorMessage ( "Couldn't print to screen." , __FILE__ , __LINE__ );
nonfatalerror = 1;
}
/* Print shutdown time */
struct tm *local ;
time_t currenttime ;
char Message [ StringMax ] ;
if ( time ( ¤ttime ) != -1 )
{
local = localtime ( ¤ttime ) ;
int x = snprintf ( Message , StringMax , "Bot shutdown at : %s" , asctime ( local ) ) ;
if ( printf ( "%s", Message ) != strlen ( Message ) )
{
ErrorMessage ( "Couldn't print to screen." , __FILE__ , __LINE__ );
nonfatalerror = 1 ;
}
}
else
{
ErrorMessage ( "Current local time is not available." , __FILE__ , __LINE__ );
nonfatalerror = 1 ;
}
return nonfatalerror ;
}
int shutdown ( void )
{
int x = finalizeinternetfunctions () ;
if ( x < 0 ) return x ;
int y = shutdownmessage () ;
if ( y < 0 ) return y ;
if ( x > 0 ) return x ;
else
if ( y > 0 ) return y ;
return 0 ;
}