HP 3000 Manuals

open [ HP C/iX Library Reference Manual ] MPE/iX 5.0 Documentation


HP C/iX Library Reference Manual

open 

Opens a file for reading or writing.

Syntax 

     #include <fcntl.h>[REV BEG]
     int open (char *path, int oflag [,int mode [,char mpe_opts]] );[REV END]

Parameters 

                [REV BEG]

path          A pointer to a path name naming a file.[REV END]

oflag         An integer containing open mode bit flags.

mode          An unused integer parameter provided for compatibility with
              other systems.

mpe_opts      A pointer to a string containing file attributes and
              options.

Return Values 

x             Upon successful completion, the integer file descriptor is
              returned.

-1            Unsuccessful completion.  In addition, errno is set to the
              indicated value if one of the following conditions is true:

              ENOENT     The fname is null, or the named file does not
                         exist and you did not use oflag to request that
                         it be created.

              EACCES     The oflag permission is denied for the named
                         file.

              EMFILE     The maximum number of file descriptors allowed
                         are currently open.

              EINVAL     The oflag specifies incompatible read/write
                         access flags.

              ESYSERR    A call to a system intrinsic failed.

Description 

The open function opens the file descriptor described in fname.  It uses
the value of oflag to determine how to open the file.

Opening a file in read mode fails if the file does not exist or cannot be
read.

The oflag parameter values are constructed by OR-ing flags from the list
below.  Notice that exactly one of the first three flags below must be
used.

O_RDONLY      Open for reading only.

O_WRONLY      Open for writing only.

O_RDWR        Open for reading and writing.

O_APPEND      If set, the file pointer is set to the end of the file
              prior to each write.

O_CREAT       If the file exists, this flag has no effect.  If the file
              does not exist, the file is created.

O_TRUNC       If the file exists, its length is truncated to zero and the
              mode and owner are unchanged.  The file pointer used to
              mark the current position within the file is set to the
              beginning of the file.

O_MPEOPTS     If this flag is specified, the argument mpe_opts specifies
              additional open options that provide greater control in the
              MPE file environment.

The mode parameter is ignored.  It is provided for compatibility with
other systems.

The mpe_opts argument points to a string of characters described below.
Spaces can be used in the mpe_opts string to improve readability.  Notice
that the case of the options is important.  An uppercase B is different
from a lowercase b.

b             If the b option is specified, the file is created as a
              binary file if this call to fopen creates the file.  The
              default is to create an ASCII file.

Bln           The Bl option specifies the blocking factor to use if this
              call to fopen() creates the file.  The option character is
              followed by an integer that indicates the blocking factor.
              If the Bl option is not specified, then the default is one
              record per block.
              [REV BEG] 

Bs            If the Bs option is specified, the file is opened or
              created as a byte stream file.  This is the only required
              option for opening byte stream files.  The maximum file
              size for a byte stream file is two gigabytes.  If
              specified, the Rn option is ignored.  The Sn option can be
              used to reset the file size.  This option is mutually
              exclusive with the V option.  If the Bs or V options are
              not specified, the file is created with an MPE fixed-length
              record format.
              [REV END]

Bun           The Bu option specifies the number of buffers to be
              allocated to this file.  If the Bu option is not specified,
              the default is 2.

C             If the C option is specified, then the file accepts
              carriage control information.  The default is to not have
              carriage control.

Dfn           The Df option specifies the final disposition of the file
              after the file is closed.  The affect of each value of n is
              defined as follows:

--------------------------------------
|        |                           |
|   0    | Don't change the          |
|        | disposition.              |
|        |                           |
--------------------------------------
|        |                           |
|   1    | Save the file as a        |
|        | permanent file.           |
|        |                           |
--------------------------------------
|        |                           |
|   2    | Save the file as a        |
|        | temporary file.           |
|        |                           |
--------------------------------------
|        |                           |
|   3    | Don't rewind on close.    |
|        |                           |
--------------------------------------
|        |                           |
|   4    | Purge the file on close.  |
|        |                           |
--------------------------------------

              If the Df option is not specified and the file is a new
              file, then the default is to save the file as a permanent
              file.  If the file is old, the default is not to change the
              disposition.

Dsn           The Ds option specifies the disk space disposition of the
              file after the file is closed for fixed, undefined, and
              variable format files.  The affect of each value of n is
              defined as follows:

-----------------------------------------------
|        |                                    |
|   0    | Don't return any disk space        |
|        | allocated beyond the end-of-file   |
|        | indicator.                         |
|        |                                    |
-----------------------------------------------
|        |                                    |
|   1    | Return to the system any disk      |
|        | space allocated beyond the         |
|        | end-of-file indicator.  The EOF    |
|        | becomes the file limit.  No        |
|        | records may be added to the file   |
|        | beyond this new limit.             |
|        |                                    |
-----------------------------------------------
|        |                                    |
|   2    | Return to the system any disk      |
|        | space allocated beyond the         |
|        | end-of-file indicator, but do not  |
|        | set the file limit to EOF, and     |
|        | allow records to be added to the   |
|        | file up to the file limit.         |
|        |                                    |
-----------------------------------------------

              If the Ds option is not specified, the default is not to
              return any disk space allocated beyond the end-of-file
              indicator.

En            The E option specifies the maximum number of extents that
              can be allocated to the file.  The maximum value is 32.
              The default value, if the E option is not specified, is 8
              extents.

Fn            The F option indicates the value used as the file code if
              this call to fopen() creates the file.  If the F option is
              not specified, the file code is zero.

L             If specified, the L option indicates that dynamic locking
              should be allowed on this file.

Mn            The M option controls multiaccess.  The option character is
              followed by an integer that indicates the level of
              multiaccess for this open request.  The levels are
              specified in the MPE/iX Intrinsics Reference Manual under
              the FOPEN intrinsic description.

Q             If the Q option is specified, file equations are
              disallowed.  The default is to allow file equations.

Rn            The R option specifies the size of the record if the file
              is created by this open request.  If the V option is also
              used, this option specifies the maximum size of the
              variable-sized records.  The option letter is followed by a
              decimal number that is equal to the number of bytes in the
              record size.  Notice that the number must be positive.  A
              byte count is always specified.  If the R option is not
              provided, then the default record size is 256 bytes.

Sn            The S option specifies the maximum size of the file.  The
              value of n is the maximum size of the file in records for
              text and binary streams, and in bytes for byte streams.
              Notice that if the S parameter is not specified, the
              default is 4095.

Te            If the Te option is specified, the file is saved in the
              temporary file domain.  If the Te option is not specified
              and the file is a new file, the default is to save the file
              as a permanent file.  If the file is old, the default is to
              not change the disposition.

Tm            If the Tm option is specified, disk read functions trim
              editor line numbers, if they exist, and trailing blanks
              from each record of an ASCII fixed record length file
              before returning file data to the reader.  This option is
              used on files opened with read only access.  Random access
              to file data using fseek() and lseek() is not permitted.
              The default is to not trim editor line numbers and blanks.

Un            If the U option is specified, the file is created with n 
              user-label records.  If this option is not specified, the
              default is no user-label records.
              [REV BEG]

V             If the V option is specified, the file is created with an
              MPE variable-length record format.  If the V or Bs options
              are not specified, then the file is created with an MPE
              fixed-length record format.  This option is mutually
              exclusive with the Bs option.
              [REV END]

Xn            The X option controls exclusive access ability for the
              file.  The option character is followed by an integer that
              indicates the level of exclusivity for this open request.
              The levels are specified in the MPE/iX Intrinsics Reference 
              Manual under the FOPEN intrinsic.
[REV BEG]


NOTE If linking with the POSIX/iX library, refer to the description of open() located in the MPE/iX Developer's Kit Reference Manual.
[REV END] Examples The following creates or opens a fixed record binary file f1 for writing with 256 byte records, a file size of 10000 records, and a file code of 1030: #include <fcntl.h> int fd; fd = open("f1",O_WRONLY | O_CREAT | O_MPEOPTS, 0664, "b R256 s10000 F1030"); To open an existing file f1 for reading: #include <fcntl.h> int fd; fd = open("f1",O_RDONLY); See Also fopen()


MPE/iX 5.0 Documentation