LabWindows/CVI

Content Type
Programming Language
Current manual

open

open

int open (const char fileName[], int openFlags, ...);

Purpose

Opens a file with the specified name according to the operation flags and returns a handle to the opened file.

Note Note  This function is not in the ANSI standard. You must include lowlvlio.h in your program or interactive window to use this function.

Parameters

Input
Name Type Description
fileName const char [] Specifies the name of the file that is opened if successful. Relative pathnames are valid only if relative to the current working directory.
Note Note  In pathnames that include backslashes, replace each single backslash with a double backslash to avoid delimiter collision.
openFlags int Contains flags to specify the allowable operations on the opened file. The flags can be combined with the bitwise OR operator, "|".
Flag Description Equivalent
O_RDONLY 0x0 Opens file for reading only. Neither O_WRONLY or O_RDWR can be used with it. _O_RDONLY
O_WRONLY 0x1 Opens file for writing only. Neither O_RDONLY or O_RDWR can be used with it. _O_WRONLY
O_RDWR 0x2 Opens file for both reading and writing. Neither O_RDONLY or O_WRONLY can be used with it. _O_RDWR
O_APPEND 0x4 Repositions the file pointer to the end of the file before every write operation. _O_APPEND
O_CREAT 0x8 Creates file if it does not exist. _O_CREAT
O_TRUNC 0x10 Truncates file to 0 bytes if it exists. _O_TRUNC
O_BINARY 0x20 Does not translate newline characters or carriage returns. _O_BINARY
O_TEXT 0x40 Translates carriage returns to newlines. _O_TEXT
O_EXCL 0x80 If O_CREAT, reports error if file exists. _O_EXCL
O_TEMPORARY 0x100 Creates file as temporary; file is deleted when last file handle is closed. Win32 only. _O_TEMPORARY
O_RANDOM 0x200 Directs system to access file randomly. Win32 only. _O_RANDOM
O_SEQUENTIAL 0x400 Directs system to access file sequentially. Win32 only. _O_SEQUENTIAL
permissions ... A parameter to specify permissions for the file. This parameter is required if the file is being created by this function call. Otherwise, it is ignored and can be omitted. All of these flags are compatible with the POSIX standard. However, under Windows, they affect only whether the file is a read-only file. In Windows:
  • There is no distinction between owner, group, or others. If a permission is set of any of the three, it is set for all.
  • The read and execute permissions are ignored.
  • A file cannot be created with write-only permissions.
  • The sticky bits are ignored.
Owner Permissions
Permissions Notes Equivalent
S_IRUSR 0x1 Ignored in Windows _S_IRUSR
S_IWUSR 0x2 _S_IWUSR
S_IXUSR 0x4 Ignored in Windows _S_IXUSR
S_IRWXU 0x7 _S_IRWXU
Group Permissions
Permissions Notes Equivalent
S_IRGRP 0x10 Ignored in Windows _S_IRGRP
S_IWGRP 0x20 _S_IWGRP
S_IXGRP 0x40 Ignored in Windows _S_IXGRP
S_IRWXG 0x70 _S_IRWXG
Other Permissions
Permissions Notes Equivalent
S_IROTH 0x100 Ignored in Windows _S_IROTH
S_IWOTH 0x200 _S_IWOTH
S_IXOTH 0x400 Ignored in Windows _S_IXOTH
S_IRWXO 0x700 _S_IRWXO
Sticky Bits
Permissions Notes Equivalent
S_ISUID 0x1000 Ignored in Windows _S_ISUID
S_IGUIS 0x2000 Ignored in Windows _S_IGUIS

Summaries Across Owner/Group/Other
Permissions Summaries Notes Equivalent
S_IREAD (S_IRUSR | S_IRGRP | S_IROTH) Ignored in Windows _S_IREAD
S_IWRITE (S_IWUSR | S_IWGRP | S_IWOTH) _S_IWRITE
S_IEXEC (S_IXUSR | S_IXGRP | S_IXOTH) Ignored in Windows _S_IEXEC

Return Value

Name Type Description
fileHandle int Contains a handle to the opened file if successful. If the open operation fails, open returns -1 and sets errno to a nonzero value.

Additional Information

Library: ANSI C Library

Include file: lowlvlio.h

LabWindows/CVI compatibility: LabWindows/CVI 3.0 and later

Was this information helpful?