Esempio n. 1
0
boolByte copyFileToDirectory(const CharString fileAbsolutePath, const CharString directoryAbsolutePath) {
  boolByte result = false;
  CharString fileOutPath = newCharStringWithCapacity(kCharStringLengthLong);
  CharString fileBasename = NULL;
  FILE *input = NULL;
  FILE *output = NULL;
  char ch;

  fileBasename = newCharStringWithCString(getFileBasename(fileAbsolutePath->data));
  buildAbsolutePath(directoryAbsolutePath, fileBasename, NULL, fileOutPath);
  input = fopen(fileAbsolutePath->data, "rb");
  if(input != NULL) {
    output = fopen(fileOutPath->data, "wb");
    if(output != NULL) {
      while(fread(&ch, 1, 1, input) == 1) {
        fwrite(&ch, 1, 1, output);
      }
      result = true;
    }
  }

  if(input != NULL) {
    fclose(input);
  }
  if(output != NULL) {
    fclose(output);
  }
  freeCharString(fileOutPath);
  freeCharString(fileBasename);
  return result;
}
Esempio n. 2
0
void errorReporterRemapPath(ErrorReporter self, CharString path) {
  CharString basename = newCharString();
  CharString outString = newCharStringWithCapacity(path->capacity);

  charStringCopyCString(basename, getFileBasename(path->data));
  buildAbsolutePath(self->reportDirPath, basename, NULL, outString);
  charStringCopy(path, outString);

  freeCharString(basename);
  freeCharString(outString);
}
Esempio n. 3
0
static int _testGetNullFileBasename(void) {
  assertIsNull(getFileBasename(NULL));
  return 0;
}
Esempio n. 4
0
static int _testGetFileBasename(void) {
  CharString c = newCharStringWithCString(getFileBasename(ABSOLUTE_TEST_FILENAME));
  assertCharStringEquals(c, TEST_FILENAME);
  freeCharString(c);
  return 0;
}