write a function that will write safely (using ACID principles) to the disk using a write ahead log in C
Implementing a write-ahead log (WAL) in C is a common approach to ensure that database operations adhere to the ACID principles (Atomicity, Consistency, Isolation, Durability). Below is a simplified example of how you might implement such a function. This example assumes a basic understanding of file operations in C and is designed for educational purposes.

In this implementation:
1. We write changes to a log file first (write-ahead logging).
2. After successfully writing to the log, we apply the changes to the main data file.
3. We ensure that the operations are atomic by using temporary files.

### Example Code

```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>

#define LOG_FILE "write_ahead_log.txt"
#define DATA_FILE "data_file.txt"

// Function to append to the log file
int append_to_log(const char *data) {
    FILE *log_file = fopen(LOG_FILE, "a");
    if (!log_file) {
        perror("Failed to open log file");
        return -1;
    }
    fprintf(log_file, "%s\n", data);
    fclose(log_file);
    return 0;
}

// Function to safely write data to the main data file
int write_data_safely(const char *data) {
    // Step 1: Write to the log
    if (append_to_log(data) != 
int write_safely(char *path, int64_t offset, const char *data, int size) {
  int64_t last_written_offset = 0;
  int ret = 0;

  struct fs_file_info fi;
  if (fs_file_info_init(&fi, path, offset) == 0) {
    ret = fs_file_info_write(&fi, data, size);
    last_written_offset = fi.last_written_offset;
  }

  if (ret == 0 && last_written_offset != offset) {
    ret = fs_file_info_fsync(&fi);
  }

  return ret;
}