tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] TINYCC-WINDOWS: readdir bug in libc ?


From: porte64
Subject: [Tinycc-devel] TINYCC-WINDOWS: readdir bug in libc ?
Date: Thu, 30 Nov 2006 17:07:36 +0100
User-agent: Internet Messaging Program (IMP) 3.2.5

Hello,

Please let me translate my post into english (sorry - i thought tcc-devel
operated in french).
I am moving from MinGW to TCC and recompiled my sources on Windows.

The only problem i ran against is that i could not compile code involving the
routines: opendir() readdir() closedir().

However, those symbols are exported from libc.a, and defined in dirent.h:

C:/tcc/lib# nm -Ag *.a|grep readdir
libc.a:d000446.o:00000000 I __imp___readdir
libc.a:d000446.o:00000000 T __readdir
libc.a:d001277.o:00000000 I __imp__readdir
libc.a:d001277.o:00000000 T _readdir
libc.a:d001278.o:00000000 I __imp__readdir_r
libc.a:d001278.o:00000000 T _readdir_r

I have tried to link to mingwex first (libgwminex.a borrowed from MinGW's
runtime) which also exports these routines, but i think this cannot
be achieved as it seems one cannot prevent TCC from linking to libc first.

# tcc -Wall -IC:/tcc/include -LC:/tcc/lib rmed.c
# tcc -Wall -IC:/tcc/include -LC:/tcc/lib -lmingwex rmed.c
tcc: undefined symbol 'opendir'
tcc: undefined symbol 'readdir'
tcc: undefined symbol 'closedir'

Can you help me ?
Is there something i did wrong, or is there a libc issue in which case
it would be nice to have a clean libc including those handy basic routines.

Best regards,
Phil


Here's the code:

/*--------------------------------  S T A R T  -------------------------------*/
/*/
 * REMOVE EMPTY DIRECTORIES
/*/

#include <sys/fcntl.h>
#include <sys/stat.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

/*------------------------------   M A C R O S   -----------------------------*/

#define FN_MAX 1024

int cleaned;

/*--------------------------------   S U B S   -------------------------------*/

void
dirwalk( char *fn ) {
DIR *dnode;
struct dirent *child;
struct stat st;
char fullpath[FN_MAX], *cn;
int regfiles;

if (stat(fn, &st) || !(S_ISDIR(st.st_mode)) ||(dnode=opendir(fn))==NULL) return;

while ((child=readdir(dnode)) != NULL) {
        cn= child->d_name;
        /* skip dummy links */
        if (*cn=='.' && (cn[1]=='\0' || (cn[1]=='.' && cn[2]=='\0'))) continue;
        /* get full path */
        if (strlen(fn)+child->d_reclen+2 > FN_MAX) {
                (void)fprintf(stderr, "path too long: %s/%s\n", fn, cn);
                return;
        }
        else {
                (void)strncpy(fullpath, fn, FN_MAX-1);
                (void)strncat(fullpath, "/", FN_MAX-1);
                (void)strncat(fullpath, cn, FN_MAX-1);
                dirwalk(fullpath);
        }
}

(void)closedir(dnode);
if (!rmdir(fn)) ++cleaned;
return;
}

/*--------------------------------   M A I N   -------------------------------*/

int
main( int ac, char **av ) {
cleaned= 0;
if (ac < 2) {
        puts("RMED - ReMove Empty Directories");
        printf("USAGE: %s <dir> [dir ...] \n", *av);
        exit(1);
}
while(--ac) dirwalk(av[ac]);
(void)printf("=== DONE ===   %d directories cleaned\n", cleaned);
exit(0);
}
/*-------------------------------    E  O  F    ------------------------------*/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]