This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: ftell() fails on files in shared folders


Corinna,

> No, it doesn't change that often. ?1.7.9 is actually a year old,
> though. ?Updating *might* help.
>
> Btw., assuming you call lseek(fileno(p), SEEK_CUR, 0) rather than
> ftell(p), what position does it return?

I have rewritten my program to use only low-level API (open, write,
lseek) and installed latest Cygwin. It seems that the error is caused
by O_RDWR - as soon as I change it to O_WRONLY everything starts to
work:

Local, O_WRONLY:
  C:\Users\gribov.y>\\s-cw-head\pgas\a.exe //s-cw-head/c$/test.bin
  success

Local, O_RDWR:
  C:\Users\gribov.y>\\s-cw-head\pgas\a.exe //s-cw-head/c$/test.bin rw
  success

Remote, O_WRONLY:
  C:\Users\gribov.y>\\s-cw-head\pgas\a.exe //s-cw-node01/c$/test.bin
  success

Remote, O_RDWR:
  C:\Users\gribov.y>\\s-cw-head\pgas\a.exe //s-cw-node01/c$/test.bin rw
  sizeof(data) == lseek(fd, 0, SEEK_END) failed at io.c:36

-- 
Best regards,
Yuri
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <fcntl.h>

#define CHECK(cond) do { \
	if( !(cond) ) { \
		printf("%s failed at %s:%d\n", #cond, __FILE__, __LINE__); \
		exit(1); \
	} } while(0)

int main(int argc, char *argv[]) {
  if( argc < 2 ) {
    fprintf(stderr, "Syntax: a.exe fname [mode]\n");
    exit(1);
  }

  const char *fname = argv[1];

  int mode = O_CREAT | O_TRUNC;
  if( argc > 2 && 0 == strcmp("rw", argv[2]) )
    mode |= O_RDWR;
  else
    mode |= O_WRONLY;

  const int perm = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH;
  const unsigned data = -1;

  int fd = open(fname, mode, perm);
  CHECK( -1 != fd );
  close(fd);

  fd = open(fname, mode, perm);
  CHECK( -1 != fd );
  CHECK( sizeof(data) == write(fd, &data, sizeof(data)) );
  CHECK( sizeof(data) == lseek(fd, 0, SEEK_END) );
  CHECK( sizeof(data) == lseek(fd, 0, SEEK_CUR) );

  printf("success\n");

  return 0;
}

--
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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]