About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/open.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 open Context: slangrtl

Synopsis

Open a file

Syntax

FD_Type open (String_Type filename, Int_Type flags [,Int_Type mode])

Description

The open function attempts to open a file specified by the filename parameter according to the flags parameter, which must be one of the following values:

     O_RDONLY   (read-only)
     O_WRONLY   (write-only)
     O_RDWR     (read/write)

In addition, flags may also be bitwise-or'd with any of the following:

     O_BINARY   (open the file in binary mode)
     O_TEXT     (open the file in text mode)
     O_CREAT    (create file if it does not exist)
     O_EXCL     (fail if the file already exists)
     O_NOCTTY   (do not make the device the controlling terminal)
     O_TRUNC    (truncate the file if it exists)
     O_APPEND   (open the file in append mode)
     O_NONBLOCK (open the file in non-blocking mode)

Some of these flags only make sense when combined with other flags. For example, if O_EXCL is used, then O_CREAT must also be specified, otherwise unpredictable behavior may result.

If O_CREAT is used for the flags parameter then the mode parameter must be present. mode specifies the permissions to use if a new file is created. The actual file permissions will be affected by the process's umask via mode&~umask. The mode parameter's value is constructed via bitwise-or of the following values:

     S_IRWXU    (Owner has read/write/execute permission)
     S_IRUSR    (Owner has read permission)
     S_IWUSR    (Owner has write permission)
     S_IXUSR    (Owner has execute permission)
     S_IRWXG    (Group has read/write/execute permission)
     S_IRGRP    (Group has read permission)
     S_IWGRP    (Group has write permission)
     S_IXGRP    (Group has execute permission)
     S_IRWXO    (Others have read/write/execute permission)
     S_IROTH    (Others have read permission)
     S_IWOTH    (Others have write permission)
     S_IXOTH    (Others have execute permission)

Upon success open returns a file descriptor object (FD_Type), otherwise NULL is returned and errno is set.

If you are not familiar with the open system call, then it is recommended that you use fopen instead.

Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.