]> git.proxmox.com Git - mirror_lxcfs.git/blob - tests/test-read.c
fix reinitialization with fuse3
[mirror_lxcfs.git] / tests / test-read.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2
3 #include "config.h"
4
5 #include <stdio.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9 #include <fcntl.h>
10 #include <errno.h>
11 #include <string.h>
12 #include <stdlib.h>
13
14 #define BUFSIZE 1025
15 char buf[BUFSIZE];
16
17 int read_count = 2;
18
19 int main(int argc, char *argv[]){
20 if(argc < 3){
21 fprintf(stderr, "usage: %s <file> <count> [buffer|direct]\n", argv[0]);
22 exit(1);
23 }
24 char *file = argv[1];
25 read_count = atoi(argv[2]);
26 int ret = 0,sum = 0, i = 0, fd = -1;
27 if(argc == 4 && strncmp(argv[3], "direct",6) == 0)
28 fd = open(file, O_RDONLY|O_DIRECT);
29 else
30 fd = open(file, O_RDONLY);
31
32 while(i++ < read_count){
33 memset(buf, 0, BUFSIZE);
34 ret = read(fd, buf, BUFSIZE-1);
35 if(ret > 0){
36 write(STDOUT_FILENO, buf, ret);
37 sum += ret;
38 }else if(ret == 0){
39 printf("======read end======\n");
40 break;
41 }else{
42 printf("error:%d\n", errno);
43 break;
44 }
45 sleep(1);
46 }
47 printf("======read sum: %d======\n", sum);
48 close(fd);
49 return 0;
50 }