Index: head/usr.bin/find/Makefile =================================================================== --- head/usr.bin/find/Makefile +++ head/usr.bin/find/Makefile @@ -7,6 +7,7 @@ SRCS= find.c function.c ls.c main.c misc.c operator.c option.c \ getdate.y YFLAGS= +CFLAGS.clang+= -Werror=undef NO_WMISSING_VARIABLE_DECLARATIONS= Index: head/usr.bin/find/find.h =================================================================== --- head/usr.bin/find/find.h +++ head/usr.bin/find/find.h @@ -36,7 +36,32 @@ */ #include +#include +#include +/* + * We need to build find during the bootstrap stage when building on a + * non-FreeBSD system. Linux does not have the st_flags and st_birthtime + * members in struct stat so we need to omit support for tests that depend + * on these members. This works fine since none of these flags are used + * during the build of world and kernel. + */ +#ifdef UF_SETTABLE +#define HAVE_STRUCT_STAT_ST_FLAGS 1 +#else +#define HAVE_STRUCT_STAT_ST_FLAGS 0 +#endif +#if defined(st_birthtime) || defined(st_birthtimespec) +#define HAVE_STRUCT_STAT_ST_BIRTHTIME 1 +#else +#define HAVE_STRUCT_STAT_ST_BIRTHTIME 0 +#endif +#if defined(MFSNAMELEN) || defined(MFSTYPENAMELEN) +#define HAVE_STRUCT_STATFS_F_FSTYPENAME 1 +#else +#define HAVE_STRUCT_STATFS_F_FSTYPENAME 0 +#endif + /* forward declarations */ struct _plandata; struct _option; @@ -70,8 +95,10 @@ #define F_IGNCASE 0x00010000 /* iname ipath iregex */ #define F_EXACTTIME F_IGNCASE /* -[acm]time units syntax */ #define F_EXECPLUS 0x00020000 /* -exec ... {} + */ +#if HAVE_STRUCT_STAT_ST_BIRTHTIME #define F_TIME_B 0x00040000 /* one of -Btime, -Bnewer, -newerB* */ #define F_TIME2_B 0x00080000 /* one of -newer?B */ +#endif #define F_LINK 0x00100000 /* lname or ilname */ /* node definition */ Index: head/usr.bin/find/function.c =================================================================== --- head/usr.bin/find/function.c +++ head/usr.bin/find/function.c @@ -261,9 +261,11 @@ } else if (plan->flags & F_TIME_A) { COMPARE((now - entry->fts_statp->st_atime + 60 - 1) / 60, plan->t_data.tv_sec); +#if HAVE_STRUCT_STAT_ST_BIRTHTIME } else if (plan->flags & F_TIME_B) { COMPARE((now - entry->fts_statp->st_birthtime + 60 - 1) / 60, plan->t_data.tv_sec); +#endif } else { COMPARE((now - entry->fts_statp->st_mtime + 60 - 1) / 60, plan->t_data.tv_sec); @@ -304,8 +306,10 @@ if (plan->flags & F_TIME_A) xtime = entry->fts_statp->st_atime; +#if HAVE_STRUCT_STAT_ST_BIRTHTIME else if (plan->flags & F_TIME_B) xtime = entry->fts_statp->st_birthtime; +#endif else if (plan->flags & F_TIME_C) xtime = entry->fts_statp->st_ctime; else @@ -362,6 +366,7 @@ return new; } +#ifdef ACL_TYPE_NFS4 /* * -acl function -- * @@ -412,6 +417,7 @@ return (0); return (1); } +#endif PLAN * c_acl(OPTION *option, char ***argvp __unused) @@ -448,12 +454,14 @@ errx(1, "-delete: %s: relative path potentially not safe", entry->fts_accpath); +#if HAVE_STRUCT_STAT_ST_FLAGS /* Turn off user immutable bits if running as root */ if ((entry->fts_statp->st_flags & (UF_APPEND|UF_IMMUTABLE)) && !(entry->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)) && geteuid() == 0) lchflags(entry->fts_accpath, entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); +#endif /* rmdir directories, unlink everything else */ if (S_ISDIR(entry->fts_statp->st_mode)) { @@ -806,6 +814,7 @@ } } +#if HAVE_STRUCT_STAT_ST_FLAGS int f_flags(PLAN *plan, FTSENT *entry) { @@ -849,6 +858,7 @@ new->fl_notflags = notflags; return new; } +#endif /* * -follow functions -- @@ -865,6 +875,7 @@ return palloc(option); } +#if HAVE_STRUCT_STATFS_F_FSTYPENAME /* * -fstype functions -- * @@ -967,6 +978,7 @@ new->c_data = fsname; return new; } +#endif /* * -group gname functions -- @@ -1189,10 +1201,12 @@ if (plan->flags & F_TIME_C) ft = entry->fts_statp->st_ctim; +#if HAVE_STRUCT_STAT_ST_BIRTHTIME else if (plan->flags & F_TIME_A) ft = entry->fts_statp->st_atim; else if (plan->flags & F_TIME_B) ft = entry->fts_statp->st_birthtim; +#endif else ft = entry->fts_statp->st_mtim; return (ft.tv_sec > plan->t_data.tv_sec || @@ -1230,8 +1244,10 @@ new->t_data = sb.st_ctim; else if (option->flags & F_TIME2_A) new->t_data = sb.st_atim; +#if HAVE_STRUCT_STAT_ST_BIRTHTIME else if (option->flags & F_TIME2_B) new->t_data = sb.st_birthtim; +#endif else new->t_data = sb.st_mtim; } @@ -1615,7 +1631,7 @@ case 's': mask = S_IFSOCK; break; -#ifdef FTS_WHITEOUT +#if defined(FTS_WHITEOUT) && defined(S_IFWHT) case 'w': mask = S_IFWHT; ftsoptions |= FTS_WHITEOUT; Index: head/usr.bin/find/ls.c =================================================================== --- head/usr.bin/find/ls.c +++ head/usr.bin/find/ls.c @@ -91,8 +91,10 @@ const char *format; static int d_first = -1; +#ifdef D_MD_ORDER if (d_first < 0) d_first = (*nl_langinfo(D_MD_ORDER) == 'd'); +#endif if (lnow == 0) lnow = time(NULL); Index: head/usr.bin/find/operator.c =================================================================== --- head/usr.bin/find/operator.c +++ head/usr.bin/find/operator.c @@ -46,6 +46,7 @@ #include #include #include +#include #include "find.h" Index: head/usr.bin/find/option.c =================================================================== --- head/usr.bin/find/option.c +++ head/usr.bin/find/option.c @@ -61,11 +61,15 @@ { "!", c_simple, f_not, 0 }, { "(", c_simple, f_openparen, 0 }, { ")", c_simple, f_closeparen, 0 }, +#if HAVE_STRUCT_STAT_ST_BIRTHTIME { "-Bmin", c_Xmin, f_Xmin, F_TIME_B }, { "-Bnewer", c_newer, f_newer, F_TIME_B }, { "-Btime", c_Xtime, f_Xtime, F_TIME_B }, +#endif { "-a", c_and, NULL, 0 }, +#ifdef ACL_TYPE_NFS4 { "-acl", c_acl, f_acl, 0 }, +#endif { "-amin", c_Xmin, f_Xmin, F_TIME_A }, { "-and", c_and, NULL, 0 }, { "-anewer", c_newer, f_newer, F_TIME_A }, @@ -81,13 +85,17 @@ { "-exec", c_exec, f_exec, 0 }, { "-execdir", c_exec, f_exec, F_EXECDIR }, { "-false", c_simple, f_false, 0 }, +#if HAVE_STRUCT_STAT_ST_FLAGS { "-flags", c_flags, f_flags, 0 }, +#endif // -fls { "-follow", c_follow, f_always_true, 0 }, // -fprint // -fprint0 // -fprintf +#if HAVE_STRUCT_STATFS_F_FSTYPENAME { "-fstype", c_fstype, f_fstype, 0 }, +#endif { "-gid", c_group, f_group, 0 }, { "-group", c_group, f_group, 0 }, { "-ignore_readdir_race",c_ignore_readdir_race, f_always_true,0 }, @@ -108,22 +116,28 @@ { "-mtime", c_Xtime, f_Xtime, 0 }, { "-name", c_name, f_name, 0 }, { "-newer", c_newer, f_newer, 0 }, +#if HAVE_STRUCT_STAT_ST_BIRTHTIME { "-newerBB", c_newer, f_newer, F_TIME_B | F_TIME2_B }, { "-newerBa", c_newer, f_newer, F_TIME_B | F_TIME2_A }, { "-newerBc", c_newer, f_newer, F_TIME_B | F_TIME2_C }, { "-newerBm", c_newer, f_newer, F_TIME_B }, { "-newerBt", c_newer, f_newer, F_TIME_B | F_TIME2_T }, { "-neweraB", c_newer, f_newer, F_TIME_A | F_TIME2_B }, +#endif { "-neweraa", c_newer, f_newer, F_TIME_A | F_TIME2_A }, { "-newerac", c_newer, f_newer, F_TIME_A | F_TIME2_C }, { "-neweram", c_newer, f_newer, F_TIME_A }, { "-newerat", c_newer, f_newer, F_TIME_A | F_TIME2_T }, +#if HAVE_STRUCT_STAT_ST_BIRTHTIME { "-newercB", c_newer, f_newer, F_TIME_C | F_TIME2_B }, +#endif { "-newerca", c_newer, f_newer, F_TIME_C | F_TIME2_A }, { "-newercc", c_newer, f_newer, F_TIME_C | F_TIME2_C }, { "-newercm", c_newer, f_newer, F_TIME_C }, { "-newerct", c_newer, f_newer, F_TIME_C | F_TIME2_T }, +#if HAVE_STRUCT_STAT_ST_BIRTHTIME { "-newermB", c_newer, f_newer, F_TIME2_B }, +#endif { "-newerma", c_newer, f_newer, F_TIME2_A }, { "-newermc", c_newer, f_newer, F_TIME2_C }, { "-newermm", c_newer, f_newer, 0 },