Esempio n. 1
0
void wbFile_delete(wbFile_t file) {
    if (file != NULL) {
        int idx = wbFile_getIndex(file);
        if (wbFile_getFileName(file) != NULL) {
            wbDelete(wbFile_getFileName(file));
        }
        if (wbFile_getMode(file) != NULL) {
            wbDelete(wbFile_getMode(file));
        }
        if (wbFile_getFileHandle(file) != NULL) {
            fclose(wbFile_getFileHandle(file));
        }
        if (idx >= 0) {
            wbAssert(wbFile_handles[idx] == file);
            wbFile_handles[idx] = NULL;
        }
        if (wbFile_getData(file) != NULL) {
            wbDelete(wbFile_getData(file));
        }
        wbDelete(file);
    }
}
Esempio n. 2
0
void wbFile_write(wbFile_t file, const void *buffer, size_t size,
                  size_t count) {
  size_t res;
  FILE *handle;

  if (file == NULL) {
    return;
  }

  handle = wbFile_getFileHandle(file);

  res = fwrite(buffer, size, count, handle);
  if (res != count) {
    wbLog(ERROR, "Failed to write data to ", wbFile_getFileName(file));
  }

  return;
}
Esempio n. 3
0
char * wbFile_read(wbFile_t file, size_t size, size_t count) {
    size_t res;
    char * buffer;
    FILE * handle;

    if (file == NULL) {
        return NULL;
    }

    handle = wbFile_getFileHandle(file);
    buffer = wbNewArray(char, size*count);

    res = fread(buffer, size, count, handle);
    if (res != count) {
        wbLog(ERROR, "Failed to read data from ", wbFile_getFileName(file));
        wbDelete(buffer);
        return NULL;
    }

    return buffer;
}