diff options
Diffstat (limited to 'apps/interpreters')
-rw-r--r-- | apps/interpreters/bas/Kconfig | 7 | ||||
-rw-r--r-- | apps/interpreters/bas/fs.c | 49 |
2 files changed, 54 insertions, 2 deletions
diff --git a/apps/interpreters/bas/Kconfig b/apps/interpreters/bas/Kconfig index 823d13ff7..275ac6350 100644 --- a/apps/interpreters/bas/Kconfig +++ b/apps/interpreters/bas/Kconfig @@ -42,6 +42,13 @@ config INTERPRETER_BAS_HAVE_ENVIRON ---help--- NuttX does not support the environ variable +config INTERPRETER_BAS_HAVE_FSTAT + bool + default n + depends on EXPERIMENTAL + ---help--- + NuttX does not support the fstat() function + config INTERPRETER_BAS_HAVE_SYSCFG bool default n diff --git a/apps/interpreters/bas/fs.c b/apps/interpreters/bas/fs.c index 56bee2dae..ad67982de 100644 --- a/apps/interpreters/bas/fs.c +++ b/apps/interpreters/bas/fs.c @@ -66,16 +66,22 @@ #include <sys/time.h> #include <sys/types.h> -#include <sys/stat.h> + +#ifdef CONFIG_INTERPRETER_BAS_HAVE_FSTAT +# include <sys/stat.h> +#endif + #include <assert.h> #include <errno.h> #include <fcntl.h> + #ifdef HAVE_GETTEXT # include <libintl.h> # define _(String) gettext(String) #else # define _(String) String #endif + #include <math.h> #include <signal.h> #include <stdio.h> @@ -1910,7 +1916,12 @@ long int FS_loc(int chn) long int FS_lof(int chn) { +#ifdef CONFIG_INTERPRETER_BAS_HAVE_FSTAT struct stat buf; +#else + off_t curpos; + off_t endpos; +#endif int fd; if (opened(chn, -1) == -1) @@ -1936,13 +1947,47 @@ long int FS_lof(int chn) } assert(fd != -1); + + /* Get the size of the file */ + +#ifdef CONFIG_INTERPRETER_BAS_HAVE_FSTAT if (fstat(fd, &buf) == -1) { FS_errmsg = strerror(errno); return -1; } - return buf.st_size / file[chn]->recLength; + return (long int)(buf.st_size / file[chn]->recLength); +#else + /* Save the current file position */ + + curpos = lseek(fd, 0, SEEK_CUR); + if (curpos == (off_t)-1) + { + FS_errmsg = strerror(errno); + return -1; + } + + /* Get the position at the end of the file */ + + endpos = lseek(fd, 0, SEEK_END); + if (endpos == (off_t)-1) + { + FS_errmsg = strerror(errno); + return -1; + } + + /* Restore the file position */ + + curpos = lseek(fd, curpos, SEEK_SET); + if (curpos == (off_t)-1) + { + FS_errmsg = strerror(errno); + return -1; + } + + return (long int)(endpos / file[chn]->recLength); +#endif } long int FS_recLength(int chn) |