This exemple show how to open, write a file and read it after ex : use case with SRM plugin : ./gfal_testrw srm://grid05.lal.in2p3.fr:8446/dpm/lal.in2p3.fr/home/dteam/test_yoda
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#define BLKLEN 65536
main(int argc, char **argv)
{
int fd;
int i;
char ibuf[BLKLEN];
char obuf[BLKLEN];
int rc;
if (argc != 2) {
fprintf (stderr, "usage: %s filename\n", argv[0]);
exit (1);
}
for (i = 0; i < BLKLEN; i++)
obuf[i] = i;
printf ("creating file %s\n", argv[1]);
if ((fd =
gfal_open (argv[1], O_WRONLY|O_CREAT, 0644)) < 0) {
exit (1);
}
printf ("open successful, fd = %d\n", fd);
if ((rc =
gfal_write (fd, obuf, BLKLEN)) != BLKLEN) {
exit (1);
}
printf ("write successful\n");
exit (1);
}
printf ("close successful\n");
printf ("reading back %s\n", argv[1]);
if ((fd =
gfal_open (argv[1], O_RDONLY, 0)) < 0) {
exit (1);
}
printf ("open successful, fd = %d\n", fd);
if ((rc =
gfal_read (fd, ibuf, BLKLEN)) != BLKLEN) {
exit (1);
}
printf ("read successful\n");
exit (1);
}
printf ("close successful\n");
for (i = 0; i < BLKLEN; i++) {
if (ibuf[i] != obuf[i]) {
fprintf (stderr, "compare failed at offset %d\n", i);
exit (1);
}
}
printf ("compare successful\n");
exit (0);
}