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