« Return to Thread: MinGw, opendir() stat64() and related

MinGw, opendir() stat64() and related

by Linux-48 :: Rate this Message:

| View in Thread

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>
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>

#define _MAX_PATH 260
#define SLASH '/'

void read_dirs(char *);

int main(int argc, char* argv[])
{
    char *topdir;
    char defaultdir[2]=".";

    if (argc != 2)
    {
        printf("Argument not supplied - using current directory.\n");
        topdir=defaultdir;
    }
    else
        topdir=argv[1];
    printf("Directory scan of %s\n",topdir);
    read_dirs(topdir);
    printf("done.\n");

    exit(0);
}

void read_dirs(char *dir)
{
    char path[_MAX_PATH];
    struct dirent *entry;
    DIR *d;
    struct stat lst; /*should be 'struct stat64 lst*/
    int rec_no = 0;

    d = opendir(dir);
    if( d == NULL )
    {
        return;
    }

    while ( (entry = readdir(d)) )
    {
        if( strcmp( entry->d_name, "." ) == 0 ||
                strcmp( entry->d_name, ".." ) == 0 )
        {
            continue;
        }

        sprintf(path,"%s/%s", dir, entry->d_name);

        if (stat(path, &lst) < 0) /* should be stat64*/
            continue;

        if ( S_ISDIR(lst.st_mode) )
        {
            chdir(entry->d_name);
            read_dirs(".");
            chdir("..");
        }
        else
        {
            getcwd(path, _MAX_PATH);
            printf("%6d %12lld %s%c%s\n",
                   rec_no, lst.st_size, path, SLASH, entry->d_name);
            rec_no++;
        }
    }

    closedir(d);
}
-----------------------------------

Thanks in advance for your assistance.

Hans



------------------------------------------------------------------------------
Virtualization & Cloud Management Using Capacity Planning
Cloud computing makes use of virtualization - but cloud computing
also focuses on allowing computing to be delivered as a service.
http://www.accelacomm.com/jaw/sfnl/114/51521223/
_______________________________________________
MinGW-users mailing list
MinGW-users@...

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@...?subject=unsubscribe

 « Return to Thread: MinGw, opendir() stat64() and related