I run the below program. I expected it'll give error. But it run perfectly and gave output.
Program:
#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
also works for
lseek(fd, -3I, SEEK_END); //but didn't print anything
For other letters it's giving error like
error: invalid suffix "S" on integer constant
What is the meaning of L
and I
on lseek?