open(O_RDWR) and lseek() fail

Roy roytam@gmail.com
Fri Mar 28 09:00:00 GMT 2014


Hello list,

I wonder why lseek(SEEK_CUR) on open(O_RDWR) fails with errno=22, the code  
works on Linux:

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
int main(int argc, char** argv){
  int f,v1,v2;
  v1 = 1234;
  close(creat("1.bin", 0600));
  f = open("1.bin", O_RDWR);
  printf("wrote %d bytes.\n",write(f, (char *)&v1, sizeof(int)));
  printf("pos = %d\n",lseek(f, 0l, SEEK_CUR));
  printf("errno = %d\n",errno);
  printf("seek to beginning.\n");
  lseek(f, 0l, SEEK_SET);
  printf("errno = %d\n",errno);
  printf("read %d bytes.\n",read(f, (char *)&v2, sizeof(int)));
  printf("v2 = %d\n",v2);
  close(f);
}

On Linux it gives no error:
wrote 4 bytes.
pos = 4
errno = 0
seek to beginning.
errno = 0
read 4 bytes.
v2 = 1234

But not on cgywin(both 1.5 and 1.7 fails):
wrote 4 bytes.
pos = -1
errno = 22
seek to beginning.
errno = 22
read 0 bytes.
v2 = 2272412

Whats wrong with cygwin?

Regards,
Roy


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple



More information about the Cygwin mailing list