[comp.os.minix] Bug in getdents

ajm@cit5.cit.oz (Tony Mcgregor) (01/16/90)

There is a bug in lib/other/getdents.c which causes ls to fail
when listing directories. Under minix getdents gets the size of the structure
it returns wrong. I think this is because of an incorrect #define.

The following fix makes it work under minix. 


#! /bin/sh
# This is a shell archive, meaning:
# 1. Remove everything above the #! /bin/sh line.
# 2. Save the resulting text in a file.
# 3. Execute the file with /bin/sh (not csh) to create:
#	getdents.cdif
#	getdents.crc
# This archive created: Tue Jan 16 12:27:29 1990
export PATH; PATH=/bin:/usr/bin:$PATH
if test -f 'getdents.cdif'
then
	echo shar: "will not over-write existing file 'getdents.cdif'"
else
cat << \SHAR_EOF > 'getdents.cdif'
*** O_getdents.c	Tue Jan 16 12:11:51 1990
--- getdents.c	Tue Jan 16 12:39:22 1990
***************
*** 59,68 ****
  #include	<signal.h>
  #endif
  
- #ifdef BSD_SYSV
- struct dirent __dirent;		/* (just for the DIRENTBASESIZ macro) */
- #endif
- 
  #ifdef UFS
  #define	RecLen( dp )	(sizeof(struct direct))	/* fixed-length entries */
  #else				/* BFS || NFS */
--- 59,64 ----
***************
*** 93,103 ****
  #define	DELETED	0
  #endif
  
! #ifndef DIRENTSIZ
! #define DIRENTSIZ(x)	(x)
! #endif
! #ifndef DIRENTBASESIZ
! #define DIRENTBASESIZ 0
  #endif
  #ifndef DIRBLKSIZ
  #define	DIRBLKSIZ	4096	/* directory file read buffer size */
--- 89,101 ----
  #define	DELETED	0
  #endif
  
! #ifndef DIRENTBASESIZ
! struct dirent __dirent;		/* (just for the DIRENTBASESIZ macro) */
! #define DIRENTBASESIZ sizeof(__dirent) + 1  /*+1 is for eostring*/
! #endif
! 
! #ifndef DIRENTSIZ
! #define DIRENTSIZ(x)	(x + DIRENTBASESIZ)
  #endif
  #ifndef DIRBLKSIZ
  #define	DIRBLKSIZ	4096	/* directory file read buffer size */
SHAR_EOF
fi
if test -f 'getdents.crc'
then
	echo shar: "will not over-write existing file 'getdents.crc'"
else
cat << \SHAR_EOF > 'getdents.crc'
32903   7831 ORIG_getdents.c
57235   7867 getdents.c
42108   1013 getdents.cdif
SHAR_EOF
fi
exit 0
#	End of shell archive


----------------------------------------------------------------------------
Tony McGregor 
Department of Robotics and Digital Tech., Chisholm Institute of Technology
PO Box 197, Caulfield East, Vic 3145, Australia  
Phone: +61 3 5732014    Fax: +61 3 5732748    ACSNET: ajm@cit5.cit.oz
----------------------------------------------------------------------------