Path: blob/master/libraries/AP_Filesystem/posix_compat.h
9644 views
/*1This program is free software: you can redistribute it and/or modify2it under the terms of the GNU General Public License as published by3the Free Software Foundation, either version 3 of the License, or4(at your option) any later version.56This program is distributed in the hope that it will be useful,7but WITHOUT ANY WARRANTY; without even the implied warranty of8MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the9GNU General Public License for more details.1011You should have received a copy of the GNU General Public License12along with this program. If not, see <http://www.gnu.org/licenses/>.13*/14/*15compatibility with posix APIs using AP_Filesystem16*/17#pragma once1819#include <sys/types.h>20#include <stdio.h>21#include <stddef.h>22#include <stdbool.h>23#include <stdint.h>2425#ifdef __cplusplus26extern "C" {27#endif2829/*30these are here to allow lua to build on HAL_ChibiOS31*/3233typedef struct apfs_file {34int fd;35bool error;36bool eof;37int16_t unget;38char *tmpfile_name;39} APFS_FILE;4041APFS_FILE *apfs_fopen(const char *pathname, const char *mode);42int apfs_fprintf(APFS_FILE *stream, const char *format, ...);43int apfs_fflush(APFS_FILE *stream);44size_t apfs_fread(void *ptr, size_t size, size_t nmemb, APFS_FILE *stream);45size_t apfs_fwrite(const void *ptr, size_t size, size_t nmemb, APFS_FILE *stream);46int apfs_fputs(const char *s, APFS_FILE *stream);47char *apfs_fgets(char *s, int size, APFS_FILE *stream);48void apfs_clearerr(APFS_FILE *stream);49int apfs_fseek(APFS_FILE *stream, long offset, int whence);50int apfs_ferror(APFS_FILE *stream);51int apfs_fclose(APFS_FILE *stream);52APFS_FILE *apfs_tmpfile(void);53int apfs_getc(APFS_FILE *stream);54int apfs_ungetc(int c, APFS_FILE *stream);55int apfs_feof(APFS_FILE *stream);56long apfs_ftell(APFS_FILE *stream);57APFS_FILE *apfs_freopen(const char *pathname, const char *mode, APFS_FILE *stream);58int apfs_remove(const char *pathname);59int apfs_rename(const char *oldpath, const char *newpath);6061#undef stdin62#undef stdout63#undef stderr64#define stdin ((APFS_FILE*)1)65#define stdout ((APFS_FILE*)2)66#define stderr ((APFS_FILE*)3)6768#undef BUFSIZ69#define BUFSIZ 25670#define EOF (-1)7172#ifndef SEEK_SET73#define SEEK_SET 074#define SEEK_CUR 175#define SEEK_END 276#endif7778#define FILE APFS_FILE7980#ifndef __cplusplus81/*82only redefine posix functions for C code (eg. lua).83for C++ use the AP_Filsystem APIs84*/8586// on some platforms, some functions are implemented with macros. undefine87// those which have caused macro redefinition warnings in the past.88#undef clearerr89#undef ferror90#undef feof91#undef getc9293#define fopen(p,m) apfs_fopen(p,m)94#define fprintf(stream, format, args...) apfs_fprintf(stream, format, ##args)95#define fflush(s) apfs_fflush(s)96#define fread(ptr,size,nmemb, stream) apfs_fread(ptr, size, nmemb, stream)97#define fwrite(ptr, size, nmemb, stream) apfs_fwrite(ptr, size, nmemb, stream)98#define fputs(s, stream) apfs_fputs(s, stream)99#define fgets(s, size, stream) apfs_fgets(s, size, stream)100#define clearerr(stream) apfs_clearerr(stream)101#define fseek(stream, offset, whence) apfs_fseek(stream, offset, whence)102#define ferror(stream) apfs_ferror(stream)103#define fclose(stream) apfs_fclose(stream)104#define tmpfile() apfs_tmpfile()105#define getc(stream) apfs_getc(stream)106#define ungetc(c, stream) apfs_ungetc(c, stream)107#define feof(stream) apfs_ferror(stream)108#define ftell(stream) apfs_ftell(stream)109#define freopen(pathname, mode, stream) apfs_freopen(pathname, mode, stream)110#define rename(oldpath, newpath) apfs_rename(oldpath, newpath)111#if !defined(__APPLE__)112#define remove(pathname) apfs_remove(pathname)113int sprintf(char *str, const char *format, ...);114#endif115#endif // __cplusplus116117#ifdef __cplusplus118}119#endif120121122