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

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2003 by CERN
00003  */
00004 
00005 /*
00006  * @(#)$RCSfile: gfal_testrw.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 ("creating file %s\n", argv[1]);
00031         if ((fd = gfal_open (argv[1], O_WRONLY|O_CREAT, 0644)) < 0) {
00032                 perror ("gfal_open");
00033                 exit (1);
00034         }
00035         printf ("open successful, fd = %d\n", fd);
00036 
00037         if ((rc = gfal_write (fd, obuf, BLKLEN)) != BLKLEN) {
00038                 if (rc < 0)
00039                         perror ("gfal_write");
00040                 else
00041                         fprintf (stderr, "gfal_write returns %d\n", rc);
00042                 (void) gfal_close (fd);
00043                 exit (1);
00044         }
00045         printf ("write 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         printf ("reading back %s\n", argv[1]);
00054         if ((fd = gfal_open (argv[1], O_RDONLY, 0)) < 0) {
00055                 perror ("gfal_open");
00056                 exit (1);
00057         }
00058         printf ("open successful, fd = %d\n", fd);
00059 
00060         if ((rc = gfal_read (fd, ibuf, BLKLEN)) != BLKLEN) {
00061                 if (rc < 0)
00062                         perror ("gfal_read");
00063                 else
00064                         fprintf (stderr, "gfal_read returns %d\n", rc);
00065                 (void) gfal_close (fd);
00066                 exit (1);
00067         }
00068         printf ("read successful\n");
00069 
00070         if ((rc = gfal_close (fd)) < 0) {
00071                 perror ("gfal_close");
00072                 exit (1);
00073         }
00074         printf ("close successful\n");
00075 
00076         for (i = 0; i < BLKLEN; i++) {
00077                 if (ibuf[i] != obuf[i]) {
00078                         fprintf (stderr, "compare failed at offset %d\n", i);
00079                         exit (1);
00080                 }
00081         }
00082         printf ("compare successful\n");
00083         exit (0);
00084 }

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