/Home/aooliver/work/stagersvc/org.glite.data.lcg_gfal/src/gfal_testread.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 by CERN
00003  */
00004 
00005 /*
00006  * @(#)$RCSfile: gfal_testread.c,v $ $Revision: 1.1.1.1 $ $Date: 2006/09/06 08:54:53 $ CERN Jean-Philippe Baud
00007  */
00008 
00009 #include <fcntl.h>
00010 #include <stdio.h>
00011 #include "gfal_api.h"
00012 #define BLKLEN 65536
00013 
00014 main(int argc, char **argv)
00015 {
00016         int fd;
00017         int i;
00018         char ibuf[BLKLEN];
00019         char obuf[BLKLEN];
00020         int rc;
00021 
00022         if (argc != 2) {
00023                 fprintf (stderr, "usage: %s filename\n", argv[0]);
00024                 exit (1);
00025         }
00026 
00027         for (i = 0; i < BLKLEN; i++)
00028                 obuf[i] = i;
00029 
00030         printf ("opening %s\n", argv[1]);
00031         if ((fd = gfal_open (argv[1], O_RDONLY, 0)) < 0) {
00032                 perror ("gfal_open");
00033                 exit (1);
00034         }
00035         printf ("open successful, fd = %d\n", fd);
00036 
00037         if ((rc = gfal_read (fd, ibuf, BLKLEN)) != BLKLEN) {
00038                 if (rc < 0)
00039                         perror ("gfal_read");
00040                 else
00041                         fprintf (stderr, "gfal_read returns %d\n", rc);
00042                 (void) gfal_close (fd);
00043                 exit (1);
00044         }
00045         printf ("read successful\n");
00046 
00047         if ((rc = gfal_close (fd)) < 0) {
00048                 perror ("gfal_close");
00049                 exit (1);
00050         }
00051         printf ("close successful\n");
00052 
00053         for (i = 0; i < BLKLEN; i++) {
00054                 if (ibuf[i] != obuf[i]) {
00055                         fprintf (stderr, "compare failed at offset %d\n", i);
00056                         exit (1);
00057                 }
00058         }
00059         printf ("compare successful\n");
00060         exit (0);
00061 }

Generated on Fri Sep 8 20:20:47 2006 for GFAL by  doxygen 1.4.6