// io.c — persistencia: escribir un archivo y forzarlo al disco.
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

int main(void) {
    int fd = open("hola.txt", O_WRONLY | O_CREAT | O_TRUNC, 0644);
    if (fd < 0) {
        perror("open");
        return 1;
    }
    const char *msg = "hola, disco\n";
    if (write(fd, msg, strlen(msg)) != (ssize_t)strlen(msg)) {
        perror("write");
        return 1;
    }
    fsync(fd);   // sin esto, los datos podrían quedar solo en la caché del kernel
    close(fd);
    printf("listo: hola.txt\n");
    return 0;
}
