NXFileCreate

Is a macro that creates a new file or truncates an existing file by calling NXFileOpen.

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

Syntax

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

Parameters

pathCtx

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

pathname

(IN) Points to a null-terminated Unicode or ASCII string that specifies the name of the file to create or rewrite. If a file by the same name already exists under the directory specified by the pathCtx parameter and the caller has rights to delete the file, the existing file is deleted and a new file with the same name is created.

fileHandle

(OUT) Points to the returned open file descriptor that is associated with the created file on success. On failure, returns a -1.

Return Values

If successful, returns an open file descriptor. Otherwise, returns an error code.

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

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

NXFileCreate creates a new file by rewriting NXFileOpen. NXFileCreate is equivalent to:

  createFlags = NX_O_WRONLY | NX_O_CREAT | NX_O_TRUNC;
  NXFileOpen (pathCtx, pathname, createFlags, &fileHandle);
  

The file is opened for write only and with the default share mode of NX_SHARE_DENYNO (unless you call NXFileOpenEx).

If a previous file exists by the same name, it is possible that the previous file that was slated to be overwritten might be destroyed if NXFileCreate returns with a failure.

See Also