mbed-drivers
FileHandle.h
1 /*
2  * Copyright (c) 2006-2016, ARM Limited, All Rights Reserved
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may
6  * not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #ifndef MBED_FILEHANDLE_H
18 #define MBED_FILEHANDLE_H
19 
20 typedef int FILEHANDLE;
21 
22 #include <stdio.h>
23 
24 #if defined(__ARMCC_VERSION) || defined(__ICCARM__)
25 typedef int ssize_t;
26 typedef long off_t;
27 
28 #else
29 # include <sys/types.h>
30 #endif
31 
32 namespace mbed {
33 
43 class FileHandle {
44 
45 public:
54  virtual ssize_t write(const void* buffer, size_t length) = 0;
55 
61  virtual int close() = 0;
62 
72  virtual ssize_t read(void* buffer, size_t length) = 0;
73 
81  virtual int isatty() = 0;
82 
93  virtual off_t lseek(off_t offset, int whence) = 0;
94 
102  virtual int fsync() = 0;
103 
104  virtual off_t flen() {
105  /* remember our current position */
106  off_t pos = lseek(0, SEEK_CUR);
107  if(pos == -1) return -1;
108  /* seek to the end to get the file length */
109  off_t res = lseek(0, SEEK_END);
110  /* return to our old position */
111  lseek(pos, SEEK_SET);
112  return res;
113  }
114 
115  virtual ~FileHandle();
116 };
117 
118 } // namespace mbed
119 
120 #endif
Definition: FileHandle.h:43
virtual ssize_t read(void *buffer, size_t length)=0
virtual int fsync()=0
virtual int close()=0
virtual ssize_t write(const void *buffer, size_t length)=0
virtual off_t lseek(off_t offset, int whence)=0
Definition: BusIn.cpp:19
virtual int isatty()=0