Introduction
nacl_io is a utility library that provides implementations of standard C APIs such as POSIX I/O (stdio.h) and BSD sockets (sys/socket.h). Its primary function is to allow code that uses these standard APIs to be compiled and used in a Native Client module. The library is included as part of Native Client SDK and is implemented in on top of Pepper API.
Since Native Client modules cannot access the host machine’s file system directly, nacl_io provides several alternative filesystem types which can be used by the application. For example, the Chrome browser supports the which provides access to a protected area of the local file system. This filesystem can be accessed by an HTML page using JavaScript commands, and also by a Native Client module using the Pepper .
With nacl_io a Native Client application can mount an HTML5 filesystem and access it via standard POSIX I/O function such as fopen, fseek, fread, fwrite, and fclose, or their low level UNIX counterparts open, lseek,read, write and close. As well as the HTML5 file system, nacl_io provides several other file system types which are described in the table below:
| File System | Description |
|---|
| memfs | An in-memory file system |
| html5fs | An HTML5 local file system, which can be persistent or temporary |
| http | Maps files on a remote webserver into the local filesystem. |
| dev | A file system containing special files (e.g.: /dev/null) |
Using nacl_io
Using nacl_io is mostly just a matter of using the standard POSIX C library functions. However, there are some steps required to initialize the library and setup the filesystem mounts. In general the following steps will be needed to use nacl_io in a NaCl application:
Logging in nacl_io
Unlike most input/output for nacl_io, internal logging writes directly to the stderr stream of the NaCl process. It deliberately bypasses the standard library functions implemented in nacl_io to avoid circular calls to itself.
The nacl_io demo
Building and running the demo
The demo application launches a Native Client module that mounts three file systems and displays a set of controls that let you work with them: