File: fileutils.cpp

package info (click to toggle)
gengetopt 2.22.6%2Bdfsg0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,732 kB
  • sloc: cpp: 14,709; sh: 11,845; ansic: 8,030; makefile: 689; yacc: 514; lex: 171; sed: 3
file content (56 lines) | stat: -rw-r--r-- 973 bytes parent folder | download | duplicates (3)
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;
}