Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

JavaScript OS.Constants

JavaScript module OS.Constants contains Operating System-specific constants. This module is largely a companion to js-ctypes.

Using OS.Constants

From the main thread

To initialize OS.Constants for use in the main thread, add the following snippet to your code:

 Components.classes["@mozilla.org/net/osfileconstantsservice;1"].
    getService(Components.interfaces.nsIOSFileConstantsService).
    init();

From a chrome worker

No initialization is required. Module OS.Constants is always available for chrome workers.

 

OS.Constants.Sys

Constants related to system configuration.

Name The name of the operating system (e.g. "Darwin").
DEBUG Set to true on debug build configurations, non-existent otherwise.

OS.Constants.Path

Paths of well-known files and directories.

libxul The path to the file containing libxul. Useful, for instance, to access the platform code from JavaScript in conjunction with js-ctypes.
profileDir The path to the current profile.
homeDir The path to the user's home directory.
desktopDir The path to the user's desktop directory (or, if it doesn't exist, the path to the user's home directory).
winAppDataDir The path to the user's application data directory.
winStartMenuProgsDir The path to the programs subdirectory in the user's start menu.
macUserLibDir The path to the user's Library directory.
macLocalApplicationsDir The path to the local Applications directory.

OS.Constants.libc

Constants for interacting with libc. Useful mostly for using js-ctypes to interact with the following platforms:

  • MacOS X;
  • Android;
  • Linux;
  • other variants of Unix.

OS.Constants.libc is available on all platforms, although some constants are not defined everywhere. Before using a constant, you should check that it is defined.

Error values

EACCES Permission denied
EAGAIN Resource temporarily unavailable
EBADF Bad file descriptor
EEXIST File exists
EFAULT Bad address
EFBIG File too large
EINVAL Invalid argument
EIO Input/output error
EISDIR Is a directory
ELOOP

(Not always available under Windows) Too many levels of symbolic links.

EMFILE Too many open files in the process
ENAMETOOLONG Name too long
ENFILE Too many open files on the system
ENOENT No such file or directory
ENOMEM Cannot allocate memory
ENOSPC No space on device
ENOTDIR Is not a directory
ENXIO Device no configured or does not support operation
EOPNOTSUPP (Not always available under Windows) Operation not supported.
EOVERFLOW (Not always available under Windows) Value too large to be stored in datatype.
EPERM Operation not permitted
ERANGE Result too large
ETIMEDOUT (Not always available under Windows) Operation timed out.
EWOULDBLOCK (Not always available under Windows) Operation would block.
EXDEV Cross-device link

Opening files

Unix access rights

Defined on all platforms but meaningful only on Unix.

S_IRWXU Current User can Read, Write, eXecute the file. Equivalent to S_IRUSR | S_IWUSR | S_IXUSR.
S_IRUSR Current User can Read the file.
S_IWUSR Current User can Write (modify) the file.
S_IXUSR Current User can eXecute the file.
S_IRWXG Current GRouP of the current user can Read, Write, eXecute the file. Equivalent to S_IRGRP | S_IWGRP | S_IXGRP.
S_IRGRP Current GRouP of the current user can Read the file.
S_IWGRP Current GRouP of the current user can Write (modify) the file.
S_IXGRP Current GRouP of the current user can eXecute the file.
S_IRWXO All Other users can Read, Write, eXecute the file. Equivalent to S_IROTH | S_IWOTH | S_IXOTH.
S_IROTH All Other users can Read the file.
S_IWOTH All Other users can Write (modify) the file.
S_IXOTH All Other users can eXecute the file.

Unix opening mode

O_APPEND Open the file for appending.
O_CREAT Create the file if it does not exist yet.
O_DIRECTORY (Linux only) Succeed only of the file is a directory.
O_EVTONLY Descriptor requested for event notifications only.
O_EXCL Raise an error if O_CREAT is set and the file exists.
O_EXLOCK Atomically obtain an exclusive lock.
O_LARGEFILE  
O_NOFOLLOW Do not follow symbolic links.
O_NONBLOCK Do not block on open or for data to become available.
O_RDONLY Open the file for read only.
O_RDWR Open the file for read and write.
O_RSYNC  
O_SHLOCK Atomically obtain a shared lock.
O_SYMLINK Allow opening of symbolic links.
O_SYNC (Linux only) Open for purely synchronous access.
O_TRUNC Truncate the file.
O_WRONLY Open the file for write only.

OS.Constants.Win

Constants for interacting with the Windows API. OS.Constants.Win is undefined on non-Windows platforms. Useful mostly in conjunction with js-ctypes.

(tbd)

Document Tags and Contributors

 Contributors to this page: marco-c, j4nu5, rnewman, Yoric
 Last updated by: marco-c,