ffopen

Date:

03-16-2012

NAME

ffopen, ffopens, ffclose, ffopenf, ffclosef - Opens or closes a file using flexible file I/O

SYNOPSIS

#include <fcntl.h>
#include <ffio.h>


int ffopen (const char *name, int oflag [, mode_t mode]);

int ffopens (const char *name, int oflag, mode_t mode,
long cbits, int cblks, struct ffsw *stat, const char *str);

int ffclose (int fd);

int ffclosef (int fd, struct ffsw *stat);

int ffopenf (const char *name, int oflag, mode_t mode,
long cbits, int cblks, struct ffsw *stat);

IMPLEMENTATION

Cray Linux Environment (CLE)

DESCRIPTION

The ffopen and ffopens functions open a file using flexible file I/O (FFIO). These functions are modeled after the open(2) system call. The file associated with name is opened, and appropriate structures are built to do special handling on the file. For ffopen, the processing layers to be used are as requested with the assign(1) command. For ffopens, the layers are specified by the string at str.

The ffopen function returns an integer. Although it is not a file descriptor, it is used in much the same way when passed to the other FFIO functions such as ffread, ffwrite, or ffclose.

The oflag and mode parameters are exactly as in open(2).

The cbits and cblks parameters are for compatibility with older UNICOS systems and are ignored.

The stat parameter is a pointer to a status return structure containing a flag, an error indication, a transfer count, and an indication of the condition that terminated the request. If stat is NULL, the error will be returned in errn0.

The ffclose and ffclosef functions close the file associated with fd. It does any necessary flushing and termination for that file. Files opened using ffopen(3c) are not guaranteed to be flushed at program termination; call ffclose or ffclosef to ensure this.

RETURN VALUES

Upon successful completion, a non-negative integer is returned; this integer is an index in a control block. Otherwise, -1 is returned, and, if the stat parameter is passed, the error value is found in stat.sw_error. If the stat parameter is NULL or not provided, the error code is found in errno.

EXAMPLES

To write a C program that will read the records of an f77 blocked file named indata and copy the data from the file (without blocking information) to stdout, compile the following program:

#define _GNU_SOURCE
#include <stdio.h>
#include <fcntl.h>
#include <ffio.h>

#define BSZ 0x20000

int main()
{
      int fd;
      ssize_t ret;
      char buf[BSZ];
      struct ffsw stat;
      int ubc = 0;

      fd = ffopen("indata", O_RDONLY);
      do
      {
            ret = ffreadf(fd, buf, BSZ, &stat, PARTIAL, &ubc);
            fwrite(buf, 1, ret, stdout);
       } while (FFSTAT(stat) != FFEOD);
       ret = ffclose(fd);
}

Use the following commands to compile, link, and run this program on CLE:

$ cc cpy.c
$ setenv FILENV ASGTMP
$ assign -F f77 indata
$ aprun a.out

The same example program could be written to use the ffopens entry point. The layers to use in decoding the blocking information are specified in the call, as shown in the following example:

#define _GNU_SOURCE
#include <stdio.h>
#include <fcntl.h>
#include <ffio.h>

#define BSZ 0x20000

int main()
{
      int fd;
      ssize_t ret;
      char buf[BSZ];
      char *str;
      struct ffsw stat;
      int ubc = 0;

      /* Set up to process f77 blocked file. */
      str = "f77";
      fd = ffopens("indata", O_RDONLY, 0, 0L, 0, &stat, str);
      do
      {
            ret = ffreadf(fd, buf, BSZ, &stat, PARTIAL, &ubc);
            fwrite(buf, 1, ret, stdout);
      } while (FFSTAT(stat) != FFEOD);
      ret = ffclose(fd);
}

SEE ALSO

ffread(3c), ffseek(3c)

open(2)