Discussion:
[PATCH 2/4] relocatable: Fix that /@unixroot prefix is not working on OS/2 kLIBC
(too old to reply)
KO Myung-Hun
2016-12-01 10:52:44 UTC
Permalink
Raw Message
OS/2 kLIBC has a feature to rewrite some path components. For example,
'/@unixroot' is replaced with a value of $UNIXROOT if it is.

So prepending a drive letter to the path starting with '/' makes the
path starting with '/@unixroot' to 'x:/@unixroot' which is unexpected.

This will breaks the behavior of some programs depending on /@unixroot
prefix.

* lib/relocatable.c (relocate): Do not touch pathname if it is started
with '/@unixroot'.
---
lib/relocatable.c | 12 ++++++++++++
1 file changed, 12 insertions(+)

diff --git a/lib/relocatable.c b/lib/relocatable.c
index 60cb54a..401f3e0 100644
--- a/lib/relocatable.c
+++ b/lib/relocatable.c
@@ -539,6 +539,18 @@ relocate (const char *pathname)
}

#ifdef __EMX__
+# ifdef __KLIBC__
+# undef strncmp
+
+ if (pathname && strncmp (pathname, "/@unixroot", 10) == 0
+ && (pathname[10] == '\0' || pathname[10] == '/' || pathname[10] == '\\'))
+ {
+ /* kLIBC itself processes /@unixroot prefix */
+
+ return pathname;
+ }
+ else
+# endif
if (pathname && ISSLASH (pathname[0]))
{
const char *unixroot = getenv ("UNIXROOT");
--
2.9.2
KO Myung-Hun
2016-12-01 10:52:43 UTC
Permalink
Raw Message
On OS/2 kLIBC, sa_family_t is unsigned char unless TCPV40HDRS is
defined.

* lib/sys_socket.in.h (sa_family_t): Typedef to unsigned char on
OS/2 kLIBC unless TCPV40HDRS is defined.
---
lib/sys_socket.in.h | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/lib/sys_socket.in.h b/lib/sys_socket.in.h
index 79aa14e..980a112 100644
--- a/lib/sys_socket.in.h
+++ b/lib/sys_socket.in.h
@@ -79,7 +79,12 @@ _GL_INLINE_HEADER_BEGIN

#if !@HAVE_SA_FAMILY_T@
# if !GNULIB_defined_sa_family_t
+/* On OS/2 kLIBC, sa_family_t is unsigned char unless TCPV40HDRS is defined. */
+# if !defined __KLIBC__ || defined TCPV40HDRS
typedef unsigned short sa_family_t;
+# else
+typedef unsigned char sa_family_t;
+# endif
# define GNULIB_defined_sa_family_t 1
# endif
#endif
--
2.9.2
KO Myung-Hun
2016-12-01 10:52:46 UTC
Permalink
Raw Message
On OS/2 kLIBC, d_name is not the last field of struct dirent. So
copying struct dirent according to the size calculated based on d_name
blows the fields after d_name up.

The correct way is to allocate the whole size of struct dirent.

* lib/scandir.c (_D_ALLOC_NAMLEN): Consider the fields after d_name on
OS/2 kLIBC.
---
lib/scandir.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/scandir.c b/lib/scandir.c
index 9da342d..a41ef1a 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -36,7 +36,15 @@
# define _D_EXACT_NAMLEN(d) strlen ((d)->d_name)
#endif
#ifndef _D_ALLOC_NAMLEN
-# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
+# ifndef __KLIBC__
+# define _D_ALLOC_NAMLEN(d) (_D_EXACT_NAMLEN (d) + 1)
+# else
+/* On OS/2 kLIBC, d_name is not the last field of struct dirent. See
+ <http://trac.netlabs.org/libc/browser/branches/libc-0.6/src/emx/include/sys/dirent.h#L68>. */
+# include <stddef.h>
+# define _D_ALLOC_NAMLEN(d) (sizeof (struct dirent) - \
+ offsetof (struct dirent, d_name))
+# endif
#endif

#if _LIBC
--
2.9.2
KO Myung-Hun
2016-12-01 10:52:45 UTC
Permalink
Raw Message
On OS/2 kLIBC, scandir() declaration is different from POSIX. As a
result, alphasort() declaration is different, too.

* lib/alphasort.c (alphasort): Implement according to OS/2 kLIBC
declaration.
* lib/scandir.c (scandir): Add declaration for OS/2 kLIBC.
---
lib/alphasort.c | 10 ++++++++++
lib/scandir.c | 9 +++++++++
2 files changed, 19 insertions(+)

diff --git a/lib/alphasort.c b/lib/alphasort.c
index 49f4bd7..9a8c0ea 100644
--- a/lib/alphasort.c
+++ b/lib/alphasort.c
@@ -21,7 +21,17 @@
#include <string.h>

int
+#ifndef __KLIBC__
alphasort (const struct dirent **a, const struct dirent **b)
{
return strcoll ((*a)->d_name, (*b)->d_name);
}
+#else
+/* On OS/2 kLIBC, the compare function declaration of scandir() is different
+ from POSIX. See <http://trac.netlabs.org/libc/browser/branches/libc-0.6/src/emx/include/dirent.h#L141>. */
+alphasort (const void *a, const void *b)
+{
+ return strcoll ((*(const struct dirent **)a)->d_name,
+ (*(const struct dirent **)b)->d_name);
+}
+#endif
diff --git a/lib/scandir.c b/lib/scandir.c
index d9cb4c4..9da342d 100644
--- a/lib/scandir.c
+++ b/lib/scandir.c
@@ -89,10 +89,19 @@ cancel_handler (void *arg)


int
+#ifndef __KLIBC__
SCANDIR (const char *dir,
DIRENT_TYPE ***namelist,
int (*select) (const DIRENT_TYPE *),
int (*cmp) (const DIRENT_TYPE **, const DIRENT_TYPE **))
+#else
+/* On OS/2 kLIBC, scandir() declaration is different from POSIX. See
+ <http://trac.netlabs.org/libc/browser/branches/libc-0.6/src/emx/include/dirent.h#L141>. */
+SCANDIR (const char *dir,
+ DIRENT_TYPE ***namelist,
+ int (*select) (DIRENT_TYPE *),
+ int (*cmp) (const void *, const void *))
+#endif
{
DIR *dp = __opendir (dir);
DIRENT_TYPE **v = NULL;
--
2.9.2
Pádraig Brady
2016-12-01 11:38:06 UTC
Permalink
Raw Message
Hi/2.
These are OS/2 patches.
Review, please...
[PATCH 1/4] sys_socket: typedef sa_family_t correctly on OS/2 kLIBC
[PATCH 3/4] alphasort, scandir: Port to OS/2 kLIBC
[PATCH 4/4] scandir: Fix _D_ALLOC_NAMLEN() on OS/2 kLIBC
Pushed.

thanks,
Pádraig

Loading...