Diff for /libaitio/example/test_bufio.c between versions 1.1 and 1.2

version 1.1, 2012/02/02 15:32:02 version 1.2, 2012/02/02 21:32:42
Line 0 Line 1
   #include <stdio.h>
   #include <stdlib.h>
   #include <string.h>
   #include <fcntl.h>
   #include <sys/mman.h>
   #include <aitio.h>
   
   
   int
   main(int argc, char **argv)
   {
           FILE *f;
           char b[BUFSIZ];
           void *p = NULL;
   
           f = io_fd2buf(io_dumbFile("xxx", 0644, 12345), "r+");
           fclose(f);
   
           if (argc < 2)
                   f = io_fmapopen(NULL, 0, 0, PROT_READ | PROT_WRITE, 0, 2000);
           else
                   f = io_fmapopen(argv[1], O_RDWR, 0, PROT_READ | PROT_WRITE, MAP_SHARED, 0);
           if (!f) {
                   printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
                   return 1;
           }
   
           fwrite("123456789", 10, 1, f);
           fseek(f, 0, SEEK_SET);
           memset(b, 0, sizeof b);
           fread(b, sizeof b, 1, f);
           printf("b=%s\n", b);
   //      fread(b, sizeof b, 1, f);
           fwrite("***", 4, 1, f);
           fwrite("*|\n", 3, 1, f);
           fseek(f, 100, SEEK_CUR);
           fwrite("oOo", 3, 1, f);
           fseek(f, -10, SEEK_END);
           fwrite("123456789", 10, 1, f);
           fseek(f, -10, SEEK_END);
           memset(b, 0, sizeof b);
           fread(b, sizeof b, 1, f);
           printf("2.b=%s\n", b);
   
           fclose(f);
   
           // part 2
           
           f = io_fmemopen(&p, 100);
           if (!f) {
                   printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
                   return 2;
           }
   
           fwrite("123456789", 10, 1, f);
           fseek(f, 0, SEEK_SET);
           memset(b, 0, sizeof b);
           fread(b, sizeof b, 1, f);
           printf("b=%s\n", b);
   //      fread(b, sizeof b, 1, f);
           fwrite("***", 4, 1, f);
           fwrite("*|\n", 3, 1, f);
           fseek(f, 100, SEEK_CUR);
           fwrite("oOo", 3, 1, f);
           fseek(f, -10, SEEK_END);
           fwrite("123456789", 10, 1, f);
           fseek(f, -10, SEEK_END);
           memset(b, 0, sizeof b);
           fread(b, sizeof b, 1, f);
           printf("2.b=%s\n", b);
   
           fclose(f);
   
           // part 3
   
           p = malloc(10000);
           f = io_fmemopen(&p, 10000);
           if (!f) {
                   printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError());
                   return 3;
           }
   
           fwrite("123456789", 10, 1, f);
           fseek(f, 0, SEEK_SET);
           memset(b, 0, sizeof b);
           fread(b, sizeof b, 1, f);
           printf("b=%s\n", b);
   //      fread(b, sizeof b, 1, f);
           fwrite("***", 4, 1, f);
           fwrite("*|\n", 3, 1, f);
           fseek(f, 100, SEEK_CUR);
           fwrite("oOo", 3, 1, f);
           fseek(f, -10, SEEK_END);
           fwrite("123456789", 10, 1, f);
           fseek(f, -10, SEEK_END);
           memset(b, 0, sizeof b);
           fread(b, sizeof b, 1, f);
           printf("2.b=%s\n", b);
   
           fclose(f);
           free(p);
   
           return 0;
   }

Removed from v.1.1  
changed lines
  Added in v.1.2


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>