Linux | 9 Feb 12:29
Picon

MinGw, opendir() stat64() and related

I coded a small utility in "C" using the Code::Blocks IDE on 32 Bit
Linux for distribution. The utility searches, identifies and can delete
files with identical content. 

I also want to distribute a Windows version of the utility but can't get
it to compile and work on Windows 7 using the Mingw 4.6.3 with the
Code::Blocks IDE for Windows.

Under Windows, the complier rejects these declarations and functions:

struct stat64 lst;
stat64(path, &lst);

Using 'stat' instead of 'stat64' will complile without errors but
'opendir()' returns 0. readir() and closedir() also fail;

The code compiles and works as it should on 32 and 64 bit Linux.

I can not find the MinGW specific sources for the functions stat(),
stat64(), opendir(), readdir(), closedir() and other functions.  

'
------------------------------------------

#define _LARGEFILE64_SOURCE
#define _FILE_OFFSET_BITS 64

#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
(Continue reading)

Keith Marshall | 9 Feb 14:50
Picon

Re: MinGw, opendir() stat64() and related

On 9 February 2012 11:29, Linux <linux@...> wrote:
> Under Windows, the complier rejects these declarations and functions:
>
> struct stat64 lst;
> stat64(path, &lst);

In the windows world, you must prefix underscores:

  struct __stat64 lst;
  _stat64( path, &lst );

> Using 'stat' instead of 'stat64' will complile without errors but
> 'opendir()' returns 0. readir() and closedir() also fail;

WJFFM.

$ cat dtree.c
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <string.h>

#if HAVE_DIRENT_D_TYPE_DT_DIR
#   define D_TYPE_IS_DT_DIR(ent)  ((ent)->d_type == DT_DIR)

#else
#   include <sys/types.h>
#   include <sys/stat.h>
#   include <unistd.h>

(Continue reading)

Keith Marshall | 9 Feb 15:17
Picon

Re: MinGw, opendir() stat64() and related

To further qualify my earlier reply:

On 9 February 2012 11:29, Linux <linux@...> wrote:
> I also want to distribute a Windows version of the utility but can't get
> it to compile and work on Windows 7 using the Mingw 4.6.3

The most recent release, from this project, is MinGW GCC-4.6.2;
this is what I have used, to build my example.

> with the Code::Blocks IDE for Windows.

While this may be your preference, it shouldn't be relevant to the
distributed code.  I prefer to use only vim.

> I can not find the MinGW specific sources for the functions stat(),
> stat64() ...

nor will you, because these come directly from Microsoft; (there is
no stat64() anyway; it is _stat64()).

> ... opendir(), readdir(), closedir() and other functions.

These three, and others related to them, are implemented in
mingwex/dirent.c, in the mingwrt source distribution, or in CVS:
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/mingw/include/dirent.h?cvsroot=src
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/mingw/mingwex/dirent.c?cvsroot=src

--

-- 
Regards,
Keith.
(Continue reading)


Gmane