
Add a more-or-less complete example of how to use the library.



---

 cur-root/samples/build  |    1 
 cur-root/samples/clean  |    2 -
 cur-root/samples/full.c |   55 ++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+), 1 deletion(-)

diff -puN /dev/null samples/full.c
--- /dev/null	2004-04-13 23:59:22.000000000 -0300
+++ cur-root/samples/full.c	2004-06-19 23:57:39.906197328 -0300
@@ -0,0 +1,55 @@
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <string.h>
+#include <libjio.h>
+
+#define FILENAME "test1"
+#define TEXT "Hello world!"
+
+int main(void)
+{
+	int r;
+	struct jfs file;
+	struct jtrans trans;
+	struct jfsck_result result;
+
+	/* check the file is OK */
+	jfsck(FILENAME, &result);
+	jfsck_cleanup(FILENAME);
+
+	/* and open it */
+	r = jopen(&file, FILENAME, O_SYNC | O_CREAT | O_TRUNC, 0600, 0);
+	if (r < 0) {
+		perror("jopen");
+		return 1;
+	}
+
+	/* write two "Hello world"s next to each other */
+	jtrans_init(&file, &trans);
+	jtrans_add(&trans, TEXT, strlen(TEXT), 0);
+	jtrans_add(&trans, TEXT, strlen(TEXT), strlen(TEXT) - 1);
+	r = jtrans_commit(&trans);
+	if (r < 0) {
+		perror("jtrans_commit");
+		return 1;
+	}
+
+	/* at this point the file has "Hello world!Hello world!" */
+
+	/* now we rollback */
+	r = jtrans_rollback(&trans);
+	if (r < 0) {
+		perror("jtrans_rollback");
+		return 1;
+	}
+
+	/* and now the file is empty! */
+
+	jtrans_free(&trans);
+	jclose(&file);
+	return 0;
+}
+
diff -puN samples/build~full_sample samples/build
--- cur/samples/build~full_sample	2004-06-19 23:57:39.903197784 -0300
+++ cur-root/samples/build	2004-06-19 23:57:39.906197328 -0300
@@ -1,4 +1,5 @@
 gcc -Wall -O6 -ljio -lpthread jio1.c -o jio1
 gcc -Wall -O6 -ljio -lpthread jio2.c -o jio2
 gcc -Wall -O6 -ljio -lpthread jio3.c -o jio3
+gcc -Wall -O6 -ljio full.c -o full
 
diff -puN samples/clean~full_sample samples/clean
--- cur/samples/clean~full_sample	2004-06-19 23:57:39.905197480 -0300
+++ cur-root/samples/clean	2004-06-19 23:57:39.906197328 -0300
@@ -1,2 +1,2 @@
-rm -rf jio1 jio2 jio3 test1 .test1.jio
+rm -rf jio1 jio2 jio3 full test1 .test1.jio
 

_
