Annotation of libaitio/example/test_bufio.c, revision 1.1.2.1
1.1.2.1 ! misho 1: #include <stdio.h>
! 2: #include <fcntl.h>
! 3: #include <sys/mman.h>
! 4: #include <aitio.h>
! 5:
! 6:
! 7: int
! 8: main(int argc, char **argv)
! 9: {
! 10: FILE *f;
! 11: char b[BUFSIZ];
! 12: void *p = NULL;
! 13:
! 14: if (argc < 2)
! 15: f = io_fmapopen(NULL, 0, 0, PROT_READ | PROT_WRITE, 0, 20000);
! 16: else
! 17: f = io_fmapopen(argv[1], O_RDWR, 0, PROT_READ | PROT_WRITE, MAP_SHARED, 0);
! 18: if (!f) {
! 19: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
! 20: return 1;
! 21: }
! 22:
! 23: fwrite("123456789", 10, 1, f);
! 24: fseek(f, 0, SEEK_SET);
! 25: fread(b, sizeof b, 1, f);
! 26: printf("b=%s\n", b);
! 27: // fread(b, sizeof b, 1, f);
! 28: fwrite("***", 4, 1, f);
! 29: fwrite("*|\n", 3, 1, f);
! 30: fseek(f, 100, SEEK_CUR);
! 31: fwrite("oOo", 3, 1, f);
! 32: fseek(f, -10, SEEK_END);
! 33: fwrite("123456789", 10, 1, f);
! 34: fseek(f, -10, SEEK_END);
! 35: fread(b, sizeof b, 1, f);
! 36: printf("2.b=%s\n", b);
! 37:
! 38: fclose(f);
! 39:
! 40: // part 2
! 41:
! 42: f = io_fmemopen(&p, 10000);
! 43: if (!f) {
! 44: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
! 45: return 2;
! 46: }
! 47:
! 48: fwrite("123456789", 10, 1, f);
! 49: fseek(f, 0, SEEK_SET);
! 50: fread(b, sizeof b, 1, f);
! 51: printf("b=%s\n", b);
! 52: // fread(b, sizeof b, 1, f);
! 53: fwrite("***", 4, 1, f);
! 54: fwrite("*|\n", 3, 1, f);
! 55: fseek(f, 100, SEEK_CUR);
! 56: fwrite("oOo", 3, 1, f);
! 57: fseek(f, -10, SEEK_END);
! 58: fwrite("123456789", 10, 1, f);
! 59: fseek(f, -10, SEEK_END);
! 60: fread(b, sizeof b, 1, f);
! 61: printf("2.b=%s\n", b);
! 62:
! 63: fclose(f);
! 64:
! 65: // part 3
! 66:
! 67: p = malloc(10000);
! 68: f = io_fmemopen(&p, 10000);
! 69: if (!f) {
! 70: printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
! 71: return 3;
! 72: }
! 73:
! 74: fwrite("123456789", 10, 1, f);
! 75: fseek(f, 0, SEEK_SET);
! 76: fread(b, sizeof b, 1, f);
! 77: printf("b=%s\n", b);
! 78: // fread(b, sizeof b, 1, f);
! 79: fwrite("***", 4, 1, f);
! 80: fwrite("*|\n", 3, 1, f);
! 81: fseek(f, 100, SEEK_CUR);
! 82: fwrite("oOo", 3, 1, f);
! 83: fseek(f, -10, SEEK_END);
! 84: fwrite("123456789", 10, 1, f);
! 85: fseek(f, -10, SEEK_END);
! 86: fread(b, sizeof b, 1, f);
! 87: printf("2.b=%s\n", b);
! 88:
! 89: fclose(f);
! 90: free(p);
! 91:
! 92: return 0;
! 93: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>