Apache Mesos
lseek.hpp
Go to the documentation of this file.
1 // Licensed under the Apache License, Version 2.0 (the "License");
2 // you may not use this file except in compliance with the License.
3 // You may obtain a copy of the License at
4 //
5 // http://www.apache.org/licenses/LICENSE-2.0
6 //
7 // Unless required by applicable law or agreed to in writing, software
8 // distributed under the License is distributed on an "AS IS" BASIS,
9 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 // See the License for the specific language governing permissions and
11 // limitations under the License.
12 
13 #ifndef __STOUT_OS_LSEEK_HPP__
14 #define __STOUT_OS_LSEEK_HPP__
15 
16 #ifdef __WINDOWS__
17 #include <io.h>
18 #else
19 #include <unistd.h>
20 #endif
21 
22 #include <stout/error.hpp>
23 #include <stout/try.hpp>
24 
25 #include <stout/os/int_fd.hpp>
26 
27 namespace os {
28 
29 inline Try<off_t> lseek(int_fd fd, off_t offset, int whence)
30 {
31 #ifdef __WINDOWS__
32  off_t result = ::_lseek(fd.crt(), offset, whence);
33 #else
34  off_t result = ::lseek(fd, offset, whence);
35 #endif
36  if (result < 0) {
37  return ErrnoError();
38  }
39  return result;
40 }
41 
42 } // namespace os {
43 
44 #endif // __STOUT_OS_LSEEK_HPP__
Definition: try.hpp:34
Try< off_t > lseek(int_fd fd, off_t offset, int whence)
Definition: lseek.hpp:29
Definition: errorbase.hpp:49
int int_fd
Definition: int_fd.hpp:35