Skip to content

Instantly share code, notes, and snippets.

@kosh04
Last active August 29, 2015 14:05
Show Gist options
  • Save kosh04/8807f3a4d0bc1faf0810 to your computer and use it in GitHub Desktop.
Save kosh04/8807f3a4d0bc1faf0810 to your computer and use it in GitHub Desktop.
dirent.h と _USE_32BIT_TIME_T の組み合わせがバグっているかもしれない話 #mingw32
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
int main(int argc, char *argv[])
{
struct dirent *entry;
DIR *dir;
char *path;
path = argv[1] ? argv[1] : ".";
dir = opendir(path);
if (dir == NULL) {
perror("opendir");
exit(EXIT_FAILURE);
}
while ((entry = readdir(dir)) != NULL) {
printf("name : %s\n", entry->d_name);
}
closedir(dir);
return 0;
}
$ gcc -v
Using built-in specs.
COLLECT_GCC=C:\MinGW\bin\gcc.exe
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.8.1/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.8.1/configure --prefix=/mingw --host=mingw32 --build=mingw32 --without-pic --enable-shared --enable-static --with-gnu-ld --enable-lto --enable-libssp --disable-multilib --enable-languages=c,c++,fortran,objc,obj-c++,ada --disable-sjlj-exceptions --with-dwarf2 --disable-win32-registry --enable-libstdcxx-debug --enable-version-specific-runtime-libs --with-gmp=/usr/src/pkg/gmp-5.1.2-1-mingw32-src/bld --with-mpc=/usr/src/pkg/mpc-1.0.1-1-mingw32-src/bld --with-mpfr= --with-system-zlib --with-gnu-as --enable-decimal-float=yes --enable-libgomp --enable-threads --with-libiconv-prefix=/mingw32 --with-libintl-prefix=/mingw --disable-bootstrap LDFLAGS=-s CFLAGS=-D_USE_32BIT_TIME_T
Thread model: win32
gcc version 4.8.1 (GCC)
$ gcc dirent.c && ./a.exe /
name : .
name : ..
name : bin
name : etc
name : include
name : lib
name : local
name : m.ico
name : msys.bat
name : msys.ico
name : postinstall
name : sbin
name : share
name : var
# まっしろ
$ gcc -D_USE_32BIT_TIME_T dirent.c && ./a.exe /
name :
name :
name :
name :
name :
name :
name :
name :
name :
name :
name :
name :
name :
name :
# TDM-GCC (mingw-w64) では上記の問題は発生しない
$ /c/MinGW64/bin/gcc -m32 -D_USE_32BIT_TIME_T dirent.c && ./a.exe /
name : .
name : ..
name : bin
name : etc
name : include
name : lib
name : local
name : m.ico
name : msys.bat
name : msys.ico
name : postinstall
name : sbin
name : share
name : var
@kosh04
Copy link
Author

kosh04 commented Aug 28, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment