以下のプログラムを実行します。エラーになると思っていました。しかし、それは完全に実行され、出力が得られました。
プログラム:
#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
L
and I
on lseekとはどういう意味ですか?