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