
/*
 *	Function	SaveFailed
 *	Programmer	N.d'Alterio
 *	Date		05/05/96
 *
 *  Synopsis:	Save news article to an archive file when posting has
 *		failed. Each article is separated by a line containing
 *		the date and time of the failure.
 *
 *  Arguments:	failed_file		Filename of failed article
 *		arc_file		Filename of archive
 *
 *  Returns:	None
 *
 *  Variables:	arc_fp			File pointer for archive
 *		msg_fp			File pointer for article
 *		tm			Current time
 * 
 *  Functions:	fopen			Open file (ANSI)
 *		fclose			Close file (ANSI)
 *		fprintf			Print to stream (ANSI)
 *		fgetc			Get char from stream (ANSI)
 *		fputc			Put char on stream (ANSI)
 *		time			Get current time (ANSI)
 *		localtime		Convert time to localtime (ANSI)
 *		asctime			Formatted time string (ANSI)
 *		CopyFile		Copy file to another (NPNS)
 *
 *  $Id: SaveFailed.c 1.1 1996/05/06 22:55:02 nagd Exp $
 *
 */

#include "NPNS.h"

char *sep = "***************************************************";

void SaveFailed( const char *failed_file, const char *arc_file )

{

  FILE *arc_fp;
  FILE *msg_fp;

  time_t tm;

  if ( !( arc_fp = fopen( arc_file, "a" ) ) ) {
	fprintf( stderr, " Could not open failed archive\n" );
  }   /* end if */

  if ( !( msg_fp = fopen( failed_file, "r" ) ) ) {
	fprintf( stderr, " Could not open message file to backup\n" );
	fclose( arc_fp );
	return;
  }   /* end if */

/*
 *   Print a header for failed file containing date.
 */

  tm = time( NULL );

  fprintf( arc_fp, "\n\n %s\n", sep );
  fprintf( arc_fp, "\t%s", asctime( localtime( &tm ) ) );
  fprintf( arc_fp, " %s\n\n", sep );

/*
 *   Now copy msg to archive
 */

 
  CopyFile( msg_fp, arc_fp );

  fclose( arc_fp );
  fclose( msg_fp );
  return;

}   /* end function SaveFailed */

/*========================================================================*
                                 END SaveFailed
 *========================================================================*/
