summaryrefslogtreecommitdiffstats
path: root/sys/boot
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2013-08-01 18:06:58 +0000
committermarcel <marcel@FreeBSD.org>2013-08-01 18:06:58 +0000
commited44436fe152c80c0b7431b9e1e730f1aca47199 (patch)
tree6b221f04820f4c96906a15c63be1512dcc626853 /sys/boot
parentf35ac11d77001bda7d565edd240d6d5940e7fa37 (diff)
downloadFreeBSD-src-ed44436fe152c80c0b7431b9e1e730f1aca47199.zip
FreeBSD-src-ed44436fe152c80c0b7431b9e1e730f1aca47199.tar.gz
Fix the build of the testmain target. This target compiles a Forth
interpreter that can be run on the system and as such cannot be compiled against libbstand. On the one hand this means we need to include the usual headers for system interfaces that we use and on the the other hand we can only use standard system interfaces. While here, define local variables only when needed to make this WARNS=2 clean on amd64. PR: 172542 Obtained from: peterj@ Pointed out by: Jan Beich <jbeich@tormail.org>
Diffstat (limited to 'sys/boot')
-rw-r--r--sys/boot/ficl/loader.c35
1 files changed, 31 insertions, 4 deletions
diff --git a/sys/boot/ficl/loader.c b/sys/boot/ficl/loader.c
index 939affc..03ef95f 100644
--- a/sys/boot/ficl/loader.c
+++ b/sys/boot/ficl/loader.c
@@ -33,7 +33,13 @@
*******************************************************************/
#ifdef TESTMAIN
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <fcntl.h>
+#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#else
#include <stand.h>
#endif
@@ -135,9 +141,9 @@ void
ficlGetenv(FICL_VM *pVM)
{
#ifndef TESTMAIN
- char *name;
+ char *name, *value;
#endif
- char *namep, *value;
+ char *namep;
int names;
#if FICL_ROBUST > 1
@@ -243,9 +249,9 @@ void
ficlFindfile(FICL_VM *pVM)
{
#ifndef TESTMAIN
- char *name;
+ char *name, *type;
#endif
- char *type, *namep, *typep;
+ char *namep, *typep;
struct preloaded_file* fp;
int names, types;
@@ -511,6 +517,14 @@ static void pfread(FICL_VM *pVM)
*/
static void pfreaddir(FICL_VM *pVM)
{
+#ifdef TESTMAIN
+ static union {
+ struct dirent dirent;
+ char buf[512];
+ } u;
+ off_t off;
+ int len;
+#endif
struct dirent *d;
int fd;
@@ -519,7 +533,20 @@ static void pfreaddir(FICL_VM *pVM)
#endif
fd = stackPopINT(pVM->pStack);
+#if TESTMAIN
+ /*
+ * The readdirfd() function is specific to the loader environment.
+ * We do the best we can to make freaddir work, but it's not at
+ * all guaranteed.
+ */
+ off = lseek(fd, 0LL, SEEK_CUR);
+ len = getdents(fd, u.buf, sizeof(u.buf));
+ d = (len != -1) ? &u.dirent : NULL;
+ if (d != NULL)
+ lseek(fd, off + d->d_reclen, SEEK_SET);
+#else
d = readdirfd(fd);
+#endif
if (d != NULL) {
stackPushPtr(pVM->pStack, d->d_name);
stackPushINT(pVM->pStack, strlen(d->d_name));
OpenPOWER on IntegriCloud