gfal_testread.c

This example show how to open and read a file ex : use case with LFC plugin : ./gfal_testread lfn:/grid/dteam/test_skywalker

00001 
00006 #include <fcntl.h>
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include <errno.h>
00010 #include <gfal_api.h>
00011 #define BLKLEN 65536
00012 
00013 int main(int argc, char **argv)
00014 {
00015         int fd;
00016         char ibuf[BLKLEN];
00017         int rc;
00018 
00019         if (argc != 2) {
00020                 fprintf (stderr, "usage: %s filename\n", argv[0]);
00021                 exit (1);
00022         }
00023 
00024         printf ("opening %s\n", argv[1]);
00025         if ((fd = gfal_open (argv[1], O_RDONLY, 0)) < 0) {
00026                 gfal_posix_check_error();
00027                 exit (1);
00028         }
00029         printf ("open successful, fd = %d (errno = %d)\n", fd, errno);
00030 
00031         if ((rc = gfal_read (fd, ibuf, BLKLEN)) < 0) {
00032                 gfal_posix_check_error();
00033                 (void) gfal_close (fd);
00034                 exit (1);
00035         }
00036         printf ("read successful (errno = %d)\n", errno);
00037 
00038         printf ("buffer: \n");
00039         fputs(ibuf, stdout);
00040 
00041         if ((gfal_close (fd)) < 0) {
00042                 gfal_posix_check_error();
00043                 exit (1);
00044         }
00045         printf ("close successful\n");
00046         exit (0);
00047 }

Generated on 13 Mar 2014 for GFAL2 by  doxygen 1.4.7