[DIR structure in Cygwin environment]
Hello Jeff,
please find attached file sys/dir.h and sys/dirent.h. Compiler switch for
Cygwin is __CYGWIN__.
Best regards,
Michael
----- Original Nachricht ----
Von: Jeffrey Johnson <n3...@me.com>
An: rpm-users@rpm5.org
Datum: 27.01.2012 15:39
Betreff: Re: [RPM5.3.5] Compilation errros in Cygwin environment
>
> On Jan 27, 2012, at 7:50 AM, Michael Baudisch wrote:
>
> > Hello,
> > I try to compile Rpm535 in a Cygwin environment. In file rpmdir.c there
> are many errors in combination with DIR structure. I examined a litte
> further. In rpmdir. h we include <dirent.h> with includes <sys/dirent.h>.
> There I find DIR defined as
> >
> > typedef struct __DIR
> > {
> > /* This is first to set alignment in non _COMPILING_NEWLIB case. */
> > unsigned long __d_cookie;
> > struct dirent *__d_dirent;
> > char *__d_dirname; /* directory name with trailing
> > '*' */
> > long __d_position; /* used by telldir/seekdir */
> > int __d_fd;
> > unsigned __d_internal;
> > void *__handle;
> > void *__fh;
> > unsigned __flags;
> > } DIR;
> >
> > This leed during compilation to
> >
> > libtool: compile: gcc -DHAVE_CONFIG_H -I. -I.. -I. -I.. -I../build
> -I../lib -I../ [long command line]
> > rpmdir.c: In function 'avClosedir':
> > rpmdir.c:120: error: 'DIR' has no member named 'lock'
> > rpmdir.c: In function 'avOpendir':
> > rpmdir.c:158: error: 'DIR' has no member named 'fd'
> > rpmdir.c:160: error: 'DIR' has no member named 'data'
> > rpmdir.c:162: error: 'DIR' has no member named 'allocation'
> > rpmdir.c:163: error: 'DIR' has no member named 'size'
> > rpmdir.c:164: error: 'DIR' has no member named 'offset'
> > rpmdir.c:166: error: 'DIR' has no member named 'filepos'
> > rpmdir.c:170: error: 'DIR' has no member named 'lock'
> > [...]
> >
> > Searching the WWW leads to many totally different headers with various
> different definitions. Which all do not match the necessarry structure
> layout. Any ideas how to get rid of the error?
> >
>
> Yes. The internals of a DIR structure differ on almost
> every platform.
>
> RPM is emulating a DIR structure internally as well as
> passing through a pointer opaquely to whatever structure
> the operating system is using when necessary.
>
> So this code "breaks" for every new platform (RPM on Cygwin hasn't
> been attempted for years afaik).
>
> If you can send along a copy of <dir.h> and tell me what
> #define you are using to identify CYGWIN during build time,
> I can ;likely send you a patch.
>
> What mostly needs doing is examining areas of the code like this:
>
> #if !defined(__DragonFly__) && !defined(__CYGWIN__)
> dp->d_reclen = 0; /* W2DO? */
> #endif
>
> #if !(defined(hpux) || defined(__hpux) || defined(sun) ||
> defined(RPM_OS_AIX) || defined(__CYGWIN__) || defined(__QNXNTO__))
> #if !defined(__APPLE__) && !defined(__FreeBSD_kernel__) &&
> !defined(__FreeBSD__) && !defined(__NetBSD__) && !defined(__DragonFly__) &&
> !defined(__OpenBSD__)
> dp->d_off = (off_t)i;
> #endif
> dp->d_type = dt[i];
> #endif
> /*@=type@*/
>
> and adding CYGWIN to the pile.
>
> Note that rpmio/fts.[ch] has similar (but not quite as bad)
> portability breakage.
>
> Could you also add a bug at
> http://launchpad.net/rpm
> please? I will then create a blueprint and attach the bug and
> then plan out milestones->implementations->releases for
> getting RPM to compile and "work" on cygwin.
>
> Thanks!
>
> 73 de Jeff
> >
> >
> > Best regards,
> > Michael
> > ______________________________________________________________________
> > RPM Package Manager http://rpm5.org
> > User Communication List rpm-users@rpm5.org
>
> ______________________________________________________________________
> RPM Package Manager http://rpm5.org
> User Communication List rpm-users@rpm5.org
>
Best regards,
Michael
/* BSD predecessor of POSIX.1 <dirent.h> and struct dirent */
#ifndef _SYS_DIR_H_
#define _SYS_DIR_H_
#include <dirent.h>
#define direct dirent
#endif /*_SYS_DIR_H_*/
/* Posix dirent.h for WIN32.
Copyright 2001, 2002, 2003, 2005, 2006, 2007, 2010 Red Hat, Inc.
This software is a copyrighted work licensed under the terms of the
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
details. */
/* Including this file should not require any Windows headers. */
#ifndef _SYS_DIRENT_H
#define _SYS_DIRENT_H
#include <sys/types.h>
#include <limits.h>
#define __DIRENT_VERSION 2
#pragma pack(push,4)
#define _DIRENT_HAVE_D_TYPE
struct dirent
{
long __d_version; /* Used internally */
__ino64_t d_ino;
unsigned char d_type;
unsigned char __d_unused1[3];
__uint32_t __d_internal1;
char d_name[NAME_MAX + 1];
};
#pragma pack(pop)
#define d_fileno d_ino /* BSD compatible definition */
#define __DIRENT_COOKIE 0xdede4242
#pragma pack(push,4)
typedef struct __DIR
{
/* This is first to set alignment in non _COMPILING_NEWLIB case. */
unsigned long __d_cookie;
struct dirent *__d_dirent;
char *__d_dirname; /* directory name with trailing '*' */
long __d_position; /* used by telldir/seekdir */
int __d_fd;
unsigned __d_internal;
void *__handle;
void *__fh;
unsigned __flags;
} DIR;
#pragma pack(pop)
DIR *opendir (const char *);
DIR *fdopendir (int);
struct dirent *readdir (DIR *);
int readdir_r (DIR *, struct dirent *, struct dirent **);
void rewinddir (DIR *);
int closedir (DIR *);
int dirfd (DIR *);
#ifndef _POSIX_SOURCE
#ifndef __INSIDE_CYGWIN__
long telldir (DIR *);
void seekdir (DIR *, long loc);
#endif
int scandir (const char *__dir,
struct dirent ***__namelist,
int (*select) (const struct dirent *),
int (*compar) (const struct dirent **, const struct dirent **));
int alphasort (const struct dirent **__a, const struct dirent **__b);
#ifdef _DIRENT_HAVE_D_TYPE
/* File types for `d_type'. */
enum
{
DT_UNKNOWN = 0,
# define DT_UNKNOWN DT_UNKNOWN
DT_FIFO = 1,
# define DT_FIFO DT_FIFO
DT_CHR = 2,
# define DT_CHR DT_CHR
DT_DIR = 4,
# define DT_DIR DT_DIR
DT_BLK = 6,
# define DT_BLK DT_BLK
DT_REG = 8,
# define DT_REG DT_REG
DT_LNK = 10,
# define DT_LNK DT_LNK
DT_SOCK = 12,
# define DT_SOCK DT_SOCK
DT_WHT = 14
# define DT_WHT DT_WHT
};
/* Convert between stat structure types and directory types. */
# define IFTODT(mode) (((mode) & 0170000) >> 12)
# define DTTOIF(dirtype) ((dirtype) << 12)
#endif /* _DIRENT_HAVE_D_TYPE */
#endif /* _POSIX_SOURCE */
#endif /*_SYS_DIRENT_H*/