OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include <sys/stat.h> | |
6 #include <sys/types.h> | |
7 #include <unistd.h> | |
8 #include <cstring> | |
Mark Seaborn
2014/01/10 13:11:20
Nit: sort #includes within block
hidehiko
2014/01/15 03:50:44
This is sorted. According to the style guide, C sy
| |
9 | |
10 #include "base/logging.h" | |
11 #include "native_client/src/trusted/service_runtime/include/sys/stat.h" | |
12 | |
13 namespace nacl { | |
14 namespace nonsfi { | |
15 | |
16 void StatToNaClAbiStat( | |
17 const struct stat& host_stat, struct nacl_abi_stat* nacl_stat) { | |
18 // Some fields in host_stat, such as st_dev, group/other bits of mode and | |
19 // (a,m,c)timensec, are ignored to sync with the NaCl's original | |
20 // implementation. Please see also NaClAbiStatHostDescStatXlateCtor in | |
21 // native_client/src/trusted/desc/posix/nacl_desc.c. | |
22 std::memset(nacl_stat, 0, sizeof(*nacl_stat)); | |
23 nacl_stat->nacl_abi_st_dev = 0; | |
24 nacl_stat->nacl_abi_st_ino = host_stat.st_ino; | |
25 nacl_abi_mode_t mode; | |
26 switch (host_stat.st_mode & S_IFMT) { | |
27 case S_IFREG: | |
28 mode = NACL_ABI_S_IFREG; | |
29 break; | |
30 case S_IFDIR: | |
31 mode = NACL_ABI_S_IFDIR; | |
32 break; | |
33 case S_IFCHR: | |
34 mode = NACL_ABI_S_IFCHR; | |
35 break; | |
36 default: | |
37 LOG(WARNING) << "Unusual NaCl descriptor type: " | |
38 << (host_stat.st_mode & S_IFMT); | |
39 mode = NACL_ABI_S_UNSUP; | |
40 } | |
41 if (host_stat.st_mode & S_IRUSR) | |
42 mode |= NACL_ABI_S_IRUSR; | |
43 if (host_stat.st_mode & S_IWUSR) | |
44 mode |= NACL_ABI_S_IWUSR; | |
45 if (host_stat.st_mode & S_IXUSR) | |
46 mode |= NACL_ABI_S_IXUSR; | |
47 nacl_stat->nacl_abi_st_mode = mode; | |
48 nacl_stat->nacl_abi_st_nlink = host_stat.st_nlink; | |
49 nacl_stat->nacl_abi_st_uid = -1; // Not root | |
50 nacl_stat->nacl_abi_st_gid = -1; // Not wheel | |
51 nacl_stat->nacl_abi_st_rdev = 0; | |
52 nacl_stat->nacl_abi_st_size = host_stat.st_size; | |
53 nacl_stat->nacl_abi_st_blksize = 0; | |
54 nacl_stat->nacl_abi_st_blocks = 0; | |
55 nacl_stat->nacl_abi_st_atime = host_stat.st_atime; | |
56 nacl_stat->nacl_abi_st_mtime = host_stat.st_mtime; | |
57 nacl_stat->nacl_abi_st_ctime = host_stat.st_ctime; | |
58 } | |
59 | |
60 } // namespace nonsfi | |
61 } // namespace nacl | |
OLD | NEW |