/*test.c*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
int main(void)
{
int fd;
char a;
int nread = 0;
int n = 0;
fd = open("test.txt", O_RDWR);
if(fd < 0)
{
perror("openfd");
exit(-1);
}
n = lseek(fd, 6, SEEK_SET);
// n = lseek(fd, -4, SEEK_END);
printf("%d\n",n);
nread = read(fd, &a, 1);
printf("%d\n",nread);
putchar(a);
return 0;
}
/*test.txt*/
123456789
运行:
./test.o
6
1
7
// n = lseek(fd, 6, SEEK_SET);
n = lseek(fd, -4, SEEK_END);
运行:
./test.o
6
0
为什么同样的偏移量不同的写法会导致读不到呢?