NXFileOpen

Opens the specified file (simplified interface).

Library:LibC
Classification:NKS
Service:File and Directory I/O

Syntax

  #include <nks/fsio.h> 
  
  int NXFileOpen (
     NXPathCtx_t   pathCtx,   
     const void   *pathname, 
     NXMode_t      mode, 
     NXHandle_t   *fileHandle); 
  

Parameters

pathCtx

(IN) Specifies the file system path context. Along with the pathname parameter, it specifies the file to open.

pathname

(IN) Points to a null-terminated Unicode or ASCII string that specifies the name of the file (relative to pathCtx) to open or create.

mode

(IN) Specifies if the file is to be opened for reading, writing, or both. See NKS Open Modes.

fileHandle

(OUT) Points to an integer-valued open file descriptor on success. On failure, returns -1.

Return Values

If successful, returns 0 and an open file descriptor in the fileHandle parameter. Otherwise, returns an error code. On failure the new file remains unopened. However, if the request was overwrite a file and NXFileOpen fails, the file might be destroyed in the process.

Decimal

Hex

Constant

Description

1

0x01

NX_ENOENT

A component of the path prefixes specified by pathname or pathCtx does not exist, or pathname is NULL. Alternatively, the file does not exist and the NX_O_CREATE mode is not specified.

4

0x04

NX_EBADF

Invalid directory handle.

5

0x05

NX_NOMEM

Insufficient memory to perform the operation.

6

0x06

NX_EACCES

Insufficient rights to the object.

7

0x07

NX_EEXIST

The specified file exists, and the NX_O_EXCL mode was specified.

9

0x09

NX_EINVAL

A pathCtx was specified, but pathname indicates a full path.

12

0x0C

NX_ENOSPC

File system in which a new file is to be created does not have enough media space.

10

0x0A

NX_ENFILE

The system limit, if any, on the number of open files has been reached.

24

0x18

NX_EAGAIN

Resource exhaustion prevented successful completion of the call.

64

0x40

NX_EISDIR

A directory object that has the same name as the specified file exists.

65

0x41

NX_ENAMETOOLONG

The pathname contents are longer than system-permitted name length.

105

0x69

NX_ENOCONTEXT

The calling thread has no NKS context.

Remarks

NXFileOpen creates a file handle and associates it with a file. In the process of setting up this association, the named file is opened by the system, and a description of the open file is set up so that I/O functions referring to that file can use the state information contained in the description.

Each time NXFileOpen is called, a new file descriptor is generated (even when the same pathname is opened).

By default, the share mode of NX_SHARE_DENYNO is used for NXFileOpen.

See Also