| Index: services/file_manager/util.cc
|
| diff --git a/services/file_manager/util.cc b/services/file_manager/util.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..c4192145e8a21a506a1eb26e5b082bf13b47be3e
|
| --- /dev/null
|
| +++ b/services/file_manager/util.cc
|
| @@ -0,0 +1,59 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "services/file_manager/util.h"
|
| +
|
| +#include <errno.h>
|
| +
|
| +#include "base/logging.h"
|
| +#include "base/strings/string_util.h"
|
| +#include "mojo/public/cpp/bindings/string.h"
|
| +
|
| +namespace mojo {
|
| +namespace files {
|
| +
|
| +Error IsPathValid(const String& path) {
|
| + DCHECK(!path.is_null());
|
| + if (!base::IsStringUTF8(path.get()))
|
| + return ERROR_INVALID_ARGUMENT;
|
| + if (path.size() > 0 && path[0] == '/')
|
| + return ERROR_PERMISSION_DENIED;
|
| + return ERROR_OK;
|
| +}
|
| +
|
| +Error IsWhenceValid(Whence whence) {
|
| + return (whence == WHENCE_FROM_CURRENT || whence == WHENCE_FROM_START ||
|
| + whence == WHENCE_FROM_END)
|
| + ? ERROR_OK
|
| + : ERROR_UNIMPLEMENTED;
|
| +}
|
| +
|
| +Error IsOffsetValid(int64_t offset) {
|
| + return (offset >= std::numeric_limits<off_t>::min() &&
|
| + offset <= std::numeric_limits<off_t>::max())
|
| + ? ERROR_OK
|
| + : ERROR_OUT_OF_RANGE;
|
| +}
|
| +
|
| +Error ErrnoToError(int errno_value) {
|
| + // TODO(vtl)
|
| + return ERROR_UNKNOWN;
|
| +}
|
| +
|
| +int WhenceToStandardWhence(Whence whence) {
|
| + DCHECK_EQ(IsWhenceValid(whence), ERROR_OK);
|
| + switch (whence) {
|
| + case WHENCE_FROM_CURRENT:
|
| + return SEEK_CUR;
|
| + case WHENCE_FROM_START:
|
| + return SEEK_SET;
|
| + case WHENCE_FROM_END:
|
| + return SEEK_END;
|
| + }
|
| + NOTREACHED();
|
| + return 0;
|
| +}
|
| +
|
| +} // namespace files
|
| +} // namespace mojo
|
|
|