From: David van Moolenbroek Date: Sat, 19 Sep 2015 23:17:55 +0000 (+0000) Subject: Update, move NetBSD find(1) X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zpipe.c?a=commitdiff_plain;h=319e7a6d071ca2b4d307b084f9cb29f0d56e2e04;p=minix.git Update, move NetBSD find(1) Change-Id: Iccda44465d49dba407d1ac1b1ced8aa8b4e6d8aa --- diff --git a/minix/commands/Makefile b/minix/commands/Makefile index 35852edeb..cb9ca97d7 100644 --- a/minix/commands/Makefile +++ b/minix/commands/Makefile @@ -9,7 +9,7 @@ SUBDIR= add_route arp at backup btrace \ decomp16 DESCRIBE devmand devsize dhcpd \ dhrystone diff diskctl \ eject fbdctl \ - find fix format fsck.mfs \ + fix format fsck.mfs \ gcov-pull host \ hostaddr ifconfig ifdef \ intr ipcrm ipcs irdpd isoread \ diff --git a/usr.bin/Makefile b/usr.bin/Makefile index ae211b781..04767a3f2 100644 --- a/usr.bin/Makefile +++ b/usr.bin/Makefile @@ -10,7 +10,7 @@ SUBDIR= asa \ column comm csplit ctags cut \ deroff dirname du \ env expand \ - false finger fold fpr from \ + false find finger fold fpr from \ fsplit ftp genassym getopt \ head hexdump id indent infocmp join jot \ lam last ldd leave \ diff --git a/minix/commands/find/Makefile b/usr.bin/find/Makefile similarity index 61% rename from minix/commands/find/Makefile rename to usr.bin/find/Makefile index 8ea80e69c..73aff82d2 100644 --- a/minix/commands/find/Makefile +++ b/usr.bin/find/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.12 2006/12/14 20:55:56 he Exp $ +# $NetBSD: Makefile,v 1.13 2009/04/14 22:15:20 lukem Exp $ # from: @(#)Makefile 8.1 (Berkeley) 6/6/93 .include @@ -6,7 +6,7 @@ PROG= find SRCS= find.c function.c ls.c main.c misc.c operator.c option.c -LDADD+= -lutil -DPADD+= ${LIBUTIL} +LDADD+=-lutil +DPADD+=${LIBUTIL} .include diff --git a/minix/commands/find/extern.h b/usr.bin/find/extern.h similarity index 100% rename from minix/commands/find/extern.h rename to usr.bin/find/extern.h diff --git a/minix/commands/find/find.1 b/usr.bin/find/find.1 similarity index 74% rename from minix/commands/find/find.1 rename to usr.bin/find/find.1 index ab0be0aba..715bcc6f3 100644 --- a/minix/commands/find/find.1 +++ b/usr.bin/find/find.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: find.1,v 1.66 2007/07/19 07:49:30 daniel Exp $ +.\" $NetBSD: find.1,v 1.80 2013/02/08 12:50:51 wiz Exp $ .\" .\" Copyright (c) 1990, 1993 .\" The Regents of the University of California. All rights reserved. @@ -32,7 +32,7 @@ .\" .\" from: @(#)find.1 8.7 (Berkeley) 5/9/95 .\" -.Dd July 19, 2007 +.Dd August 26, 2012 .Dt FIND 1 .Os .Sh NAME @@ -65,13 +65,10 @@ listed below) in terms of each file in the tree. .Pp The options are as follows: -.Pp .Bl -tag -width Ds .It Fl H -The -.Fl H -option causes the file information and file type (see -.Xr stat 2 ) , +Causes the file information and file type (see +.Xr stat 2 ) returned for each symbolic link encountered on the command line to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will @@ -79,27 +76,21 @@ be for the link itself. File information of all symbolic links not on the command line is that of the link itself. .It Fl L -The -.Fl L -option causes the file information and file type (see +Causes the file information and file type (see .Xr stat 2 ) returned for each symbolic link to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. .It Fl P -The -.Fl P -option causes the file information and file type (see +Causes the file information and file type (see .Xr stat 2 ) returned for each symbolic link to be those of the link itself. .It Fl d -The -.Fl d -option causes +Causes .Nm to perform a depth-first traversal, i.e., directories -are visited in post-order and all entries in a directory will be acted +are visited in post-order, and all entries in a directory will be acted on before the directory itself. By default, .Nm @@ -108,34 +99,26 @@ Note, the default is .Ar not a breadth-first traversal. .It Fl E -The -.Fl E -option causes +Causes .Ar regexp arguments to primaries to be interpreted as extended regular expressions (see .Xr re_format 7 ) . .It Fl f -The -.Fl f -option specifies a file hierarchy for +Specifies a file hierarchy for .Nm to traverse. File hierarchies may also be specified as the operands immediately following the options. .It Fl h -The -.Fl h -option causes the file information and file type (see -.Xr stat 2 ) , +Causes the file information and file type (see +.Xr stat 2 ) returned for each symbolic link to be those of the file referenced by the link, not the link itself. If the referenced file does not exist, the file information and type will be for the link itself. .It Fl s -The -.Fl s -option causes the entries of each directory to be sorted in +Causes the entries of each directory to be sorted in lexicographical order. Note that the sorting is done only inside of each directory; files in different directories are not sorted. @@ -147,14 +130,12 @@ which is different from .Dq Li "find ... \&| sort" order. .It Fl X -The -.Fl X -option is a modification to permit +Modifies the output to permit .Nm to be safely used in conjunction with .Xr xargs 1 . If a file name contains any of the delimiting characters used by -.Nm xargs , +.Xr xargs 1 , a diagnostic message is displayed on standard error, and the file is skipped. The delimiting characters include single @@ -163,38 +144,52 @@ and double .Pq Dq \&" quotes, backslash .Pq Dq \e , -space, tab and newline characters. +space, tab, and newline characters. Alternatively, the .Ic -print0 or .Ic -printx primaries can be used to format the output in a way that -.Nm xargs +.Xr xargs 1 can accept. .It Fl x -The -.Fl x -option restricts the search to the file system containing the +Restricts the search to the file system containing the directory specified. Does not list mount points to other file systems. .El .Sh PRIMARIES -.Bl -tag -width Ds +All primaries which take a numeric argument of +.Ar n +allow the number to be preceded by a plus sign +.Pq Dq \&+ +or a minus sign +.Pq Dq \- . +A preceding plus sign means +.Dq more than Ar n , +a preceding minus sign means +.Dq less than Ar n , +and neither means +.Dq exactly Ar n . +.Pp +.Bl -tag -width Ds -compact .It Ic -amin Ar n True if the difference between the file last access time and the time .Nm was started, rounded up to the next full minute, is .Ar n minutes. +.Pp .It Ic -anewer Ar file True if the current file has a more recent last access time than -.Ar file . +.Ar file . +.Pp .It Ic -atime Ar n True if the difference between the file last access time and the time .Nm was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. +.Pp .It Ic -cmin Ar n True if the difference between the time of last change of file status information and the time @@ -202,9 +197,11 @@ information and the time was started, rounded up to the next full minute, is .Ar n minutes. +.Pp .It Ic -cnewer Ar file True if the current file has a more recent last change time than -.Ar file . +.Ar file . +.Pp .It Ic -ctime Ar n True if the difference between the time of last change of file status information and the time @@ -212,93 +209,128 @@ information and the time was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. +.Pp .It Ic -delete -Delete found files and/or directories. -Always returns True. +Delete found files, symbolic links, and directories. +Always returns true. This executes from the current working directory as .Nm recurses down the tree. -It will not attempt to delete a filename with a -.Dq \/ -character in its pathname relative to -.Dq \. -for security reasons. +To avoid deleting unexpected files, it will ignore any filenames that +.Xr fts 3 +returns that contain a +.Dq / +.Xr ( fts 3 +should not return such pathnames). Depth-first traversal processing is implied by this option. -This can also be invoked as +This primary can also be invoked as .Ic -rm . +.Pp .It Ic -empty True if the current file or directory is empty. -.\" The ".sp" below is probably not the right way to get the desired effect. -.It Ic -exec Ar utility Oo argument ... Oc No ; -.sp -1l -.It Ic -exec Ar utility Oo argument ... Oc No {} + +.Pp +.It Ic -exec Ar utility Oo argument ... Oc Ic \&; +.It Ic -exec Ar utility Oo argument ... Oc Ic {} Ic \&+ Execute the specified .Ar utility with the specified arguments. -The list of arguments is terminated by -.Dq Li \&; -or -.Dq Li \&+ . +.Pp +The list of arguments for .Ar utility -will be executed from the directory from which +is terminated by a lone semicolon +.Dq Ic \&; +or plus +.Dq Ic \&+ +character as a separate parameter. +The command specified by +.Ar utility +will be executed with its current working directory being the directory +from which .Nm was executed. .Pp -If terminated by a semicolon -.Pq Dq \&; , -the +If the list of arguments is terminated by a semicolon +.Pq Dq Ic \&; , +then .Ar utility -is invoked once per path. -If the string -.Dq {} -appears anywhere in the utility name or the arguments, -it is replaced by the pathname of the current file. -.Pp -If terminated by a plus sign -.Pq Dq \&+ , -the pathnames for which the -primary is evaluated are aggregated into sets, and +is invoked once per pathname. +If +the string +.Dq Ic {} +appears one or more times in the utility name or arguments, +then it is replaced by the pathname of the current file +(but it need not appear, in which case the pathname +will not be passed to +.Ar utility ) . +The semicolon-terminated form of the +.Ic -exec +primary returns true if and only if +.Ar utility +exits with a zero exit status. +Note that the semicolon will have to be escaped on the shell command line +in order to be passed as a parameter. +.Pp +If the list of arguments is terminated by a plus sign +.Pq Dq Ic \&+ , +then the pathnames for which the primary is evaluated are aggregated +into sets, and .Ar utility will be invoked once per set, similar to .Xr xargs 1 . -If any invocation exits with non-zero exit status, then +In this case the string +.Dq Ic {} +must appear, and must appear as the last item in the argument list, +just before the +.Dq Ic \&+ +parameter, and is replaced by the pathnames of the current set of files. +Each set is limited to no more than 5,000 pathnames, +and is also limited such that the total number of bytes in the argument +list does not exceed +.Dv ARG_MAX . +The plus-terminated form of the +.Ic -exec +primary always returns true. +If the plus-terminated form of the +.Ic -exec +primary results in any invocation of +.Ar utility +exiting with non-zero exit status, then .Nm -will eventually do so as well, but this does not cause +will eventually exit with non-zero status as well, +but this does not cause .Nm to exit early. -The string -.Dq {} -must appear, and must appear last. -Each set is limitted to no more than 5,000 pathnames, -and is also limitted such that the invokation of -.Ar utility -does not exceed -.Dv ARG_MAX . -.It Ic -execdir Ar utility Oo argument ... Oc No ; +.Pp +.It Ic -execdir Ar utility Oo argument ... Oc Ic \&; The .Ic -execdir primary is similar to the semicolon-terminated -.Pq Dq \&; +.Pq Dq Ic \&; variant of the .Ic -exec primary, with the exception that .Ar utility will be executed from the directory that holds the current file. -The filename substituted for the string -.Dq {} -is not qualified. +Only the base filename is substituted for the string +.Dq Ic {} . Set aggregation -.Pq Do \&+ Dc termination +.Pq Do Ic \&+ Dc termination is not supported. -.It Ic -exit Op Ar n +.Pp +.It Ic -exit Op Ar status This primary causes .Nm -to stop traversing the filesystem and exit immediately if a -previous condition was met. -If no value is specified, the exit value will be 0, else -.Ar n . -Note that other primaries will be evaluated and acted upon before exiting. +to stop traversing the file system and exit immediately, +with the specified numeric exit status. +If the +.Ar status +value is not specified, then +.Nm +will exit with status zero. +Note that any preceding primaries will be evaluated and acted upon +before exiting. +.Pp .It Ic -false This primary always evaluates to false. This can be used following a primary that caused the @@ -308,11 +340,12 @@ This can be useful after using a primary so it can continue to the next expression (using an .Cm -or operator, for example). +.Pp .It Ic -flags Oo Fl Oc Ns Ar flags If .Ar flags are preceded by a dash -.Pq Dq - , +.Pq Dq Ic \- , this primary evaluates to true if at least all of the bits in .Ar flags @@ -331,8 +364,10 @@ files with no flags bits set are matched. (See .Xr chflags 1 for more information about file flags.) +.Pp .It Ic -follow Follow symbolic links. +.Pp .It Ic -fprint Ar filename This primary always evaluates to true. This creates @@ -342,12 +377,13 @@ The file is created at startup. It writes the pathname of the current file to this file, followed by a newline character. The file will be empty if no files are matched. +.Pp .It Ic -fstype Ar type True if the file is contained in a file system of type .Ar type . The .Xr sysctl 8 -command can be used to find out the types of filesystems +command can be used to find out the types of file systems that are available on the system: .Bd -literal -offset indent sysctl vfs.generic.fstypes @@ -362,22 +398,38 @@ the .Nm is being executed, and the latter matches any file system which is mounted read-only. +.Pp .It Ic -group Ar gname True if the file belongs to the group -.Ar gname . +.Ar gname . If .Ar gname is numeric and there is no such group name, then .Ar gname is treated as a group id. +.Pp .It Ic -iname Ar pattern -True if the last component of the pathname being examined -matches +True if the last component of the pathname being examined matches +.Ar pattern +in a case-insensitive manner. +Special shell pattern matching characters +.Po +.Dq \&[ , +.Dq \&] , +.Dq \&* , +and +.Dq \&? +.Pc +may be used as part of .Ar pattern . -Case insensitive. +These characters may be matched explicitly by escaping them with a +backslash +.Pq Dq \e . +.Pp .It Ic -inum Ar n True if the file has inode number -.Ar n . +.Ar n . +.Pp .It Ic -iregex Ar regexp True if the path name of the current file matches the case-insensitive basic regular expression @@ -385,13 +437,16 @@ basic regular expression .Ar regexp . This is a match on the whole path, not a search for the regular expression within the path. +.Pp .It Ic -links Ar n True if the file has .Ar n links. +.Pp .It Ic -rm -This is an alias for +This primary is an alias for .Ic -delete . +.Pp .It Ic -ls This primary always evaluates to true. The following information for the current file is written to standard output: @@ -404,25 +459,30 @@ displayed preceded by .Dq -\*[Gt] . The format is identical to that produced by .Dq ls -dgils . +.Pp .It Ic -maxdepth Ar n True if the current search depth is less than or equal to what is specified in .Ar n . +.Pp .It Ic -mindepth Ar n True if the current search depth is at least what is specified in .Ar n . +.Pp .It Ic -mmin Ar n True if the difference between the file last modification time and the time .Nm was started, rounded up to the next full minute, is .Ar n minutes. +.Pp .It Ic -mtime Ar n True if the difference between the file last modification time and the time .Nm was started, rounded up to the next full 24-hour period, is .Ar n 24-hour periods. -.It Ic -ok Ar utility Oo argument ... Oc No ; +.Pp +.It Ic -ok Ar utility Oo argument ... Oc Ic \&; The .Ic -ok primary is similar to the semicolon-terminated @@ -431,41 +491,49 @@ variant of the .Ic -exec primary, with the exception that .Nm -requests user affirmation for the execution of the utility by printing +requests user affirmation for the execution of +.Ar utility +by printing a message to the terminal and reading a response. If the response is other than .Dq y , the command is not executed and the -.Ar -ok +.Ic -ok primary evaluates to false. Set aggregation .Pq Do \&+ Dc termination is not supported. +.Pp .It Ic -name Ar pattern True if the last component of the pathname being examined matches -.Ar pattern . +.Ar pattern . Special shell pattern matching characters .Po .Dq \&[ , .Dq \&] , .Dq \&* , +and .Dq \&? .Pc may be used as part of -.Ar pattern . +.Ar pattern . These characters may be matched explicitly by escaping them with a backslash .Pq Dq \e . +.Pp .It Ic -newer Ar file True if the current file has a more recent last modification time than -.Ar file . +.Ar file . +.Pp .It Ic -nouser True if the file belongs to an unknown user. +.Pp .It Ic -nogroup True if the file belongs to an unknown group. +.Pp .It Ic -path Ar pattern True if the pathname being examined matches -.Ar pattern . +.Ar pattern . Special shell pattern matching characters .Po .Dq \&[ , @@ -475,7 +543,7 @@ and .Dq \&? .Pc may be used as part of -.Ar pattern . +.Ar pattern . These characters may be matched explicitly by escaping them with a backslash .Pq Dq \e . @@ -483,11 +551,12 @@ Slashes .Pq Dq / are treated as normal characters and do not have to be matched explicitly. +.Pp .It Ic -perm Oo Fl Oc Ns Ar mode The .Ar mode may be either symbolic (see -.Xr chmod 1 ) +.Xr chmod 1 ) or an octal number. If the mode is symbolic, a starting value of zero is assumed and the mode sets or clears permissions without regard to the process' file mode @@ -507,41 +576,48 @@ If the mode is octal, only bits 07777 of the file's mode bits participate in the comparison. If the mode is preceded by a dash -.Pq Dq - , +.Pq Dq Ic \- , this primary evaluates to true if at least all of the bits in the mode are set in the file's mode bits. If the mode is not preceded by a dash, this primary evaluates to true if the bits in the mode exactly match the file's mode bits. Note, the first character of a symbolic mode may not be a dash -.Pq Dq - . +.Pq Dq Ic \- . +.Pp .It Ic -print This primary always evaluates to true. It prints the pathname of the current file to standard output, followed by a newline character. If none of +.Ic -delete , .Ic -exec , +.Ic -execdir , .Ic -exit , .Ic -fprint , .Ic -ls , .Ic -ok , .Ic -print0 , +.Ic -printx , nor -.Ic -printx +.Ic -rm is specified, the given expression shall be effectively replaced by .Cm \&( Ns Ar given\& expression Ns Cm \&) .Ic -print . +.Pp .It Ic -print0 This primary always evaluates to true. It prints the pathname of the current file to standard output, followed -by a null character. +by a NUL character. +.Pp .It Ic -printx This primary always evaluates to true. It prints the pathname of the current file to standard output, with each space, tab, newline, backslash, dollar sign, and single, double, or back quotation mark prefixed by a backslash, so the output of -.Nm find +.Nm can safely be used as input to -.Nm xargs . +.Xr xargs 1 . +.Pp .It Ic -prune This primary always evaluates to true. It causes @@ -552,6 +628,7 @@ Note, the primary has no effect if the .Fl d option was specified. +.Pp .It Ic -regex Ar regexp True if the path name of the current file matches the case-sensitive basic regular expression @@ -559,16 +636,18 @@ basic regular expression .Ar regexp . This is a match on the whole path, not a search for the regular expression within the path. +.Pp .It Ic -size Ar n Ns Op Cm c True if the file's size, rounded up, in 512-byte blocks is -.Ar n . +.Ar n . If .Ar n is followed by a -.Dq c , +.Dq Ic c , then the primary is true if the file's size is .Ar n bytes. +.Pp .It Ic -type Ar t True if the file is of the specified type. Possible file types are as follows: @@ -596,31 +675,22 @@ whiteout .Pp .It Ic -user Ar uname True if the file belongs to the user -.Ar uname . +.Ar uname . If .Ar uname is numeric and there is no such user name, then .Ar uname is treated as a user id (and considered a numeric argument). +.Pp .It Ic -xdev This primary always evaluates to true. It causes find not to descend past directories that have a different -device ID (st_dev, see +device ID +.Va ( st_dev , +see .Xr stat 2 S5.6.2 [POSIX.1]). .El -.Pp -All primaries which take a numeric argument allow the number to be -preceded by a plus sign -.Pq Dq + -or a minus sign -.Pq Dq \- . -A preceding plus sign means -.Dq more than n , -a preceding minus sign means -.Dq less than n , -and neither means -.Dq exactly n . .Sh OPERATORS The primaries may be combined using the following operators. The operators are listed in order of decreasing precedence. @@ -628,13 +698,11 @@ The operators are listed in order of decreasing precedence. .It Cm \&( Ar expression Cm \&) This evaluates to true if the parenthesized expression evaluates to true. -.Pp .It Cm \&! Ar expression This is the unary .Tn NOT operator. It evaluates to true if the expression is false. -.Pp .It Ar expression Cm -and Ar expression .It Ar expression expression The @@ -646,7 +714,6 @@ As it is implied by the juxtaposition of two expressions it does not have to be specified. The expression evaluates to true if both expressions are true. The second expression is not evaluated if the first expression is false. -.Pp .It Ar expression Cm -or Ar expression The .Cm -or @@ -659,49 +726,61 @@ The second expression is not evaluated if the first expression is true. .El .Pp All operands and primaries must be separate arguments to -.Nm . +.Nm . Primaries which themselves take arguments expect each argument to be a separate argument to -.Nm . +.Nm . .Sh EXIT STATUS The .Nm utility normally exits 0 on success, and exits with 1 under certain internal error conditions. -If any invokations of -.Dq Ic -exec Ar ... No + +If any invocations of +.Dq Ic -exec Ar ... Ic \&+ primaries return non-zero exit-status, then .Nm will do so as well. .Sh EXAMPLES The following examples are shown as given to the shell: .Bl -tag -width findx -.It Li "find / \e! -name \*q*.c\*q -print" +.It Li "find / \e! -name \*q*.c\*q \-print" Print out a list of all the files whose names do not end in .Dq \&.c . -.It Li "find / -newer ttt -user wnj -print" +.It Li "find / \-newer ttt \-user wnj \-print" Print out a list of all the files owned by user .Dq wnj that are newer than the file .Dq ttt . -.It Li "find / \e! \e( -newer ttt -user wnj \e) -print" +.It Li "find . \-type f \-mmin \-30 \-print \-or \-mindepth 1 \-prune" +Print out a list of all the files in the current directory that are +newer than 30 minutes. +.It Li "find . \-type f \-atime +10 \-mindepth 2 \-print" +Print out a list of all the files in any sub-directories that have not +been accessed in the past ten days. +.It Li "find . \-mtime +90 \-exec rm \-i {} + \-or \-mindepth 1 \-prune" +Interactively remove all of the files in the current directory that have +not been modified in 90 days. +.It Li "find . \-type f \-mtime +90 \-ok mv {} {}.old \e;" +Interactively rename all of the files in the current directory and all +sub-directories that have not been modified in 90 days. +.It Li "find / \e! \e( \-newer ttt \-user wnj \e) \-print" Print out a list of all the files which are not both newer than .Dq ttt and owned by .Dq wnj . -.It Li "find / \e( -newer ttt -or -user wnj \e) -print" +.It Li "find / \e( \-newer ttt \-or \-user wnj \e) \-print" Print out a list of all the files that are either owned by .Dq wnj or that are newer than .Dq ttt . -.It Li "find / \e( -newer ttt -or -user wnj \e) -exit 1" +.It Li "find / \e( \-newer ttt \-or \-user wnj \e) \-exit 1" Return immediately with a value of 1 if any files are found that are either owned by .Dq wnj or that are newer than .Dq ttt , but do not print them. -.It Li "find / \e( -newer ttt -or -user wnj \e) -ls -exit 1" +.It Li "find / \e( \-newer ttt \-or \-user wnj \e) \-ls \-exit 1" Same as above, but list the first file matching the criteria before exiting with a value of 1. .El @@ -715,6 +794,7 @@ with a value of 1. .Xr getgrent 3 , .Xr getpwent 3 , .Xr strmode 3 , +.Xr re_format 7 , .Xr symlink 7 , .Xr sysctl 8 .Sh STANDARDS @@ -757,41 +837,51 @@ Historically, the and .Fl x options were implemented using the primaries -.Dq -depth , -.Dq -follow , +.Dq Ic -depth , +.Dq Ic -follow , and -.Dq -xdev . -These primaries always evaluated to true. -As they were really global variables that took effect before the traversal -began, some legal expressions could have unexpected results. -An example is the expression -.Dq -print -o -depth . -As -print always evaluates to true, the standard order of evaluation -implies that -depth would never be evaluated. -This is not the case. -.Pp -The operator -.Dq -or +.Dq Ic -xdev . +These primaries always evaluated to true, and always +took effect when the +.Ar expression +was parsed, before the file system traversal began. +As a result, some legal expressions could be confusing. +For example, in the expression +.Dq Ic -print Ic -or Ic -depth , +.Ic -print +always evaluates to true, so the standard meaning of +.Ic -or +implies that +.Ic -depth +would never be evaluated, but that is not what happens; +in fact, +.Ic -depth +takes effect immediately, without testing whether +.Ic -print +returns true or false. +.Pp +Historically, the operator +.Dq Ic -or was implemented as -.Dq -o , +.Dq Ic -o , and the operator -.Dq -and +.Dq Ic -and was implemented as -.Dq -a . +.Dq Ic -a . .Pp Historic implementations of the -.Ic -exec +.Dq Ic -exec and -.Ic -ok +.Dq Ic -ok primaries did not replace the string -.Dq {} +.Dq Ic {} in the utility name or the -utility arguments if it had preceding or following non-whitespace characters. +utility arguments if it did not appear as a separate argument. This version replaces it no matter where in the utility name or arguments it appears. .Pp Support for -.Dq Ic -exec Ar ... No + +.Dq Ic -exec Ar ... Ic \&+ is consistent with .Em IEEE PASC Interpretation 1003.2 #210 , though the feature originated in @@ -799,11 +889,11 @@ though the feature originated in .Pp The .Ic -delete -primary does not interact well with other options that cause the filesystem +primary does not interact well with other options that cause the file system tree traversal options to be changed. .Sh HISTORY A much simpler -.Nm find +.Nm command appeared in First Edition AT\*[Am]T Unix. The syntax had become similar to the present version by the time of the Fifth Edition. diff --git a/minix/commands/find/find.c b/usr.bin/find/find.c similarity index 84% rename from minix/commands/find/find.c rename to usr.bin/find/find.c index 29126847c..2adb64e33 100644 --- a/minix/commands/find/find.c +++ b/usr.bin/find/find.c @@ -1,4 +1,4 @@ -/* $NetBSD: find.c,v 1.25 2007/09/25 04:10:12 lukem Exp $ */ +/* $NetBSD: find.c,v 1.29 2012/03/20 20:34:57 matt Exp $ */ /*- * Copyright (c) 1991, 1993, 1994 @@ -33,6 +33,13 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)find.c 8.5 (Berkeley) 8/5/94"; +#else +__RCSID("$NetBSD: find.c,v 1.29 2012/03/20 20:34:57 matt Exp $"); +#endif +#endif /* not lint */ #include #include @@ -44,13 +51,12 @@ #include #include #include +#include +#include #include "find.h" -static int ftscompare(const FTSENT * const *, const FTSENT * const *); - -static void sig_lock(sigset_t *); -static void sig_unlock(const sigset_t *); +static int ftscompare(const FTSENT **, const FTSENT **); /* * find_formplan -- @@ -141,28 +147,46 @@ find_formplan(char **argv) } static int -ftscompare(const FTSENT * const *e1, const FTSENT * const *e2) +ftscompare(const FTSENT **e1, const FTSENT **e2) { return (strcoll((*e1)->fts_name, (*e2)->fts_name)); } -static void -sig_lock(sigset_t *s) +static sigset_t ss; +static bool notty; + +static __inline void +sig_init(void) { - sigset_t new; + struct sigaction sa; + notty = !(isatty(STDIN_FILENO) || isatty(STDOUT_FILENO) || + isatty(STDERR_FILENO)); + if (notty) + return; + sigemptyset(&ss); + sigaddset(&ss, SIGINFO); /* block SIGINFO */ + + memset(&sa, 0, sizeof(sa)); + sa.sa_flags = SA_RESTART; + sa.sa_handler = show_path; + (void)sigaction(SIGINFO, &sa, NULL); - sigemptyset(&new); -#ifdef SIGINFO - sigaddset(&new, SIGINFO); /* block SIGINFO */ -#endif - sigprocmask(SIG_BLOCK, &new, s); } -static void -sig_unlock(const sigset_t *s) +static __inline void +sig_lock(sigset_t *s) { + if (notty) + return; + sigprocmask(SIG_BLOCK, &ss, s); +} +static __inline void +sig_unlock(const sigset_t *s) +{ + if (notty) + return; sigprocmask(SIG_SETMASK, s, NULL); } @@ -186,9 +210,9 @@ find_execute(PLAN *plan, char **paths) if (!(tree = fts_open(paths, ftsoptions, issort ? ftscompare : NULL))) err(1, "ftsopen"); + sig_init(); sig_lock(&s); - for (rval = 0; cval && (g_entry = fts_read(tree)) != NULL; sig_lock(&s)) { - sig_unlock(&s); + for (rval = 0; cval && (g_entry = fts_read(tree)) != NULL;) { switch (g_entry->fts_info) { case FTS_D: if (isdepth) @@ -201,17 +225,21 @@ find_execute(PLAN *plan, char **paths) case FTS_DNR: case FTS_ERR: case FTS_NS: + sig_unlock(&s); (void)fflush(stdout); warnx("%s: %s", g_entry->fts_path, strerror(g_entry->fts_errno)); rval = 1; + sig_lock(&s); continue; } #define BADCH " \t\n\\'\"" if (isxargs && strpbrk(g_entry->fts_path, BADCH)) { + sig_unlock(&s); (void)fflush(stdout); warnx("%s: illegal path", g_entry->fts_path); rval = 1; + sig_lock(&s); continue; } @@ -220,15 +248,17 @@ find_execute(PLAN *plan, char **paths) * false or all have been executed. This is where we do all * the work specified by the user on the command line. */ + sig_unlock(&s); for (p = plan; p && (p->eval)(p, g_entry); p = p->next) if (p->type == N_EXIT) { rval = p->exit_val; cval = 0; } + sig_lock(&s); } sig_unlock(&s); - if (errno) + if (g_entry == NULL && errno) err(1, "fts_read"); (void)fts_close(tree); @@ -252,10 +282,7 @@ find_execute(PLAN *plan, char **paths) * If any func() returns non-zero, then so will find_traverse(). */ int -find_traverse(plan, func, arg) - PLAN *plan; - int (*func)(PLAN *, void *); - void *arg; +find_traverse(PLAN *plan, int (*func)(PLAN *, void *), void *arg) { PLAN *p; int r, rval; diff --git a/minix/commands/find/find.h b/usr.bin/find/find.h similarity index 94% rename from minix/commands/find/find.h rename to usr.bin/find/find.h index cc2350f0c..b456c73a9 100644 --- a/minix/commands/find/find.h +++ b/usr.bin/find/find.h @@ -1,4 +1,4 @@ -/* $NetBSD: find.h,v 1.24 2007/02/06 13:25:01 elad Exp $ */ +/* $NetBSD: find.h,v 1.25 2013/05/04 06:29:32 uebayasi Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -35,18 +35,14 @@ */ #include +#include /* node type */ enum ntype { N_AND = 1, /* must start > 0 */ N_AMIN, N_ANEWER, N_ATIME, N_CLOSEPAREN, N_CMIN, N_CNEWER, N_CTIME, - N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT, N_EXPR, N_FALSE, - N_FOLLOW, N_FPRINT, -#if !defined(__minix) - N_FSTYPE, - N_FLAGS, -#endif - N_GROUP, + N_DEPTH, N_EMPTY, N_EXEC, N_EXECDIR, N_EXIT, N_EXPR, N_FALSE, N_FLAGS, + N_FOLLOW, N_FPRINT, N_FSTYPE, N_GROUP, N_INAME, N_INUM, N_IREGEX, N_LINKS, N_LS, N_MINDEPTH, N_MAXDEPTH, N_MMIN, N_MTIME, N_NAME, N_NEWER, N_NOGROUP, N_NOT, N_NOUSER, N_OK, N_OPENPAREN, N_OR, N_PATH, N_PERM, N_PRINT, N_PRINT0, N_PRINTX, @@ -66,7 +62,6 @@ typedef struct _plandata { #define F_MTFLAG 1 /* fstype */ #define F_MTTYPE 2 #define F_ATLEAST 1 /* perm */ -#define F_ANY 2 /* perm */ int flags; /* private flags */ enum ntype type; /* plan node type */ union { @@ -77,6 +72,7 @@ typedef struct _plandata { nlink_t _l_data; /* link count */ off_t _o_data; /* file size */ time_t _t_data; /* time value */ + struct timespec _ts_data; /* time value */ uid_t _u_data; /* uid */ short _mt_data; /* mount flags */ struct _plandata *_p_data[2]; /* PLAN trees */ @@ -112,6 +108,7 @@ typedef struct _plandata { #define o_data p_un._o_data #define p_data p_un._p_data #define t_data p_un._t_data +#define ts_data p_un._ts_data #define u_data p_un._u_data #define e_argv p_un.ex._e_argv #define e_orig p_un.ex._e_orig diff --git a/minix/commands/find/function.c b/usr.bin/find/function.c similarity index 94% rename from minix/commands/find/function.c rename to usr.bin/find/function.c index fea457900..c4b563cff 100644 --- a/minix/commands/find/function.c +++ b/usr.bin/find/function.c @@ -1,4 +1,4 @@ -/* $NetBSD: function.c,v 1.64 2007/07/19 07:49:30 daniel Exp $ */ +/* $NetBSD: function.c,v 1.72 2013/05/04 06:29:32 uebayasi Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -33,6 +33,13 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)function.c 8.10 (Berkeley) 5/4/95"; +#else +__RCSID("$NetBSD: function.c,v 1.72 2013/05/04 06:29:32 uebayasi Exp $"); +#endif +#endif /* not lint */ #include #include @@ -48,21 +55,16 @@ #include #include #include -#include +#include #include #include #include #include #include #include -#include #include "find.h" -typedef int bool; -#define false 0 -#define true 1 - #define COMPARE(a, b) { \ switch (plan->flags) { \ case F_EQUAL: \ @@ -76,7 +78,7 @@ typedef int bool; } \ } -static int32_t find_parsenum(PLAN *, const char *, const char *, char *); +static int64_t find_parsenum(PLAN *, const char *, const char *, char *); static void run_f_exec(PLAN *); int f_always_true(PLAN *, FTSENT *); int f_amin(PLAN *, FTSENT *); @@ -129,10 +131,10 @@ extern time_t now; * find_parsenum -- * Parse a string of the form [+-]# and return the value. */ -static int32_t +static int64_t find_parsenum(PLAN *plan, const char *option, const char *vp, char *endch) { - int32_t value; + int64_t value; const char *str; char *endchar; /* Pointer to character ending conversion. */ @@ -157,7 +159,7 @@ find_parsenum(PLAN *plan, const char *option, const char *vp, char *endch) * and endchar points to the beginning of the string we know we have * a syntax error. */ - value = strtol(str, &endchar, 10); + value = strtoq(str, &endchar, 10); if (value == 0 && endchar == str) errx(1, "%s: %s: illegal numeric value", option, vp); if (endchar[0] && (endch == NULL || endchar[0] != *endch)) @@ -213,12 +215,10 @@ c_amin(char ***argvp, int isok) * file. */ int -f_anewer(plan, entry) - PLAN *plan; - FTSENT *entry; +f_anewer(PLAN *plan, FTSENT *entry) { - return (entry->fts_statp->st_atime > plan->t_data); + return timespeccmp(&entry->fts_statp->st_atim, &plan->ts_data, >); } PLAN * @@ -234,7 +234,7 @@ c_anewer(char ***argvp, int isok) if (stat(filename, &sb)) err(1, "%s", filename); new = palloc(N_ANEWER, f_anewer); - new->t_data = sb.st_atime; + new->ts_data = sb.st_atim; return (new); } @@ -265,6 +265,7 @@ c_atime(char ***argvp, int isok) TIME_CORRECT(new, N_ATIME); return (new); } + /* * -cmin n functions -- * @@ -304,7 +305,7 @@ int f_cnewer(PLAN *plan, FTSENT *entry) { - return (entry->fts_statp->st_ctime > plan->t_data); + return timespeccmp(&entry->fts_statp->st_ctim, &plan->ts_data, >); } PLAN * @@ -320,7 +321,7 @@ c_cnewer(char ***argvp, int isok) if (stat(filename, &sb)) err(1, "%s", filename); new = palloc(N_CNEWER, f_cnewer); - new->t_data = sb.st_ctime; + new->ts_data = sb.st_ctim; return (new); } @@ -355,7 +356,7 @@ c_ctime(char ***argvp, int isok) /* * -delete functions -- * - * True always. Makes its best shot and continues on regardless. + * Always true. Makes its best shot and continues on regardless. */ int f_delete(PLAN *plan __unused, FTSENT *entry) @@ -377,14 +378,14 @@ f_delete(PLAN *plan __unused, FTSENT *entry) errx(1, "-delete: %s: relative path potentially not safe", entry->fts_accpath); -#if !defined(__minix) +#ifndef __minix /* 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) chflags(entry->fts_accpath, entry->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE)); -#endif +#endif /* !__minix */ /* rmdir directories, unlink everything else */ if (S_ISDIR(entry->fts_statp->st_mode)) { @@ -453,7 +454,7 @@ f_empty(PLAN *plan, FTSENT *entry) empty = 1; dir = opendir(entry->fts_accpath); if (dir == NULL) - err(1, "%s", entry->fts_accpath); + return (0); for (dp = readdir(dir); dp; dp = readdir(dir)) if (dp->d_name[0] != '.' || (dp->d_name[1] != '\0' && @@ -499,7 +500,8 @@ c_empty(char ***argvp, int isok) int f_exec(PLAN *plan, FTSENT *entry) { - int cnt, l; + size_t cnt; + int l; pid_t pid; int status; @@ -545,9 +547,9 @@ f_exec(PLAN *plan, FTSENT *entry) fflush(stdout); fflush(stderr); - switch (pid = fork()) { + switch (pid = vfork()) { case -1: - err(1, "fork"); + err(1, "vfork"); /* NOTREACHED */ case 0: if (fchdir(dotfd)) { @@ -577,9 +579,9 @@ run_f_exec(PLAN *plan) fflush(stdout); fflush(stderr); - switch (pid = fork()) { + switch (pid = vfork()) { case -1: - err(1, "fork"); + err(1, "vfork"); /* NOTREACHED */ case 0: if (fchdir(dotfd)) { @@ -627,7 +629,8 @@ PLAN * c_exec(char ***argvp, int isok) { PLAN *new; /* node returned */ - int cnt, brace, lastbrace; + size_t cnt; + int brace, lastbrace; char **argv, **ap, *p; isoutput = 1; @@ -637,8 +640,8 @@ c_exec(char ***argvp, int isok) new->flags |= F_NEEDOK; /* - * Terminate if we encounter an arg exacty equal to ";", or an - * arg exacty equal to "+" following an arg exacty equal to + * Terminate if we encounter an arg exactly equal to ";", or an + * arg exactly equal to "+" following an arg exactly equal to * "{}". */ for (ap = argv = *argvp, brace = 0;; ++ap) { @@ -646,6 +649,7 @@ c_exec(char ***argvp, int isok) errx(1, "%s: no terminating \";\" or \"+\"", isok ? "-ok" : "-exec"); lastbrace = brace; + brace = 0; if (strcmp(*ap, "{}") == 0) brace = 1; if (strcmp(*ap, ";") == 0) @@ -664,12 +668,12 @@ c_exec(char ***argvp, int isok) errx(1, "-ok: terminating \"+\" not permitted."); if (new->flags & F_PLUSSET) { - u_int c, bufsize; + size_t c, bufsize; cnt = ap - *argvp - 1; /* units are words */ new->ep_maxargs = 5000; - new->e_argv = (char **)emalloc((u_int)(cnt + new->ep_maxargs) - * sizeof(char **)); + new->e_argv = emalloc((cnt + new->ep_maxargs) + * sizeof(*new->e_argv)); /* We start stuffing arguments after the user's last one. */ new->ep_bxp = &new->e_argv[cnt]; @@ -679,34 +683,36 @@ c_exec(char ***argvp, int isok) * Count up the space of the user's arguments, and * subtract that from what we allocate. */ +#define MAXARG (ARG_MAX - 4 * 1024) for (argv = *argvp, c = 0, cnt = 0; argv < ap; ++argv, ++cnt) { c += strlen(*argv) + 1; + if (c >= MAXARG) + errx(1, "Arguments too long"); new->e_argv[cnt] = *argv; } - bufsize = ARG_MAX - 4 * 1024 - c; - + bufsize = MAXARG - c; /* * Allocate, and then initialize current, base, and * end pointers. */ - new->ep_p = new->ep_bbp = malloc(bufsize + 1); + new->ep_p = new->ep_bbp = emalloc(bufsize + 1); new->ep_ebp = new->ep_bbp + bufsize - 1; new->ep_rval = 0; } else { /* !F_PLUSSET */ cnt = ap - *argvp + 1; - new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *)); - new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *)); - new->e_len = (int *)emalloc((u_int)cnt * sizeof(int)); + new->e_argv = emalloc(cnt * sizeof(*new->e_argv)); + new->e_orig = emalloc(cnt * sizeof(*new->e_orig)); + new->e_len = emalloc(cnt * sizeof(*new->e_len)); for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) { new->e_orig[cnt] = *argv; for (p = *argv; *p; ++p) if (p[0] == '{' && p[1] == '}') { new->e_argv[cnt] = - emalloc((u_int)MAXPATHLEN); + emalloc(MAXPATHLEN); new->e_len[cnt] = MAXPATHLEN; break; } @@ -735,7 +741,7 @@ c_exec(char ***argvp, int isok) int f_execdir(PLAN *plan, FTSENT *entry) { - int cnt; + size_t cnt; pid_t pid; int status; char *file; @@ -755,7 +761,7 @@ f_execdir(PLAN *plan, FTSENT *entry) fflush(stdout); fflush(stderr); - switch (pid = fork()) { + switch (pid = vfork()) { case -1: err(1, "fork"); /* NOTREACHED */ @@ -779,7 +785,7 @@ PLAN * c_execdir(char ***argvp, int isok) { PLAN *new; /* node returned */ - int cnt; + size_t cnt; char **argv, **ap, *p; ftsoptions &= ~FTS_NOSTAT; @@ -796,15 +802,15 @@ c_execdir(char ***argvp, int isok) } cnt = ap - *argvp + 1; - new->e_argv = (char **)emalloc((u_int)cnt * sizeof(char *)); - new->e_orig = (char **)emalloc((u_int)cnt * sizeof(char *)); - new->e_len = (int *)emalloc((u_int)cnt * sizeof(int)); + new->e_argv = emalloc(cnt * sizeof(*new->e_argv)); + new->e_orig = emalloc(cnt * sizeof(*new->e_orig)); + new->e_len = emalloc(cnt * sizeof(*new->e_len)); for (argv = *argvp, cnt = 0; argv < ap; ++argv, ++cnt) { new->e_orig[cnt] = *argv; for (p = *argv; *p; ++p) if (p[0] == '{' && p[1] == '}') { - new->e_argv[cnt] = emalloc((u_int)MAXPATHLEN); + new->e_argv[cnt] = emalloc(MAXPATHLEN); new->e_len[cnt] = MAXPATHLEN; break; } @@ -857,7 +863,6 @@ c_false(char ***argvp, int isok) } -#if !defined(__minix) /* * -flags [-]flags functions -- */ @@ -871,8 +876,6 @@ f_flags(PLAN *plan, FTSENT *entry) return ((plan->f_data | flags) == flags); else return (flags == plan->f_data); - /* MINIX has no file flags. */ - return 0; /* NOTREACHED */ } @@ -900,7 +903,6 @@ c_flags(char ***argvp, int isok) new->f_data = flagset; return (new); } -#endif /* * -follow functions -- @@ -955,7 +957,6 @@ c_fprint(char ***argvp, int isok) * * True if the file is of a certain type. */ -#if !defined(__minix) int f_fstype(PLAN *plan, FTSENT *entry) { @@ -1049,7 +1050,6 @@ c_fstype(char ***argvp, int isok) new->c_data = arg; return (new); } -#endif /* * -group gname functions -- @@ -1215,6 +1215,7 @@ c_mindepth(char ***argvp, int isok) new->min_data = atoi(arg); return (new); } + /* * -mmin n functions -- * @@ -1242,6 +1243,7 @@ c_mmin(char ***argvp, int isok) TIME_CORRECT(new, N_MMIN); return (new); } + /* * -mtime n functions -- * @@ -1330,7 +1332,7 @@ int f_newer(PLAN *plan, FTSENT *entry) { - return (entry->fts_statp->st_mtime > plan->t_data); + return timespeccmp(&entry->fts_statp->st_mtim, &plan->ts_data, >); } PLAN * @@ -1346,7 +1348,7 @@ c_newer(char ***argvp, int isok) if (stat(filename, &sb)) err(1, "%s", filename); new = palloc(N_NEWER, f_newer); - new->t_data = sb.st_mtime; + new->ts_data = sb.st_mtim; return (new); } @@ -1430,15 +1432,9 @@ f_perm(PLAN *plan, FTSENT *entry) mode_t mode; mode = entry->fts_statp->st_mode & - (S_ISUID|S_ISGID -#ifdef S_ISTXT - |S_ISTXT -#endif - |S_IRWXU|S_IRWXG|S_IRWXO); + (S_ISUID|S_ISGID|S_ISTXT|S_IRWXU|S_IRWXG|S_IRWXO); if (plan->flags == F_ATLEAST) return ((plan->m_data | mode) == mode); - else if (plan->flags == F_ANY) - return ((plan->m_data & mode) != 0); else return (mode == plan->m_data); /* NOTREACHED */ @@ -1459,9 +1455,6 @@ c_perm(char ***argvp, int isok) if (*perm == '-') { new->flags = F_ATLEAST; ++perm; - } else if (*perm == '+') { - new->flags = F_ANY; - ++perm; } if ((set = setmode(perm)) == NULL) @@ -1577,7 +1570,7 @@ f_regex(PLAN *plan, FTSENT *entry) static PLAN * c_regex_common(char ***argvp, int isok, enum ntype type, bool icase) { - char errbuf[100]; + char errbuf[LINE_MAX]; regex_t reg; char *regexp = **argvp; char *lineregexp; @@ -1702,11 +1695,9 @@ c_type(char ***argvp, int isok) case 'p': mask = S_IFIFO; break; -#ifdef S_IFSOCK case 's': mask = S_IFSOCK; break; -#endif #ifdef S_IFWHT case 'W': case 'w': diff --git a/minix/commands/find/ls.c b/usr.bin/find/ls.c similarity index 77% rename from minix/commands/find/ls.c rename to usr.bin/find/ls.c index 3077c5745..23b7cfe67 100644 --- a/minix/commands/find/ls.c +++ b/usr.bin/find/ls.c @@ -1,4 +1,4 @@ -/* $NetBSD: ls.c,v 1.19 2006/10/11 19:51:10 apb Exp $ */ +/* $NetBSD: ls.c,v 1.21 2011/08/31 16:24:57 plunky Exp $ */ /* * Copyright (c) 1989, 1993 @@ -30,6 +30,13 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)ls.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: ls.c,v 1.21 2011/08/31 16:24:57 plunky Exp $"); +#endif +#endif /* not lint */ #include #include @@ -45,10 +52,6 @@ #include #include #include -#include -#include -#include -#include #include "find.h" @@ -63,40 +66,20 @@ printlong(char *name, /* filename to print */ struct stat *sb) /* stat buffer */ { char modep[15]; - static dev_t dev; - static int blocksize = 0; - long blocks = -1; - - if(!blocksize || sb->st_dev != dev) { - int fd; - struct statfs fs; - blocksize = 0; - if((fd = open(name, O_RDONLY)) >= 0) { - if(fstatfs(fd, &fs) >= 0) { - blocksize = fs.f_bsize; - } - close(fd); - } - } - if(blocksize > 0) - blocks = ((long)sb->st_size+blocksize-1)/blocksize; - - (void)printf("%7lu ", (u_long)sb->st_ino); - if(blocks >= 0) - (void)printf("%6ld ", blocks); - else - (void)printf("? "); + (void)printf("%7lu %6lld ", (u_long)sb->st_ino, + (long long)sb->st_blocks); (void)strmode(sb->st_mode, modep); - (void)printf("%s %3lu %-10s %-10s ", modep, (unsigned long)sb->st_nlink, - user_from_uid(sb->st_uid, 0), + (void)printf("%s %3lu %-*s %-*s ", modep, (unsigned long)sb->st_nlink, + LOGIN_NAME_MAX, user_from_uid(sb->st_uid, 0), LOGIN_NAME_MAX, group_from_gid(sb->st_gid, 0)); if (S_ISCHR(sb->st_mode) || S_ISBLK(sb->st_mode)) - (void)printf("%3d,%5d ", major(sb->st_rdev), - minor(sb->st_rdev)); + (void)printf("%3llu,%5llu ", + (unsigned long long)major(sb->st_rdev), + (unsigned long long)minor(sb->st_rdev)); else - (void)printf("%9ld ", (long)sb->st_size); + (void)printf("%9lld ", (long long)sb->st_size); printtime(sb->st_mtime); (void)printf("%s", name); if (S_ISLNK(sb->st_mode)) @@ -115,7 +98,7 @@ printtime(time_t ftime) (void)putchar(longstring[i]); #define SIXMONTHS ((DAYSPERNYEAR / 2) * SECSPERDAY) - if (ftime + SIXMONTHS > time((time_t *)NULL)) + if (ftime + SIXMONTHS > time(NULL)) for (i = 11; i < 16; ++i) (void)putchar(longstring[i]); else { diff --git a/minix/commands/find/main.c b/usr.bin/find/main.c similarity index 88% rename from minix/commands/find/main.c rename to usr.bin/find/main.c index 7fe413920..5aab17761 100644 --- a/minix/commands/find/main.c +++ b/usr.bin/find/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.28 2008/07/21 14:19:22 lukem Exp $ */ +/* $NetBSD: main.c,v 1.31 2013/01/24 17:50:08 christos Exp $ */ /*- * Copyright (c) 1990, 1993, 1994 @@ -33,6 +33,15 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "@(#)main.c 8.4 (Berkeley) 5/4/95"; +#else +__COPYRIGHT("@(#) Copyright (c) 1990, 1993, 1994\ + The Regents of the University of California. All rights reserved."); +__RCSID("$NetBSD: main.c,v 1.31 2013/01/24 17:50:08 christos Exp $"); +#endif +#endif /* not lint */ #include #include @@ -41,7 +50,6 @@ #include #include #include -#include #include #include #include @@ -61,26 +69,17 @@ int issort; /* sort directory entries */ int isxargs; /* don't permit xargs delimiting chars */ int regcomp_flags = REG_BASIC; /* regex compilation flags */ -int main(int, char **); -static void usage(void); +__dead static void usage(void); int main(int argc, char *argv[]) { - struct sigaction sa; char **p, **start; int ch; (void)time(&now); /* initialize the time-of-day */ (void)setlocale(LC_ALL, ""); - memset(&sa, 0, sizeof(sa)); - sa.sa_flags = SA_RESTART; - sa.sa_handler = show_path; -#ifdef SIGINFO - sigaction(SIGINFO, &sa, NULL); -#endif - /* array to hold dir list. at most (argc - 1) elements. */ p = start = malloc(argc * sizeof (char *)); if (p == NULL) @@ -149,8 +148,7 @@ main(int argc, char *argv[]) *p = NULL; - if ((dotfd = open(".", O_RDONLY, 0)) == -1 || - fcntl(dotfd, F_SETFD, FD_CLOEXEC) == -1) + if ((dotfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) err(1, "."); exit(find_execute(find_formplan(argv), start)); @@ -160,7 +158,7 @@ static void usage(void) { - (void)fprintf(stderr, -"usage: find [-H | -L | -P] [-dEhsXx] [-f file] file [file ...] [expression]\n"); + (void)fprintf(stderr, "Usage: %s [-H | -L | -P] [-dEhsXx] [-f file] " + "file [file ...] [expression]\n", getprogname()); exit(1); } diff --git a/minix/commands/find/misc.c b/usr.bin/find/misc.c similarity index 95% rename from minix/commands/find/misc.c rename to usr.bin/find/misc.c index 24bd49f3d..8ba84c0a2 100644 --- a/minix/commands/find/misc.c +++ b/usr.bin/find/misc.c @@ -33,6 +33,13 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)misc.c 8.2 (Berkeley) 4/1/94"; +#else +__RCSID("$NetBSD: misc.c,v 1.14 2006/10/11 19:51:10 apb Exp $"); +#endif +#endif /* not lint */ #include #include diff --git a/minix/commands/find/operator.c b/usr.bin/find/operator.c similarity index 97% rename from minix/commands/find/operator.c rename to usr.bin/find/operator.c index 5ed5c6414..19e8cb97e 100644 --- a/minix/commands/find/operator.c +++ b/usr.bin/find/operator.c @@ -33,6 +33,14 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)operator.c 8.1 (Berkeley) 6/6/93"; +#else +__RCSID("$NetBSD: operator.c,v 1.9 2006/10/11 19:51:10 apb Exp $"); +#endif +#endif /* not lint */ + #include #include diff --git a/minix/commands/find/option.c b/usr.bin/find/option.c similarity index 96% rename from minix/commands/find/option.c rename to usr.bin/find/option.c index f30f7d8ce..b827ab200 100644 --- a/minix/commands/find/option.c +++ b/usr.bin/find/option.c @@ -33,6 +33,13 @@ */ #include +#ifndef lint +#if 0 +static char sccsid[] = "from: @(#)option.c 8.2 (Berkeley) 4/16/94"; +#else +__RCSID("$NetBSD: option.c,v 1.26 2007/02/06 15:33:22 perry Exp $"); +#endif +#endif /* not lint */ #include #include @@ -68,12 +75,10 @@ static OPTION const options[] = { { "-execdir", N_EXECDIR, c_execdir, 1 }, { "-exit", N_EXIT, c_exit, 0 }, { "-false", N_FALSE, c_false, 0 }, + { "-flags", N_FLAGS, c_flags, 1 }, { "-follow", N_FOLLOW, c_follow, 0 }, { "-fprint", N_FPRINT, c_fprint, 1 }, -#if !defined(__minix) - { "-flags", N_FLAGS, c_flags, 1 }, { "-fstype", N_FSTYPE, c_fstype, 1 }, -#endif { "-group", N_GROUP, c_group, 1 }, { "-iname", N_INAME, c_iname, 1 }, { "-inum", N_INUM, c_inum, 1 },