[syslinux] [PATCH 1/1] COM32: Add stub functions for directories

Gene Cumm gene.cumm at gmail.com
Tue Oct 28 16:24:00 PDT 2008


From: Gene Cumm <gene.cumm at gmail.com>

The following files add stub functions for common directory
operations.  These all return in an error state to indicate to the
program using these functions that the operation can not be performed.

Signed-off-by: Gene Cumm <gene.cumm at gmail.com>

---

The following files add stub functions for common directory
operations.  These all return in an error state to indicate to the
program using these functions that the operation can not be performed.
 The returned value is either NULL or a value appropriate for an error
state and errno is set to ENOSYS.

All functions set errno to ENOSYS.  opendir, readdir, getcwd, and
fdopendir return NULL.  closedir returns 0 if (DIR *dir) is NULL,
otherwise returns -1.  chdir returns -1.

Until I searched the errno.h list, I was doing the following (using a
value chosen from normal error values for the function that I thought
most appropriate for errno):  opendir set errno to ENOTDIR.  readdir
set errno to EBADF.  closedir returns 0 if (DIR *dir) is NULL,
otherwise returns -1 and sets errno to EBADF.  getcwd set errno to
ENOENT.  chdir set errno ENOTDIR.  fdopendir set errno to EBADF.

Details are also added to the COM32 headers (com32/include) and lib
Makefile (com32/lib).  I separated these out within Makefile such that
they stand out for now.  Once fully implemented within the COM32 lib,
it would probably be more appropriate to place them according to the
normal sort.

Diff performed on current syslinux git master as of 2008-10-28 at 19:14 -0400.

diff -uprN a/com32/include/dirent.h b/com32/include/dirent.h
--- a/com32/include/dirent.h	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/include/dirent.h	2008-10-27 20:34:41.000000000 -0400
@@ -0,0 +1,38 @@
+/*
+ * dirent.h
+ */
+
+#ifndef _DIRENT_H
+#define _DIRENT_H
+
+#include <klibc/extern.h>
+#include <klibc/compiler.h>
+#include <stddef.h>
+#include <sys/types.h>
+
+#ifndef NAME_MAX
+#define NAME_MAX 255
+#endif
+
+struct dirent {
+	long		d_ino;		/* Inode/File number */
+// 	unsigned short	d_reclen;	/* Record Length */
+// 	unsigned short	d_namlen;	/* Length of d_name */
+	char		d_name[NAME_MAX + 1];
+};
+
+typedef struct {
+//	struct _finddata_t	dd_dta;		/* disk transfer area for this dir */
+		/* In MinGW32, contains attrib, times, size and filename */
+	struct dirent		dd_dir;		/* dirent struct to return from dir */
+	long			dd_handle;	/* _findnext handle */
+	short			dd_stat;	/* status return from last lookup */
+	char			dd_name[NAME_MAX + 1];	/* full name of file (struct is extended */
+} DIR;
+
+__extern DIR*		opendir(const char *);
+__extern struct dirent*	readdir(DIR *);
+__extern int		closedir(DIR *);
+__extern DIR *		fdopendir(int);
+
+#endif	/* Not _DIRENT_H */
diff -uprN a/com32/include/unistd.h b/com32/include/unistd.h
--- a/com32/include/unistd.h	2008-10-19 12:29:36.000000000 -0400
+++ b/com32/include/unistd.h	2008-10-26 15:42:05.000000000 -0400
@@ -22,6 +22,9 @@ __extern int isatty(int);

 __extern int getscreensize(int, int *, int *);

+__extern char *getcwd(char *, int);
+__extern int chdir(const char *);
+
 /* Standard file descriptor numbers. */
 #define STDIN_FILENO	0
 #define STDOUT_FILENO	1
diff -uprN a/com32/lib/chdir.c b/com32/lib/chdir.c
--- a/com32/lib/chdir.c	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/lib/chdir.c	2008-10-27 19:53:40.000000000 -0400
@@ -0,0 +1,13 @@
+/*
+ * chdir.c
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+int chdir(const char *path)
+{
+	errno = ENOSYS;
+	return -1;
+}
diff -uprN a/com32/lib/closedir.c b/com32/lib/closedir.c
--- a/com32/lib/closedir.c	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/lib/closedir.c	2008-10-27 19:51:44.000000000 -0400
@@ -0,0 +1,18 @@
+/*
+ * closedir.c
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+int closedir(DIR* dir)
+{
+	int rv;
+	if(dir == NULL)
+		rv = 0;
+	else
+		rv = -1;
+	errno = ENOSYS;
+	return rv;
+}
diff -uprN a/com32/lib/fdopendir.c b/com32/lib/fdopendir.c
--- a/com32/lib/fdopendir.c	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/lib/fdopendir.c	2008-10-27 19:53:40.000000000 -0400
@@ -0,0 +1,13 @@
+/*
+ * fdopendir.c
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+DIR * fdopendir(int __fd)
+{
+	errno = ENOSYS;
+	return NULL;
+}
diff -uprN a/com32/lib/getcwd.c b/com32/lib/getcwd.c
--- a/com32/lib/getcwd.c	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/lib/getcwd.c	2008-10-27 19:53:40.000000000 -0400
@@ -0,0 +1,13 @@
+/*
+ * getcwd.c
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+char *getcwd(char *buf, size_t size)
+{
+	errno = ENOSYS;
+	return NULL;
+}
diff -uprN a/com32/lib/Makefile b/com32/lib/Makefile
--- a/com32/lib/Makefile	2008-10-19 12:29:36.000000000 -0400
+++ b/com32/lib/Makefile	2008-10-26 16:09:15.000000000 -0400
@@ -21,6 +21,8 @@ LIBOBJS = \
 	asprintf.o vasprintf.o strlcpy.o strlcat.o			\
 	vsscanf.o zalloc.o						\
 	\
+	opendir.o readdir.o closedir.o getcwd.o chdir.o fdopendir.o	\
+	\
 	libgcc/__ashldi3.o libgcc/__udivdi3.o			\
 	libgcc/__negdi2.o libgcc/__ashrdi3.o libgcc/__lshrdi3.o		\
 	libgcc/__muldi3.o libgcc/__udivmoddi4.o libgcc/__umoddi3.o	\
diff -uprN a/com32/lib/opendir.c b/com32/lib/opendir.c
--- a/com32/lib/opendir.c	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/lib/opendir.c	2008-10-27 19:52:38.000000000 -0400
@@ -0,0 +1,13 @@
+/*
+ * opendir.c
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+DIR* opendir(const char* szPath)
+{
+	errno = ENOSYS;
+	return NULL;
+}
diff -uprN a/com32/lib/readdir.c b/com32/lib/readdir.c
--- a/com32/lib/readdir.c	1969-12-31 19:00:00.000000000 -0500
+++ b/com32/lib/readdir.c	2008-10-27 19:52:38.000000000 -0400
@@ -0,0 +1,13 @@
+/*
+ * readdir.c
+ */
+
+#include <dirent.h>
+#include <stdio.h>
+#include <errno.h>
+
+struct dirent* readdir(DIR* dir)
+{
+	errno = ENOSYS;
+	return NULL;
+}




More information about the Syslinux mailing list