Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(239)

Side by Side Diff: components/filesystem/util.cc

Issue 1147083002: mandoline: Fork the files service from the mojo repository. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: I think the problem was in the mandoline build.gn Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/filesystem/util.h ('k') | mandoline/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 "components/filesystem/util.h"
6
7 #include <errno.h>
8 #include <fcntl.h>
9 #include <sys/stat.h>
10 #include <time.h>
11
12 #include <limits>
13
14 #include "base/logging.h"
15 #include "base/strings/string_util.h"
16 #include "mojo/public/cpp/bindings/string.h"
17
18 namespace mojo {
19 namespace files {
20
21 Error IsPathValid(const String& path) {
22 DCHECK(!path.is_null());
23 if (!base::IsStringUTF8(path.get()))
24 return ERROR_INVALID_ARGUMENT;
25 if (path.size() > 0 && path[0] == '/')
26 return ERROR_PERMISSION_DENIED;
27 return ERROR_OK;
28 }
29
30 Error IsWhenceValid(Whence whence) {
31 return (whence == WHENCE_FROM_CURRENT || whence == WHENCE_FROM_START ||
32 whence == WHENCE_FROM_END)
33 ? ERROR_OK
34 : ERROR_UNIMPLEMENTED;
35 }
36
37 Error IsOffsetValid(int64_t offset) {
38 return (offset >= std::numeric_limits<off_t>::min() &&
39 offset <= std::numeric_limits<off_t>::max())
40 ? ERROR_OK
41 : ERROR_OUT_OF_RANGE;
42 }
43
44 Error ErrnoToError(int errno_value) {
45 // TODO(vtl)
46 return ERROR_UNKNOWN;
47 }
48
49 int WhenceToStandardWhence(Whence whence) {
50 DCHECK_EQ(IsWhenceValid(whence), ERROR_OK);
51 switch (whence) {
52 case WHENCE_FROM_CURRENT:
53 return SEEK_CUR;
54 case WHENCE_FROM_START:
55 return SEEK_SET;
56 case WHENCE_FROM_END:
57 return SEEK_END;
58 }
59 NOTREACHED();
60 return 0;
61 }
62
63 Error TimespecToStandardTimespec(const Timespec* in, struct timespec* out) {
64 if (!in) {
65 out->tv_sec = 0;
66 out->tv_nsec = UTIME_OMIT;
67 return ERROR_OK;
68 }
69
70 static_assert(sizeof(int64_t) >= sizeof(time_t), "whoa, time_t is huge");
71 if (in->seconds < std::numeric_limits<time_t>::min() ||
72 in->seconds > std::numeric_limits<time_t>::max())
73 return ERROR_OUT_OF_RANGE;
74
75 if (in->nanoseconds < 0 || in->nanoseconds >= 1000000000)
76 return ERROR_INVALID_ARGUMENT;
77
78 out->tv_sec = static_cast<time_t>(in->seconds);
79 out->tv_nsec = static_cast<long>(in->nanoseconds);
80 return ERROR_OK;
81 }
82
83 Error TimespecOrNowToStandardTimespec(const TimespecOrNow* in,
84 struct timespec* out) {
85 if (!in) {
86 out->tv_sec = 0;
87 out->tv_nsec = UTIME_OMIT;
88 return ERROR_OK;
89 }
90
91 if (in->now) {
92 if (!in->timespec.is_null())
93 return ERROR_INVALID_ARGUMENT;
94 out->tv_sec = 0;
95 out->tv_nsec = UTIME_NOW;
96 return ERROR_OK;
97 }
98
99 return TimespecToStandardTimespec(in->timespec.get(), out);
100 }
101
102 } // namespace files
103 } // namespace mojo
OLDNEW
« no previous file with comments | « components/filesystem/util.h ('k') | mandoline/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698