Support platforms without clock_gettime()
[libjio.git] / samples / jio3.c
blobc71c7272a911f5e74024bb795dbf76b4043278c8
2 #include <stdio.h>
3 #include <string.h>
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <unistd.h>
9 #include <libjio.h>
12 int main(int argc, char **argv)
14 int rv;
15 jfs_t *fs;
16 jtrans_t *ts;
18 fs = jopen("test3", O_RDWR | O_CREAT, 0660, 0);
19 if (fs == NULL)
20 perror("jopen()");
22 ts = jtrans_new(fs);
23 if (ts == NULL)
24 perror("jtrans_new()");
26 #define str1 "1ROLLBACKTEST1!\n"
27 jtrans_add(ts, str1, strlen(str1), 0);
29 #define str2 "2ROLLBACKTEST2!\n"
30 jtrans_add(ts, str2, strlen(str2), strlen(str1));
32 #define str3 "3ROLLBACKTEST3!\n"
33 jtrans_add(ts, str3, strlen(str3), strlen(str1) + strlen(str2));
35 rv = jtrans_commit(ts);
36 if (rv != strlen(str1) + strlen(str2) + strlen(str3))
37 perror("jtrans_commit()");
38 printf("commit ok: %d\n", rv);
40 rv = jtrans_rollback(ts);
41 if (rv < 0)
42 perror("jtrans_rollback()");
43 printf("rollback ok: %d\n", rv);
45 jtrans_free(ts);
47 if (jclose(fs))
48 perror("jclose()");
50 return 0;