This is the mail archive of the cygwin@sourceware.cygnus.com 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]

fread/fwrite problems in b18



Hi! I wonder if anyone can help.  I've written a short program to remove a
fix sized header (of 512 bytes) from a raw image file. However when I
compile it and run under gcc b18, I do not get the output I expect. That
is the output file size is always 30 bytes. The same code compiles and
works perfectly in Solaris 2.4 and Linux 2.0.27. The truncated version of
the code is fowarded below.

The computer which I'm using is a P100 with 16Mb RAM.

Another problem which I'm facing is that when I allocate a large array,
say 1000x1000 and when I read and write data to/off it, I get junk towards
1/4 way into the array. Once again the same code works very well in the
platforms above. Is there a problem with memory allocation? I'll send a
truncated piece of code later, unless the problem has been previously
logged. 

Thanks.

Regards,
Bala


========== Forwarded code starts here ================

/* Program to delete 512 byte headers of image files */

#include <stdio.h>

main(argc,argv)
int argc;
char **argv;
{
        FILE    *infile, *outfile;
        char    buf[BUFSIZ];
        int     n;


        if (argc<2)
        {
                fprintf(stderr,"Usage : %s <infile>\n",argv[0]);
                exit(1);
        }

        /* image file */
        if ((infile=fopen(argv[1],"r"))==NULL)
        {
                perror(argv[1]);
                exit(1);
        }

        /* create temp file */
        if ((outfile=fopen("outfile","w"))==NULL)
        {
                perror("outfile");
                exit(1);
        }


        /* Skip 512 byte header */
        fread(buf,sizeof(char),512,infile);

        /* Write rest of file to outfile */
        while((n=fread(buf,sizeof(char),BUFSIZ,infile))>0)
                fwrite(buf,sizeof(char),n,outfile);

        fclose(infile);
        fclose(outfile);
}


========== Code ends here ================


-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


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