delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2001/01/22/22:15:01

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sources DOT redhat DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sources DOT redhat DOT com>
List-Help: <mailto:cygwin-help AT sources DOT redhat DOT com>, <http://sources.redhat.com/ml/#faqs>
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: <v04210106b692974bf0a1@[64.13.5.209]>
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 <dave-cygwin AT centerclick DOT org>
Subject: problems with read()

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 <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>

#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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019