[comp.sys.hp] Problem with <dirent.h>

preetham@ra.src.umd.edu (Preetham Gopalaswamy) (06/05/91)

I am trying to compile the MDQS spooling system for my HP 300's and 800's and
run into a problem at the compile stage in a program at the routine "readdir".
I vaguely recall somebody on this group mentioning some sort of problem with
using <dirent.h>, some incompatibility between SYSV and BSD.  Does anybody 
remember what the problem was.   I will include the portion of the code where
the problem is faced and the compiler generated errors.   Any help would be
highly appreciated.
I checked the definition of the structure "dirent" and it seemed like this
should work.  I could have missed something obvious though.

							Preetham Gopalaswamy



/*
 *              M U L T I - D E V I C E   Q U E U E I N G   S Y S T E M
 *
 *                                D R E C O V E R . C
 *
 *                              Douglas P. Kingston III
 *
 *                              Part of the MDQS Daemon
 */

#include <stdio.h>
#include "queue.h"              /* Includes <sys/types.h> */
#include <dirent.h>

#ifdef DIRBLKSIZ                /* 4BSD flavor assumed */
#define dirent  direct
#endif

extern  char *Newprefix;
extern  char *Qcntrldir;
extern  int Debug;
extern  int Waveoff;

/*
 *      R E C O V E R ( )
 *
 *      This function is called once when the daemon is started up.
 *      All jobs in the queue are enrolled into the daemons queues
 *      unless there is not enough space in which case, they are linked
 *      into the new directory which will cause them to be read later.
 */
recover()
{
        register struct dirent *dirp;
        register DIR    *dirf;
        char    newname[PATHSIZ];

        /*
         *      Read in all the requests in the control directory.
         *      If we run out of space, then just start linking
         *      to the Newdir so the daemon will accept them when
         *      it has space.
         */
recover()
{
        register struct dirent *dirp;
        register DIR    *dirf;
        char    newname[PATHSIZ];

        /*
         *      Read in all the requests in the control directory.
         *      If we run out of space, then just start linking
         *      to the Newdir so the daemon will accept them when
         *      it has space.
         */
        if(( dirf = opendir( Qcntrldir )) == NULL ) {
                complain( "recover() cannot open %s, recovery aborted.",
                        Qcntrldir );
                return;
        }

        while(( dirp = readdir( dirf )) != NULL ) {	<-------  LINE 51
                if( dirp->d_name[0] != 'Q')		<-------  LINE 52
                        continue;

debug("Recovering %s.", dirp->d_name);			<-------  LINE 55
                if( ! Waveoff ) {
                        enroll( dirp->d_name );		<-------  LINE 57
                        rmreq( Newprefix, dirp->d_name, QUIET );
                } else {
                        /* The daemon's queues are full, link to Newdir */
                        sprintf(newname, "%s/%s", Newprefix, dirp->d_name);
                        if( link( dirp->d_name, newname ) && Debug )
debug("Link failed (%s, %s).", newname, sys_errlist[errno] );
                }
        }
        closedir( dirf );
}


######################################################################



The compiler generated the following errors :

        cc -c -O -I. -I../h ../src/drecover.c
"../src/drecover.c", line 51: warning: incorrect structure pointer combination
"../src/drecover.c", line 52: undefined structure or union
"../src/drecover.c", line 52: warning: incorrect member use: d_name
"../src/drecover.c", line 55: undefined structure or union
"../src/drecover.c", line 55: warning: incorrect member use: d_name
"../src/drecover.c", line 57: undefined structure or union
"../src/drecover.c", line 57: warning: incorrect member use: d_name
"../src/drecover.c", line 58: undefined structure or union
"../src/drecover.c", line 58: warning: incorrect member use: d_name
"../src/drecover.c", line 61: undefined structure or union
"../src/drecover.c", line 61: warning: incorrect member use: d_name
"../src/drecover.c", line 62: undefined structure or union
"../src/drecover.c", line 62: warning: incorrect member use: d_name
*** Error code 1

Stop.

toad@hpdmd48.boi.hp.com (Tom Trent) (06/07/91)

I found this in a file in my /usr/contrib/Xm directory:

#ifdef BSD
#include <sys/dir.h>
#else
#include <dirent.h>
#endif

     .
     .
     .


#ifdef BSD
        struct direct   *item;          /*  entry in directory  */
#else
        struct dirent   *item;          /*  entry in directory  */
#endif
~




Of any use?
                               Tom Trent
                               Disk Storage Systems
                               Hewlett Packard

decot@hpcupt1.cup.hp.com (Dave Decot) (06/07/91)

We need to know the contents of "queue.h" in order to fully identify this
problem.  In addition, it seems that you have posted something which
is not the program you compiled, since in addition to the <- arrows,
it contains two copies of the first few lines of the recover() function.

Also, the use of DIRBLKSIZ to detect whether or not the BSD-style of
directory streams is there is not supported and probably will not work.

I would suggest deleting these lines, since if a system has <dirent.h>
at all (as it must in order to compile this program), it should contain
valid definitions of struct dirent and the corresponding declaration of
readdir().  Thus, the use of "direct" should not be necessary.

Dave Decot

DISCLAIMER: These are my opinions only, not those of HP.