Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / native_client / src / untrusted / irt / irt_filename.c
1 /*
2  * Copyright (c) 2011 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 #include "native_client/src/untrusted/irt/irt.h"
8 #include "native_client/src/untrusted/irt/irt_dev.h"
9 #include "native_client/src/untrusted/nacl/syscall_bindings_trampoline.h"
10
11 static int nacl_irt_open(const char *pathname, int oflag, mode_t cmode,
12                          int *newfd) {
13   int rv = NACL_GC_WRAP_SYSCALL(NACL_SYSCALL(open)(pathname, oflag, cmode));
14   if (rv < 0)
15     return -rv;
16   *newfd = rv;
17   return 0;
18 }
19
20 static int nacl_irt_stat(const char *pathname, struct stat *st) {
21   return -NACL_SYSCALL(stat)(pathname, st);
22 }
23
24 static int nacl_irt_mkdir(const char *pathname, mode_t mode) {
25   return -NACL_SYSCALL(mkdir)(pathname, mode);
26 }
27
28 static int nacl_irt_rmdir(const char *pathname) {
29   return -NACL_SYSCALL(rmdir)(pathname);
30 }
31
32 static int nacl_irt_chdir(const char *pathname) {
33   return -NACL_SYSCALL(chdir)(pathname);
34 }
35
36 static int nacl_irt_getcwd(char *pathname, size_t len) {
37   return -NACL_SYSCALL(getcwd)(pathname, len);
38 }
39
40 static int nacl_irt_unlink(const char *pathname) {
41   return -NACL_SYSCALL(unlink)(pathname);
42 }
43
44 static int nacl_irt_truncate(const char *pathname, off_t length) {
45   return -NACL_SYSCALL(truncate)(pathname, &length);
46 }
47
48 static int nacl_irt_lstat(const char *pathname, struct stat *st) {
49   return -NACL_SYSCALL(lstat)(pathname, st);
50 }
51
52 static int nacl_irt_link(const char *oldpath, const char *newpath) {
53   return -NACL_SYSCALL(link)(oldpath, newpath);
54 }
55
56 static int nacl_irt_rename(const char *oldpath, const char *newpath) {
57   return -NACL_SYSCALL(rename)(oldpath, newpath);
58 }
59
60 static int nacl_irt_symlink(const char *oldpath, const char *newpath) {
61   return -NACL_SYSCALL(symlink)(oldpath, newpath);
62 }
63
64 static int nacl_irt_chmod(const char *path, mode_t mode) {
65   return -NACL_SYSCALL(chmod)(path, mode);
66 }
67
68 static int nacl_irt_access(const char *path, int amode) {
69   return -NACL_SYSCALL(access)(path, amode);
70 }
71
72 static int nacl_irt_readlink(const char *path, char *buf, size_t bufsize,
73                              size_t *nread) {
74   int rv = NACL_SYSCALL(readlink)(path, buf, bufsize);
75   if (rv < 0)
76     return -rv;
77   *nread = rv;
78   return 0;
79 }
80
81 static int nacl_irt_utimes(const char *filename, const struct timeval *times) {
82   return -NACL_SYSCALL(utimes)(filename, times);
83 }
84
85 const struct nacl_irt_filename nacl_irt_filename = {
86   nacl_irt_open,
87   nacl_irt_stat,
88 };
89
90 const struct nacl_irt_dev_filename_v0_2 nacl_irt_dev_filename_v0_2 = {
91   nacl_irt_open,
92   nacl_irt_stat,
93   nacl_irt_mkdir,
94   nacl_irt_rmdir,
95   nacl_irt_chdir,
96   nacl_irt_getcwd,
97   nacl_irt_unlink,
98 };
99
100 const struct nacl_irt_dev_filename nacl_irt_dev_filename = {
101   nacl_irt_open,
102   nacl_irt_stat,
103   nacl_irt_mkdir,
104   nacl_irt_rmdir,
105   nacl_irt_chdir,
106   nacl_irt_getcwd,
107   nacl_irt_unlink,
108   nacl_irt_truncate,
109   nacl_irt_lstat,
110   nacl_irt_link,
111   nacl_irt_rename,
112   nacl_irt_symlink,
113   nacl_irt_chmod,
114   nacl_irt_access,
115   nacl_irt_readlink,
116   nacl_irt_utimes,
117 };