OLD | NEW |
(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 "services/file_manager/util.h" |
| 6 |
| 7 #include <errno.h> |
| 8 |
| 9 #include "base/logging.h" |
| 10 #include "base/strings/string_util.h" |
| 11 #include "mojo/public/cpp/bindings/string.h" |
| 12 |
| 13 namespace mojo { |
| 14 namespace files { |
| 15 |
| 16 Error IsPathValid(const String& path) { |
| 17 DCHECK(!path.is_null()); |
| 18 if (!base::IsStringUTF8(path.get())) |
| 19 return ERROR_INVALID_ARGUMENT; |
| 20 if (path.size() > 0 && path[0] == '/') |
| 21 return ERROR_PERMISSION_DENIED; |
| 22 return ERROR_OK; |
| 23 } |
| 24 |
| 25 Error IsWhenceValid(Whence whence) { |
| 26 return (whence == WHENCE_FROM_CURRENT || whence == WHENCE_FROM_START || |
| 27 whence == WHENCE_FROM_END) |
| 28 ? ERROR_OK |
| 29 : ERROR_UNIMPLEMENTED; |
| 30 } |
| 31 |
| 32 Error IsOffsetValid(int64_t offset) { |
| 33 return (offset >= std::numeric_limits<off_t>::min() && |
| 34 offset <= std::numeric_limits<off_t>::max()) |
| 35 ? ERROR_OK |
| 36 : ERROR_OUT_OF_RANGE; |
| 37 } |
| 38 |
| 39 Error ErrnoToError(int errno_value) { |
| 40 // TODO(vtl) |
| 41 return ERROR_UNKNOWN; |
| 42 } |
| 43 |
| 44 int WhenceToStandardWhence(Whence whence) { |
| 45 DCHECK_EQ(IsWhenceValid(whence), ERROR_OK); |
| 46 switch (whence) { |
| 47 case WHENCE_FROM_CURRENT: |
| 48 return SEEK_CUR; |
| 49 case WHENCE_FROM_START: |
| 50 return SEEK_SET; |
| 51 case WHENCE_FROM_END: |
| 52 return SEEK_END; |
| 53 } |
| 54 NOTREACHED(); |
| 55 return 0; |
| 56 } |
| 57 |
| 58 } // namespace files |
| 59 } // namespace mojo |
OLD | NEW |