Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT sources DOT redhat DOT com Delivered-To: mailing list cygwin AT sources DOT redhat DOT com Mime-Version: 1.0 Message-Id: X-Mailer: QUALCOMM MacOS Eudora Pro Version 4.2.1 (PPC) Date: Mon, 22 Jan 2001 21:34:40 -0500 To: cygwin AT cygwin DOT com From: David Johnson Subject: problems with read() Content-Type: text/plain; charset="us-ascii" ; format="flowed" I'm seeing weird problems with read() Below is a simple program that open()'s a file and read()'s 4K at a time until the entire file is read. Opening the file with different paths seems to produce the problem while other paths have no problem. The first read to the file returns 20-40 bytes of the file and then each read after that returns 0 bytes of the file. This is on WinNT 4.0 Workstation SP6 cygwin 1.1.7 These two work ok: $ ./test_file_io.exe testfile1a file: 10240 bytes in size read: 0 start, 4096 read read: 4096 start, 4096 read read: 8192 start, 2048 read size: 10240, read: 10240 $ ./test_file_io.exe /home/administrator/testfile1a file: 10240 bytes in size read: 0 start, 4096 read read: 4096 start, 4096 read read: 8192 start, 2048 read size: 10240, read: 10240 This one doesn't: $ ./test_file_io.exe /cygdrive/c/cygwin/home/administrator/testfile1a file: 10240 bytes in size read: 0 start, 22 read read: 22 start, 0 read read: 22 start, 0 read read: 22 start, 0 read read: 22 start, 0 read read: 22 start, 0 read read: 22 start, 0 read read: 22 start, 0 read read: 22 start, 0 read [...] Program follows: #include #include #include #include #include #define BUFFERSIZE 4096 int testfile(char *filename); int main (int argc, char *argv[]) { if (argc != 2 || argv[1] == NULL) { fprintf(stderr,"Usage: %s filename\n",argv[0]); exit(1); } testfile(argv[1]); } int testfile(char *filename) { int fd; struct stat info; ssize_t read_len, so_far; unsigned char buffer[BUFFERSIZE]; /* open */ fd = open(filename, O_RDONLY); if (fd < 0) { perror("open"); return -1; } /* we need the file size */ if (fstat(fd, &info) < 0) { perror("fstat"); return -1; } printf("file: %8d bytes in size\n", info.st_size); /* read the file */ so_far = 0; while ( so_far < info.st_size ) { read_len = read(fd, buffer, BUFFERSIZE); if (read_len < 0) { perror("read"); return -1; } printf("read: %8d start, %8d read\n", so_far, read_len); so_far += read_len; } printf("size: %8d, read: %8d\n",info.st_size,so_far); } /* end */ -- Want to unsubscribe from this list? Check out: http://cygwin.com/ml/#unsubscribe-simple