Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / native_client / src / shared / platform / nacl_host_dir.h
1 /*
2  * Copyright 2008 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 /*
8  * NaCl Service Runtime.  Host Directory descriptor / Handle abstraction.
9  */
10
11 #ifndef NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_NACL_HOST_DIR_H__
12 #define NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_NACL_HOST_DIR_H__
13
14 #include <errno.h>
15
16 #include "native_client/src/include/portability.h"
17
18 #include "native_client/src/include/nacl_base.h"
19
20 #if NACL_LINUX
21 # include "native_client/src/shared/platform/linux/nacl_host_dir_types.h"
22 #elif NACL_OSX
23 # include "native_client/src/shared/platform/osx/nacl_host_dir_types.h"
24 #elif NACL_WINDOWS
25 # include "native_client/src/shared/platform/win/nacl_host_dir_types.h"
26 #endif
27
28 EXTERN_C_BEGIN
29
30 struct nacl_abi_stat;
31
32 /* TODO: this is also declared in nacl_host_desc.h */
33 extern int NaClXlateErrno(int errnum);
34
35 /*
36  * Constructor for a NaClHostDir object.
37  *
38  * path should be a host-OS pathname to a directory.  No validation is
39  * done.
40  *
41  * Uses raw syscall return convention, so returns 0 for success and
42  * non-zero (usually -NACL_ABI_EINVAL) for failure.
43  *
44  * We cannot return the platform descriptor/handle and be consistent
45  * with a largely POSIX-ish interface, since e.g. windows handles may
46  * be negative and might look like negative errno returns.
47  *
48  * Underlying function: opendir(Mac) / open(Linux) / FindFirstFile(Windows)
49  */
50 extern int NaClHostDirOpen(struct NaClHostDir *d,
51                            char               *path);
52
53 /*
54  * Read data from an opened directory into a memory buffer.
55  *
56  * Underlying function: readdir(Mac) / getdents(Linux) / FindNextFile(Windows)
57  */
58 extern ssize_t NaClHostDirGetdents(struct NaClHostDir *d,
59                                    void               *buf,
60                                    size_t             len);
61
62 /*
63  * Rewind the NaClHostDir object such that future calls
64  * to NaClHostDirGetdents read from the beginning of the
65  * directory as if the object was newly created.
66  *
67  * Underlying functions: rewinddir(Mac) / lseek(Linux) / FindFirstFile(Windows)
68  */
69 extern int NaClHostDirRewind(struct NaClHostDir *d);
70
71 /*
72  * Dtor for the NaClHostDir object. Close the directory.
73  *
74  * Underlying function: closedir(Mac) / close(Linux) / FindClose(Windows)
75  */
76 extern int NaClHostDirClose(struct NaClHostDir  *d);
77
78 EXTERN_C_END
79
80 #endif  /* NATIVE_CLIENT_SRC_TRUSTED_PLATFORM_NACL_HOST_DIR_H__ */