1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
|
//
// C++ Implementation: fileutils
//
// Description:
//
//
// Author: Lorenzo Bettini <http://www.lorenzobettini.it>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include "fileutils.h"
using namespace std;
char *
create_filename (char *name, char *ext)
{
char *filename ;
filename = (char *) malloc (strlen (name) + strlen (ext) + 2);
/* 2 = 1 for the . and one for the '\0' */
if (! filename)
{
fprintf (stderr, "Error in memory allocation! %s %d\n",
__FILE__, __LINE__);
abort ();
}
sprintf (filename, "%s.%s", name, ext);
return filename ;
}
ofstream *
open_fstream (const char *filename)
{
ofstream *fstream = new ofstream (filename);
if ( ! (*fstream) )
{
fprintf( stderr, "Error creating %s\n", filename ) ;
abort() ;
}
return fstream;
}
|