Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Filesystem/posix_compat.h
9644 views
1
/*
2
This program is free software: you can redistribute it and/or modify
3
it under the terms of the GNU General Public License as published by
4
the Free Software Foundation, either version 3 of the License, or
5
(at your option) any later version.
6
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
11
12
You should have received a copy of the GNU General Public License
13
along with this program. If not, see <http://www.gnu.org/licenses/>.
14
*/
15
/*
16
compatibility with posix APIs using AP_Filesystem
17
*/
18
#pragma once
19
20
#include <sys/types.h>
21
#include <stdio.h>
22
#include <stddef.h>
23
#include <stdbool.h>
24
#include <stdint.h>
25
26
#ifdef __cplusplus
27
extern "C" {
28
#endif
29
30
/*
31
these are here to allow lua to build on HAL_ChibiOS
32
*/
33
34
typedef struct apfs_file {
35
int fd;
36
bool error;
37
bool eof;
38
int16_t unget;
39
char *tmpfile_name;
40
} APFS_FILE;
41
42
APFS_FILE *apfs_fopen(const char *pathname, const char *mode);
43
int apfs_fprintf(APFS_FILE *stream, const char *format, ...);
44
int apfs_fflush(APFS_FILE *stream);
45
size_t apfs_fread(void *ptr, size_t size, size_t nmemb, APFS_FILE *stream);
46
size_t apfs_fwrite(const void *ptr, size_t size, size_t nmemb, APFS_FILE *stream);
47
int apfs_fputs(const char *s, APFS_FILE *stream);
48
char *apfs_fgets(char *s, int size, APFS_FILE *stream);
49
void apfs_clearerr(APFS_FILE *stream);
50
int apfs_fseek(APFS_FILE *stream, long offset, int whence);
51
int apfs_ferror(APFS_FILE *stream);
52
int apfs_fclose(APFS_FILE *stream);
53
APFS_FILE *apfs_tmpfile(void);
54
int apfs_getc(APFS_FILE *stream);
55
int apfs_ungetc(int c, APFS_FILE *stream);
56
int apfs_feof(APFS_FILE *stream);
57
long apfs_ftell(APFS_FILE *stream);
58
APFS_FILE *apfs_freopen(const char *pathname, const char *mode, APFS_FILE *stream);
59
int apfs_remove(const char *pathname);
60
int apfs_rename(const char *oldpath, const char *newpath);
61
62
#undef stdin
63
#undef stdout
64
#undef stderr
65
#define stdin ((APFS_FILE*)1)
66
#define stdout ((APFS_FILE*)2)
67
#define stderr ((APFS_FILE*)3)
68
69
#undef BUFSIZ
70
#define BUFSIZ 256
71
#define EOF (-1)
72
73
#ifndef SEEK_SET
74
#define SEEK_SET 0
75
#define SEEK_CUR 1
76
#define SEEK_END 2
77
#endif
78
79
#define FILE APFS_FILE
80
81
#ifndef __cplusplus
82
/*
83
only redefine posix functions for C code (eg. lua).
84
for C++ use the AP_Filsystem APIs
85
*/
86
87
// on some platforms, some functions are implemented with macros. undefine
88
// those which have caused macro redefinition warnings in the past.
89
#undef clearerr
90
#undef ferror
91
#undef feof
92
#undef getc
93
94
#define fopen(p,m) apfs_fopen(p,m)
95
#define fprintf(stream, format, args...) apfs_fprintf(stream, format, ##args)
96
#define fflush(s) apfs_fflush(s)
97
#define fread(ptr,size,nmemb, stream) apfs_fread(ptr, size, nmemb, stream)
98
#define fwrite(ptr, size, nmemb, stream) apfs_fwrite(ptr, size, nmemb, stream)
99
#define fputs(s, stream) apfs_fputs(s, stream)
100
#define fgets(s, size, stream) apfs_fgets(s, size, stream)
101
#define clearerr(stream) apfs_clearerr(stream)
102
#define fseek(stream, offset, whence) apfs_fseek(stream, offset, whence)
103
#define ferror(stream) apfs_ferror(stream)
104
#define fclose(stream) apfs_fclose(stream)
105
#define tmpfile() apfs_tmpfile()
106
#define getc(stream) apfs_getc(stream)
107
#define ungetc(c, stream) apfs_ungetc(c, stream)
108
#define feof(stream) apfs_ferror(stream)
109
#define ftell(stream) apfs_ftell(stream)
110
#define freopen(pathname, mode, stream) apfs_freopen(pathname, mode, stream)
111
#define rename(oldpath, newpath) apfs_rename(oldpath, newpath)
112
#if !defined(__APPLE__)
113
#define remove(pathname) apfs_remove(pathname)
114
int sprintf(char *str, const char *format, ...);
115
#endif
116
#endif // __cplusplus
117
118
#ifdef __cplusplus
119
}
120
#endif
121
122