Ciao,
read e write in C serializzano bene.
Ad esempio penserei ad una cosa del tipo
codice:
#include <stdio.h>
#include <io.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#define SERIALIZE_OR_DIE(fd, x) ( write(fd, &x, sizeof(x)) \
== sizeof(x) || close(fd) && exit(1))
#define UNSERIALIZE_OR_DIE(fd, x) (read(fd, &x, sizeof(x)) \
== sizeof(x) || close(fd) && exit(1))
typedef struct _Type{
char a[100];
int b;
} Type;
int main()
{
int fd;
Type t, u;
int n, o;
strcpy(t.a, "test");
t.b = 2;
n = 3;
fd = open("data", O_BINARY | O_TRUNC | O_CREAT | O_RDWR ,
S_IREAD | S_IWRITE );
fd == -1 && exit(1);
SERIALIZE_OR_DIE (fd, t);
SERIALIZE_OR_DIE (fd, n);
lseek(fd, 0L, SEEK_SET) == 0 || exit(1);
UNSERIALIZE_OR_DIE (fd, u);
UNSERIALIZE_OR_DIE (fd, o);
close(fd);
printf("%s %d %d\n", u.a, u.b, o);
}