8000 add configure test for fts_read · util-linux/util-linux@a5163a8 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5163a8

Browse files
committed
add configure test for fts_read
1 parent 559d021 commit a5163a8

File tree

1 file changed

+121
-3
lines changed

1 file changed

+121
-3
lines changed

configure.ac

Lines changed: 121 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -822,9 +822,127 @@ AS_IF([test x"$have_dirfd" = xno], [
822822

823823
AM_CONDITIONAL([HAVE_DIRFD], [test "x$have_dirfd" = xyes || test "x$have_ddfd" = xyes])
824824

825-
have_fts_open=no
826-
AC_CHECK_FUNCS([fts_open], [have_fts_open=yes], [have_fts_open=no])
827-
AM_CONDITIONAL([HAVE_FTS_OPEN], [test "x$have_fts_open" = xyes])
825+
AC_MSG_CHECKING([Whether fts_read() actually works])
826+
AC_RUN_IFELSE([AC_LANG_PROGRAM([[
827+
#include <stdio.h>
828+
#include <stdlib.h>
829+
#include <unistd.h>
830+
#include <sys/stat.h>
831+
#include <limits.h>
832+
#include <fcntl.h>
833+
#include <errno.h>
834+
#include <fts.h>
835+
]]< 10000 /span>, [[
836+
char template[NAME_MAX];
837+
char *paths[] = { NULL, NULL };
838+
char path[PATH_MAX];
839+
FTSENT *node;
840+
FTS *fts;
841+
int r;
842+
int files = 0, dirs = 0;
843+
844+
snprintf(template, sizeof(template), "%s/fts_checkXXXXXX", getenv("TMPDIR") ?: "/tmp");
845+
846+
paths[0] = mkdtemp(template);
847+
if (paths[0] == NULL) {
848+
perror("mkdtemp");
849+
return 1;
850+
}
851+
852+
r = mkdir(template, 0755);
853+
if (r < 0 && errno != EEXIST) {
854+
perror("mkdir");
855+
return 1;
856+
}
857+
dirs++;
858+
859+
snprintf(path, sizeof(path), "%s/subdir", template);
860+
r = mkdir(path, 0755);
861+
if (r < 0 && errno != EEXIST) {
862+
perror("mkdir");
863+
return 1;
864+
}
865+
dirs++;
866+
867+
snprintf(path, sizeof(path), "%s/file1.txt", template);
868+
r = creat(path, 0644);
869+
if (r < 0) {
870+
perror("creat");
871+
return 1;
872+
}
873+
close(r);
874+
files++;
875+
876+
snprintf(path, sizeof(path), "%s/file2.txt", template);
877+
r = creat(path, 0644);
878+
if (r < 0) {
879+
perror("creat");
880+
return 1;
881+
}
882+
close(r);
883+
files++;
884+
885+
snprintf(path, sizeof(path), "%s/subdir/file3.txt", template);
886+
r = creat(path, 0644);
887+
if (r < 0) {
888+
perror("creat");
889+
return 1;
890+
}
891+
close(r);
892+
files++;
893+
894+
snprintf(path, sizeof(path), "%s/subdir/file4.txt", template);
895+
r = creat(path, 0644);
896+
if (r < 0) {
897+
perror("creat");
898+
return 1;
899+
}
900+
close(r);
901+
files++;
902+
903+
fts = fts_open(paths, FTS_NOCHDIR | FTS_PHYSICAL, NULL);
904+
if (fts == NULL) {
905+
perror("fts_open");
906+
return 1;
907+
}
908+
909+
while ((node = fts_read(fts)) != NULL) {
910+
switch (node->fts_info) {
911+
case FTS_F:
912+
files--;
913+
break;
914+
case FTS_D:
915+
dirs--;
916+
break;
917+
case FTS_ERR:
918+
perror("fts_read");
919+
return 1;
920+
default:
921+
break;
922+
}
923+
}
924+
925+
if (fts_close(fts) < 0) {
926+
perror("fts_close");
927+
return 1;
928+
}
929+
930+
if (files != 0) {
931+
fprintf(stderr, "Error: %d files not found\n", files);
932+
return 1;
933+
}
934+
935+
if (dirs != 0) {
936+
fprintf(stderr, "Error: %d directories not found\n", dirs);
937+
return 1;
938+
}
939+
]])], [
940+
AC_MSG_RESULT([yes])
941+
AC_DEFINE([HAVE_FTS_OPEN], [1],
942+
[Define if fts_read() actually works])
943+
], [
944+
AC_MSG_RESULT([no])
945+
])
828946

829947
MQ_LIBS=
830948
AC_CHECK_LIB([rt], [mq_open], [MQ_LIBS="-lrt"])

0 commit comments

Comments
 (0)
0