Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 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 | #ifndef SERVICES_FILES_UTIL_H_ |
| 6 | #define SERVICES_FILES_UTIL_H_ |
| 7 | |
Viet-Trung Luu | 08e339a | 2015-10-10 01:03:09 -0700 | [diff] [blame] | 8 | #include "mojo/services/files/interfaces/types.mojom.h" |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 9 | |
| 10 | namespace mojo { |
| 11 | |
| 12 | class String; |
| 13 | |
| 14 | namespace files { |
| 15 | |
| 16 | // Validation functions (typically used to check arguments; they return |
John Grossman | 87fe514 | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 17 | // |Error::OK| if valid, else the standard/recommended error for the validation |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 18 | // error): |
| 19 | |
| 20 | // Checks if |path|, which must be non-null, is (looks like) a valid (relative) |
John Grossman | 87fe514 | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 21 | // path. (On failure, returns |Error::INVALID_ARGUMENT| if |path| is not UTF-8, |
| 22 | // or |Error::PERMISSION_DENIED| if it is not relative.) |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 23 | Error IsPathValid(const String& path); |
| 24 | |
| 25 | // Checks if |whence| is a valid (known) |Whence| value. (On failure, returns |
John Grossman | 87fe514 | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 26 | // |Error::UNIMPLEMENTED|.) |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 27 | Error IsWhenceValid(Whence whence); |
| 28 | |
| 29 | // Checks if |offset| is a valid file offset (from some point); this is |
| 30 | // implementation-dependent (typically checking if |offset| fits in an |off_t|). |
John Grossman | 87fe514 | 2015-10-02 10:11:43 -0700 | [diff] [blame] | 31 | // (On failure, returns |Error::OUT_OF_RANGE|.) |
Viet-Trung Luu | 2a39449 | 2015-03-04 08:03:20 -0800 | [diff] [blame] | 32 | Error IsOffsetValid(int64_t offset); |
| 33 | |
| 34 | // Conversion functions: |
| 35 | |
| 36 | // Converts a standard errno value (|E...|) to an |Error| value. |
| 37 | Error ErrnoToError(int errno_value); |
| 38 | |
| 39 | // Converts a |Whence| value to a standard whence value (|SEEK_...|). |
| 40 | int WhenceToStandardWhence(Whence whence); |
| 41 | |
| 42 | // Converts a |Timespec| to a |struct timespec|. If |in| is null, |out->tv_nsec| |
| 43 | // is set to |UTIME_OMIT|. |
| 44 | Error TimespecToStandardTimespec(const Timespec* in, struct timespec* out); |
| 45 | |
| 46 | // Converts a |TimespecOrNow| to a |struct timespec|. If |in| is null, |
| 47 | // |out->tv_nsec| is set to |UTIME_OMIT|; if |in->now| is set, |out->tv_nsec| is |
| 48 | // set to |UTIME_NOW|. |
| 49 | Error TimespecOrNowToStandardTimespec(const TimespecOrNow* in, |
| 50 | struct timespec* out); |
| 51 | |
| 52 | } // namespace files |
| 53 | } // namespace mojo |
| 54 | |
| 55 | #endif // SERVICES_FILES_UTIL_H_ |