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

#include <fcntl.h>
#include <stdio.h>
#include "gfal_api.h"

Go to the source code of this file.

Defines

#define BLKLEN   65536

Functions

 main (int argc, char **argv)


Define Documentation

#define BLKLEN   65536
 

Definition at line 12 of file gfal_testrw.c.


Function Documentation

main int  argc,
char **  argv
 

Definition at line 14 of file gfal_testrw.c.

References BLKLEN, gfal_close(), gfal_open(), gfal_read(), and gfal_write().

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:48 2006 for GFAL by  doxygen 1.4.6