[comp.bugs.sys5] Bug in SVR4 BSD-compatibility library

lcz@sat.datapoint.com (Lee Ziegenhals) (01/26/91)

There appears to be a bug in the BSD compatibility library in SVR4.  The
library includes the BSD version of readdir(3) which returns (struct direct *).
This routine is not mentioned in the BSD/Xenix Compatibility Guide, but it is
included in /usr/ucbinclude/sys/dir.h.  The problem is that getwd(3) and
scandir(3) both use the SYSV definition of readdir, which returns
(struct dirent *)!  The result is that if you include ucblib, getwd and
scandir do not work, because they end up calling the BSD readdir while
expecting the SYSV readdir.

My temporary solution was to remove readdir from libucb, so that getwd and
scandir call the SYSV readdir.  The proper solution appears to be to modify
getwd and scandir to use the BSD readdir.  However, I am curious about the fact
that readdir does not appear in the compatibility guide.  Has anyone else seen
this?  Are there any SVR4 versions that have fixed this problem?  I am running
the unmodified AT&T SVR4 V2.0.

Lee Ziegenhals (lcz@sat.datapoint.com)

sef@kithrup.COM (Sean Eric Fagan) (01/26/91)

In article <867@dptspd.sat.datapoint.com> lcz@sat.datapoint.com (Lee Ziegenhals) writes:
>Has anyone else seen
>this?  Are there any SVR4 versions that have fixed this problem?  I am running
>the unmodified AT&T SVR4 V2.0.

Heh.  This is actually rather amusing.  For 3.2, there is a similar problem:
libx.a has a version of readdir() that returns the structure defined in
<sys/ndir.h>, which is incompatable with the version defined in libc.a and
<dirent.h>.  (Comments about this have been made on c.u.sysv386; the basic
consensus has been to remove the offending modules from libx.a; since I
haven't done that on kithrup yet, I tend to replace '-lx' with '-lc -lx'.)

-- 
Sean Eric Fagan  | "I made the universe, but please don't blame me for it;
sef@kithrup.COM  |  I had a bellyache at the time."
-----------------+           -- The Turtle (Stephen King, _It_)
Any opinions expressed are my own, and generally unpopular with others.

gwyn@smoke.brl.mil (Doug Gwyn) (01/26/91)

In article <867@dptspd.sat.datapoint.com> lcz@sat.datapoint.com (Lee Ziegenhals) writes:
>There appears to be a bug in the BSD compatibility library in SVR4.  The
>library includes the BSD version of readdir(3) which returns (struct direct *).

There is the real problem.  Even on BSD systems, it would be preferable to
use a POSIX-compatible interface (one of which I provide), and future
releases of BSD will provide that.

I understand the desire for the "compatibility library" to support
struct direct etc. in order to permit recompilation of obsolete code
without having to edit it first.  However, it would be much better to
modernize the out-of-date source code than to promulgate support for
obsolete interfaces forever.

>My temporary solution was to remove readdir from libucb, so that getwd and
>scandir call the SYSV readdir.  The proper solution appears to be to modify
>getwd and scandir to use the BSD readdir.

Gack!  Your "temporary" solution is MUCH better than your "proper" one.
We should NOT be encouraging the proliferation of the obsolete non-POSIX
*dir() interfaces.  As for the next BSD release, getwd() and scandir()
should use the POSIX interface.

andy@xwkg.Icom.Com (Andrew H. Marrinson) (01/28/91)

It seems to me that we want to be able to use BSD compatible readdir
because of the wealth of programs that rely on them (non-standard
though they may be).  It also seems that this situation is very
similar to the problem involving POSIX compliant implementation of
fread and fwrite.  These functions must continue to work even if the
user redefines the read and write functions on which they are based.
The solution taken was to have fread and fwrite call functions called
_read and _write.  The functions read and write in libc.so are then
defined to be the same as read and write unless the user redefines
them (using a piece of hair called #pragma weak, but that's not
important here).

I think the best solution would be fore getwd, and similar functions
that use readdir to call _readdir instead.  This way, programs that
link with libucb.a would get ucb compatible readdir, but the library
routines that depend on System V readdir would get what they need too.
Everything continues to work just fine.

Anyone from USL listening? (1/2 :-))
--
		Andrew H. Marrinson
		Icom Systems, Inc.
		Wheeling, IL, USA
		(andy@icom.icom.com)

chip@tct.uucp (Chip Salzenberg) (01/29/91)

According to sef@kithrup.COM (Sean Eric Fagan):
>[3.2] libx.a has a version of readdir() that returns the structure defined in
><sys/ndir.h>, which is incompatable with the version defined in libc.a and
><dirent.h>.

My preferred solution is to extract the useful routines from libx.a --
chsize(), nap() and rdchk() come to mind -- and use them to create
libxenix.a.  Then I replace "-lx" with "-lxenix".
-- 
Chip Salzenberg at Teltronics/TCT     <chip@tct.uucp>, <uunet!pdn!tct!chip>

andyc@bucky.intel.com (Andy Crump) (01/30/91)

>>>>> On 25 Jan 91 17:50:04 GMT, lcz@sat.datapoint.com (Lee Ziegenhals) said:

Lee> There appears to be a bug in the BSD compatibility library in SVR4.  The
Lee> library includes the BSD version of readdir(3) which returns (struct direct *).
Lee> This routine is not mentioned in the BSD/Xenix Compatibility Guide, but it is
Lee> included in /usr/ucbinclude/sys/dir.h.  The problem is that getwd(3) and
Lee> scandir(3) both use the SYSV definition of readdir, which returns
Lee> (struct dirent *)!  The result is that if you include ucblib, getwd and
Lee> scandir do not work, because they end up calling the BSD readdir while
Lee> expecting the SYSV readdir.

getwd is fixed in SVR4.0 Version 3.0.  But scandir is still broke.  I
will file a problem report with AT&T on scandir.
--

    -- Andy Crump

    ...!tektronix!reed!littlei!andyc | andyc@littlei.intel.com
    ...!uunet!littlei!andyc          | andyc@littlei.uu.net

Disclaimer: Any opinions expressed here are my own and 
            not representive of Intel Corportation.