version 1.1.2.1, 2012/02/02 15:32:02
|
version 1.2.80.1, 2016/08/15 12:13:47
|
Line 1
|
Line 1
|
#include <stdio.h> |
#include <stdio.h> |
|
#include <stdlib.h> |
|
#include <string.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <sys/mman.h> |
#include <sys/mman.h> |
#include <aitio.h> |
#include <aitio.h> |
Line 11 main(int argc, char **argv)
|
Line 13 main(int argc, char **argv)
|
char b[BUFSIZ]; |
char b[BUFSIZ]; |
void *p = NULL; |
void *p = NULL; |
|
|
|
f = io_fd2buf(io_dumbFile("xxx", 0644, 12345), "r+"); |
|
fclose(f); |
|
|
if (argc < 2) |
if (argc < 2) |
f = io_fmapopen(NULL, 0, 0, PROT_READ | PROT_WRITE, 0, 20000); | f = io_fmapopen(NULL, 0, 0, PROT_READ | PROT_WRITE, 0, 2000); |
else |
else |
f = io_fmapopen(argv[1], O_RDWR, 0, PROT_READ | PROT_WRITE, MAP_SHARED, 0); |
f = io_fmapopen(argv[1], O_RDWR, 0, PROT_READ | PROT_WRITE, MAP_SHARED, 0); |
if (!f) { |
if (!f) { |
Line 22 main(int argc, char **argv)
|
Line 27 main(int argc, char **argv)
|
|
|
fwrite("123456789", 10, 1, f); |
fwrite("123456789", 10, 1, f); |
fseek(f, 0, SEEK_SET); |
fseek(f, 0, SEEK_SET); |
|
memset(b, 0, sizeof b); |
fread(b, sizeof b, 1, f); |
fread(b, sizeof b, 1, f); |
printf("b=%s\n", b); |
printf("b=%s\n", b); |
// fread(b, sizeof b, 1, f); |
// fread(b, sizeof b, 1, f); |
Line 32 main(int argc, char **argv)
|
Line 38 main(int argc, char **argv)
|
fseek(f, -10, SEEK_END); |
fseek(f, -10, SEEK_END); |
fwrite("123456789", 10, 1, f); |
fwrite("123456789", 10, 1, f); |
fseek(f, -10, SEEK_END); |
fseek(f, -10, SEEK_END); |
|
memset(b, 0, sizeof b); |
fread(b, sizeof b, 1, f); |
fread(b, sizeof b, 1, f); |
printf("2.b=%s\n", b); |
printf("2.b=%s\n", b); |
|
|
Line 39 main(int argc, char **argv)
|
Line 46 main(int argc, char **argv)
|
|
|
// part 2 |
// part 2 |
|
|
f = io_fmemopen(&p, 10000); | f = io_fmemopen(&p, 100); |
if (!f) { |
if (!f) { |
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError()); |
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError()); |
return 2; |
return 2; |
Line 47 main(int argc, char **argv)
|
Line 54 main(int argc, char **argv)
|
|
|
fwrite("123456789", 10, 1, f); |
fwrite("123456789", 10, 1, f); |
fseek(f, 0, SEEK_SET); |
fseek(f, 0, SEEK_SET); |
|
memset(b, 0, sizeof b); |
fread(b, sizeof b, 1, f); |
fread(b, sizeof b, 1, f); |
printf("b=%s\n", b); |
printf("b=%s\n", b); |
// fread(b, sizeof b, 1, f); |
// fread(b, sizeof b, 1, f); |
Line 57 main(int argc, char **argv)
|
Line 65 main(int argc, char **argv)
|
fseek(f, -10, SEEK_END); |
fseek(f, -10, SEEK_END); |
fwrite("123456789", 10, 1, f); |
fwrite("123456789", 10, 1, f); |
fseek(f, -10, SEEK_END); |
fseek(f, -10, SEEK_END); |
|
memset(b, 0, sizeof b); |
fread(b, sizeof b, 1, f); |
fread(b, sizeof b, 1, f); |
printf("2.b=%s\n", b); |
printf("2.b=%s\n", b); |
|
|
Line 64 main(int argc, char **argv)
|
Line 73 main(int argc, char **argv)
|
|
|
// part 3 |
// part 3 |
|
|
p = malloc(10000); | p = e_malloc(10000); |
f = io_fmemopen(&p, 10000); |
f = io_fmemopen(&p, 10000); |
if (!f) { |
if (!f) { |
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError()); |
printf("Error:: #%d - %s\n", io_GetErrno(), io_GetError()); |
Line 73 main(int argc, char **argv)
|
Line 82 main(int argc, char **argv)
|
|
|
fwrite("123456789", 10, 1, f); |
fwrite("123456789", 10, 1, f); |
fseek(f, 0, SEEK_SET); |
fseek(f, 0, SEEK_SET); |
|
memset(b, 0, sizeof b); |
fread(b, sizeof b, 1, f); |
fread(b, sizeof b, 1, f); |
printf("b=%s\n", b); |
printf("b=%s\n", b); |
// fread(b, sizeof b, 1, f); |
// fread(b, sizeof b, 1, f); |
Line 83 main(int argc, char **argv)
|
Line 93 main(int argc, char **argv)
|
fseek(f, -10, SEEK_END); |
fseek(f, -10, SEEK_END); |
fwrite("123456789", 10, 1, f); |
fwrite("123456789", 10, 1, f); |
fseek(f, -10, SEEK_END); |
fseek(f, -10, SEEK_END); |
|
memset(b, 0, sizeof b); |
fread(b, sizeof b, 1, f); |
fread(b, sizeof b, 1, f); |
printf("2.b=%s\n", b); |
printf("2.b=%s\n", b); |
|
|
fclose(f); |
fclose(f); |
free(p); | e_free(p); |
|
|
return 0; |
return 0; |
} |
} |