CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_Filesystem/posix_compat.h
Views: 1798
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
#define fopen(p,m) apfs_fopen(p,m)
87
#define fprintf(stream, format, args...) apfs_fprintf(stream, format, ##args)
88
#define fflush(s) apfs_fflush(s)
89
#define fread(ptr,size,nmemb, stream) apfs_fread(ptr, size, nmemb, stream)
90
#define fwrite(ptr, size, nmemb, stream) apfs_fwrite(ptr, size, nmemb, stream)
91
#define fputs(s, stream) apfs_fputs(s, stream)
92
#define fgets(s, size, stream) apfs_fgets(s, size, stream)
93
#define clearerr(stream) apfs_clearerr(stream)
94
#define fseek(stream, offset, whence) apfs_fseek(stream, offset, whence)
95
#define ferror(stream) apfs_ferror(stream)
96
#define fclose(stream) apfs_fclose(stream)
97
#define tmpfile() apfs_tmpfile()
98
#undef getc
99
#define getc(stream) apfs_getc(stream)
100
#define ungetc(c, stream) apfs_ungetc(c, stream)
101
#define feof(stream) apfs_ferror(stream)
102
#define ftell(stream) apfs_ftell(stream)
103
#define freopen(pathname, mode, stream) apfs_freopen(pathname, mode, stream)
104
#define rename(oldpath, newpath) apfs_rename(oldpath, newpath)
105
#if !defined(__APPLE__)
106
#define remove(pathname) apfs_remove(pathname)
107
int sprintf(char *str, const char *format, ...);
108
#endif
109
#endif // __cplusplus
110
111
#ifdef __cplusplus
112
}
113
#endif
114
115