我运行下面的程序。我预计它会出错。但它运行完美并给出了输出。
程序:
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
int main()
{
int fd, retval;
char wBuf[20] = "Be my friend", rBuf[20] = {0};
fd = open("test.txt", O_RDWR | O_CREAT, 0666);
write(fd, wBuf, strlen(wBuf));
retval = lseek(fd, -3L, SEEK_END); //Observe 2nd argument
if(retval < 0) {
perror("lseek");
exit(1);
}
read(fd, rBuf, 5);
printf("%s\n", rBuf);
}
lseek
也适用于
lseek(fd, -3I, SEEK_END); //but didn't print anything
对于其他字母,它会给出错误,例如
error: invalid suffix "S" on integer constant
lseekL
和on是什么意思?I