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.
Unix opening mode
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)