diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/posix.c b/libraries/AP_HAL_ChibiOS/hwdef/common/posix.c
index 5a3ca038eb..a5f842ae21 100644
--- a/libraries/AP_HAL_ChibiOS/hwdef/common/posix.c
+++ b/libraries/AP_HAL_ChibiOS/hwdef/common/posix.c
@@ -247,6 +247,9 @@ fgetc(FILE *stream)
return (c);
}
+int getc(FILE *fp) {
+ return (fgetc (fp));
+}
/// @brief Put a byte to TTY device or FatFs file stream
/// open() or fopen() sets stream->put = fatfs_outc() for FatFs functions
/// See fdevopen() sets stream->put get for TTY devices
@@ -298,6 +301,10 @@ fputc(int c, FILE *stream)
}
}
+void clearerr(FILE *stream)
+{
+ stream->flags = 0;
+}
///@brief functions normally defined as macros
@@ -423,6 +430,23 @@ fgets(char *str, int size, FILE *stream)
return(str);
}
+
+/** char *gets(p) -- get line from stdin */
+
+char *
+gets (char *p)
+{
+ char *s;
+ int n;
+
+ s = fgets (p, MAXLN, stdin);
+ if (s == 0)
+ return (0);
+ n = strlen (p);
+ if (n && p[n - 1] == '\n')
+ p[n - 1] = 0;
+ return (s);
+}
/// @brief put a string to stdout
/// See fdevopen() sets stream->put get for TTY devices
///
@@ -774,7 +798,7 @@ FILE *fopen(const char *path, const char *mode)
/// @return count on sucess.
/// @return 0 or < size on error with errno set.
-size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
+size_t __wrap_fread(void *ptr, size_t size, size_t nmemb, FILE *stream)
{
size_t count = size * nmemb;
int fn = fileno(stream);
@@ -1199,7 +1223,14 @@ ssize_t write(int fd, const void *buf, size_t count)
return ((ssize_t) size);
}
-
+FILE * __wrap_freopen ( const char * filename, const char * mode, FILE * stream )
+{
+ int ret = close(stream);
+ if (ret < 0) {
+ return NULL;
+ }
+ return fopen(filename, mode);
+}
/// @brief POSIX close a file stream.
///
/// - man page flose (3).
@@ -1208,8 +1239,8 @@ ssize_t write(int fd, const void *buf, size_t count)
/// @return 0 on sucess.
/// @return -1 on error witrh errno set.
-/*
-int fclose(FILE *stream)
+
+int __wrap_fclose(FILE *stream)
{
int fn = fileno(stream);
if(fn < 0)
@@ -1217,7 +1248,6 @@ int fclose(FILE *stream)
return( close(fn) );
}
-*/
// =============================================
// =============================================
/// - POSIX file information functions
@@ -1679,6 +1709,19 @@ int unlink(const char *pathname)
return(0);
}
+
+int remove(const char *pathname)
+{
+ errno = 0;
+ int res = f_unlink(pathname);
+ if(res != FR_OK)
+ {
+ errno = fatfs_to_errno(res);
+ return(-1);
+ }
+ return(0);
+}
+
// =============================================
// =============================================
/// - POSIX - directory scanning functions
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/posix.h b/libraries/AP_HAL_ChibiOS/hwdef/common/posix.h
index 71a988fad5..6e61876184 100644
--- a/libraries/AP_HAL_ChibiOS/hwdef/common/posix.h
+++ b/libraries/AP_HAL_ChibiOS/hwdef/common/posix.h
@@ -35,6 +35,10 @@ along with this program. If not, see .
#include
#include
#include
+
+#define MAXLN 128
+#define ISSPACE " \t\n\r\f\v"
+
///@brief make sure we use our strerror_r function
#ifdef __cplusplus
@@ -46,6 +50,8 @@ extern "C" {
/// - Using these makes code portable accross many acrchitectures
//typedef uint32_t blkcnt_t; /*< blkcnt_t for this architecture */
//typedef uint32_t blksize_t; /*< blksize_t for this architecture */
+typedef int32_t off_t;
+typedef off_t fpos_t;
extern int errno;
// =============================================
@@ -297,6 +303,7 @@ extern FILE *__iob[MAX_FILES];
int isatty ( int fileno );
int fgetc ( FILE *stream );
int fputc ( int c , FILE *stream );
+void clearerr(FILE *stream);
#ifndef IO_MACROS
int getchar ( void );
int putchar ( int c );
@@ -321,7 +328,7 @@ int close ( int fileno );
int fileno ( FILE *stream );
FILE *fileno_to_stream ( int fileno );
FILE *fopen ( const char *path , const char *mode );
-size_t fread ( void *ptr , size_t size , size_t nmemb , FILE *stream );
+size_t __wrap_fread ( void *ptr , size_t size , size_t nmemb , FILE *stream );
int ftruncate ( int fd , off_t length );
size_t fwrite ( const void *ptr , size_t size , size_t nmemb , FILE *stream );
int open (const char *pathname, int flags);
@@ -331,7 +338,10 @@ int syncfs(int fd);
int fsync ( int fd );
int truncate ( const char *path , off_t length );
ssize_t write ( int fd , const void *buf , size_t count );
-//int fclose ( FILE *stream );
+int __wrap_fclose ( FILE *stream );
+FILE * __wrap_freopen ( const char * filename, const char * mode, FILE * stream );
+int getc(FILE *fp);
+char *gets (char *p);
//void dump_stat ( struct stat *sp );
#if 0
@@ -356,6 +366,7 @@ int mkdir ( const char *pathname , mode_t mode );
int rename ( const char *oldpath , const char *newpath );
int rmdir ( const char *pathname );
int unlink ( const char *pathname );
+int remove(const char *pathname);
int closedir ( DIR *dirp );
DIR *opendir ( const char *pathdir );
struct dirent *readdir ( DIR *dirp );
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c b/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c
index ede70f9794..0abc5c1293 100644
--- a/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c
+++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.c
@@ -112,9 +112,12 @@ int printf(const char *fmt, ...)
return done;
}
-#define MAXLN 128
-#define ISSPACE " \t\n\r\f\v"
-
+//just a stub
+int
+scanf (const char *fmt, ...)
+{
+ return 0;
+}
/*
* sscanf(buf,fmt,va_alist)
*/
@@ -311,3 +314,32 @@ vsscanf (const char *buf, const char *s, va_list ap)
}
return (count);
}
+
+/*
+ * fscanf(stream,fmt,va_alist)
+ */
+int fscanf (FILE *stream, const char *fmt, ...)
+{
+ int count;
+ va_list ap;
+
+ va_start (ap, fmt);
+ count = vfscanf (stream, fmt, ap);
+ va_end (ap);
+ return (count);
+}
+
+/*
+ * vfscanf(stream,fmt,ap)
+ */
+static int vfscanf (FILE *stream, const char *fmt, va_list ap)
+{
+ int count;
+ char buf[MAXLN + 1];
+
+ if (fgets (buf, MAXLN, stream) == 0) {
+ return (-1);
+ }
+ count = vsscanf (buf, fmt, ap);
+ return (count);
+}
diff --git a/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.h b/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.h
index f2b40131fc..352fcd8123 100644
--- a/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.h
+++ b/libraries/AP_HAL_ChibiOS/hwdef/common/stdio.h
@@ -27,8 +27,9 @@ int vasprintf(char **strp, const char *fmt, va_list ap);
int asprintf(char **strp, const char *fmt, ...);
int vprintf(const char *fmt, va_list arg);
int printf(const char *fmt, ...);
+int fscanf ( FILE * stream, const char * format, ... );
-
+int scanf (const char *fmt, ...);
int sscanf (const char *buf, const char *fmt, ...);
int vsscanf (const char *buf, const char *s, va_list ap);
void *malloc(size_t size);