summaryrefslogtreecommitdiff
path: root/src/xd.c
blob: 5e9644e70891516ad1d925422705ddf3ca4dd831 (plain)
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
#include "xd.h"

#include <raylib.h>
#include <stdio.h>
#include <stdlib.h>

XdData *Xd_LoadFromFile(const char *filePath) {
  FILE *file = fopen(filePath, "rb");

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

  XdData *data = malloc(sizeof(XdData));
  fread(data, sizeof(XdData), 1, file);

  fclose(file);
  return data;
}

void Xd_SaveFile(const char *filePath, XdData *data) {
  if (data == NULL) {
    printf("data is null\n");
    return;
  }

  FILE *file = fopen(filePath, "wb");

  if (file == NULL) {
    perror("Failed to open a file");
    return;
  }

  fwrite(data, sizeof(XdData), 1, file);

  fclose(file);
  printf("saved\n");
}