stderr is seekable? (lseek(2))

Harti Brandt harti at freebsd.org
Tue Sep 14 01:02:43 PDT 2004


On Tue, 14 Sep 2004, Jun Kuriyama wrote:

JK>
JK>When I tested this program, it finished successfully.  But on Linux,
JK>lseek(2) returns -1 and errno is ESPIPE.
JK>
JK>I expected to be returned ESPIPE as Linux did.  Is our behavior
JK>correct, or there is something wrong?

Posix requires to return EPIPE when the file is a socket, pipe or fifo.
I assume you start the program with stderr connected to tty? This case
seems not to be specified, so we are free to return whatever we want (but 
should probably document it). There is only one place in Posix that talks 
about seeking and terminals: in the read() man page. But this place does 
not place any requirement on lseek(), but on pread() with an implied seek 
(to return an error).

harti

JK>
JK>-----
JK>#include <sys/types.h>
JK>#include <unistd.h>
JK>#include <stdio.h>
JK>#include <errno.h>
JK>
JK>int
JK>main(int argc, char **argv)
JK>{
JK>  off_t r = lseek(2, 1, SEEK_CUR);
JK>  printf("r=%d\n", r);
JK>  if (r == -1) {
JK>    printf("errno=%d, %s\n", errno, strerror(errno));
JK>  }
JK>  return 0;
JK>}
JK>-----
JK>
JK>
JK>


More information about the freebsd-arch mailing list