Galactic Bloodshed
fileutils.cc
Go to the documentation of this file.
1 // Copyright 2014 The Galactic Bloodshed Authors. All rights reserved.
2 // Use of this source code is governed by a license that can be
3 // found in the COPYING file.
4 
5 #include "gb/utils/fileutils.h"
6 
7 // TODO - Actually move implementation to c++ instead of fopens
8 void InitFile(const std::string &path, void *buffer, size_t len) {
9  const char *filename = path.c_str();
10  FILE *f = fopen(filename, "w+");
11  if (buffer != nullptr && len > 0) {
12  if (f == nullptr) {
13  printf("Unable to open \"%s\".\n", filename);
14  exit(-1);
15  }
16  fwrite(buffer, len, 1, f);
17  }
18  chmod(filename, 00660);
19  fclose(f);
20 }
21 
22 void EmptyFile(const std::string &path) { InitFile(path); }
void InitFile(const std::string &path, void *buffer=nullptr, size_t length=0)
Definition: fileutils.cc:8
void EmptyFile(const std::string &path)
Definition: fileutils.cc:22