diff --git a/src/bin/findutils/COPYING b/src/bin/findutils/COPYING
index a43ea2126f..4432540474 100644
--- a/src/bin/findutils/COPYING
+++ b/src/bin/findutils/COPYING
@@ -1,285 +1,627 @@
- GNU GENERAL PUBLIC LICENSE
- Version 2, June 1991
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
- 675 Mass Ave, Cambridge, MA 02139, USA
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
- The licenses for most software are designed to take away your
-freedom to share and change it. By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users. This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it. (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.) You can apply it to
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
+
+ The licenses for most software and other practical works are designed
+to take away your freedom to share and change the works. By contrast,
+the GNU General Public License is intended to guarantee your freedom to
+share and change all versions of a program--to make sure it remains free
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
+them if you wish), that you receive source code or can get it if you
+want it, that you can change the software or use pieces of it in new
+free programs, and that you know you can do these things.
- To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have. You must make sure that they, too, receive or can get the
-source code. And you must show them these terms so they know their
-rights.
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
- We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
- Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software. If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
- Finally, any free program is threatened constantly by software
-patents. We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary. To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
-
- GNU GENERAL PUBLIC LICENSE
- TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
- 0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License. The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language. (Hereinafter, translation is included without limitation in
-the term "modification".) Each licensee is addressed as "you".
+ TERMS AND CONDITIONS
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope. The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
+ 0. Definitions.
- 1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
+ "This License" refers to version 3 of the GNU General Public License.
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
+ "Copyright" also means copyright-like laws that apply to other kinds of
+works, such as semiconductor masks.
+
+ "The Program" refers to any copyrightable work licensed under this
+License. Each licensee is addressed as "you". "Licensees" and
+"recipients" may be individuals or organizations.
- 2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
+ To "modify" a work means to copy from or adapt all or part of the work
+in a fashion requiring copyright permission, other than the making of an
+exact copy. The resulting work is called a "modified version" of the
+earlier work or a work "based on" the earlier work.
- a) You must cause the modified files to carry prominent notices
- stating that you changed the files and the date of any change.
+ A "covered work" means either the unmodified Program or a work based
+on the Program.
- b) You must cause any work that you distribute or publish, that in
- whole or in part contains or is derived from the Program or any
- part thereof, to be licensed as a whole at no charge to all third
- parties under the terms of this License.
+ To "propagate" a work means to do anything with it that, without
+permission, would make you directly or secondarily liable for
+infringement under applicable copyright law, except executing it on a
+computer or modifying a private copy. Propagation includes copying,
+distribution (with or without modification), making available to the
+public, and in some countries other activities as well.
- c) If the modified program normally reads commands interactively
- when run, you must cause it, when started running for such
- interactive use in the most ordinary way, to print or display an
- announcement including an appropriate copyright notice and a
- notice that there is no warranty (or else, saying that you provide
- a warranty) and that users may redistribute the program under
- these conditions, and telling the user how to view a copy of this
- License. (Exception: if the Program itself is interactive but
- does not normally print such an announcement, your work based on
- the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole. If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works. But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
+ To "convey" a work means any kind of propagation that enables other
+parties to make or receive copies. Mere interaction with a user through
+a computer network, with no transfer of a copy, is not conveying.
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
+ An interactive user interface displays "Appropriate Legal Notices"
+to the extent that it includes a convenient and prominently visible
+feature that (1) displays an appropriate copyright notice, and (2)
+tells the user that there is no warranty for the work (except to the
+extent that warranties are provided), that licensees may convey the
+work under this License, and how to view a copy of this License. If
+the interface presents a list of user commands or options, such as a
+menu, a prominent item in the list meets this criterion.
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
+ 1. Source Code.
- 3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
+ The "source code" for a work means the preferred form of the work
+for making modifications to it. "Object code" means any non-source
+form of a work.
- a) Accompany it with the complete corresponding machine-readable
- source code, which must be distributed under the terms of Sections
- 1 and 2 above on a medium customarily used for software interchange; or,
+ A "Standard Interface" means an interface that either is an official
+standard defined by a recognized standards body, or, in the case of
+interfaces specified for a particular programming language, one that
+is widely used among developers working in that language.
- b) Accompany it with a written offer, valid for at least three
- years, to give any third party, for a charge no more than your
- cost of physically performing source distribution, a complete
- machine-readable copy of the corresponding source code, to be
- distributed under the terms of Sections 1 and 2 above on a medium
- customarily used for software interchange; or,
+ The "System Libraries" of an executable work include anything, other
+than the work as a whole, that (a) is included in the normal form of
+packaging a Major Component, but which is not part of that Major
+Component, and (b) serves only to enable use of the work with that
+Major Component, or to implement a Standard Interface for which an
+implementation is available to the public in source code form. A
+"Major Component", in this context, means a major essential component
+(kernel, window system, and so on) of the specific operating system
+(if any) on which the executable work runs, or a compiler used to
+produce the work, or an object code interpreter used to run it.
- c) Accompany it with the information you received as to the offer
- to distribute corresponding source code. (This alternative is
- allowed only for noncommercial distribution and only if you
- received the program in object code or executable form with such
- an offer, in accord with Subsection b above.)
+ The "Corresponding Source" for a work in object code form means all
+the source code needed to generate, install, and (for an executable
+work) run the object code and to modify the work, including scripts to
+control those activities. However, it does not include the work's
+System Libraries, or general-purpose tools or generally available free
+programs which are used unmodified in performing those activities but
+which are not part of the work. For example, Corresponding Source
+includes interface definition files associated with source files for
+the work, and the source code for shared libraries and dynamically
+linked subprograms that the work is specifically designed to require,
+such as by intimate data communication or control flow between those
+subprograms and other parts of the work.
-The source code for a work means the preferred form of the work for
-making modifications to it. For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable. However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
+ The Corresponding Source need not include anything that users
+can regenerate automatically from other parts of the Corresponding
+Source.
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
- 4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License. Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
+ The Corresponding Source for a work in source code form is that
+same work.
- 5. You are not required to accept this License, since you have not
-signed it. However, nothing else grants you permission to modify or
-distribute the Program or its derivative works. These actions are
-prohibited by law if you do not accept this License. Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
+ 2. Basic Permissions.
- 6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions. You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
+ All rights granted under this License are granted for the term of
+copyright on the Program, and are irrevocable provided the stated
+conditions are met. This License explicitly affirms your unlimited
+permission to run the unmodified Program. The output from running a
+covered work is covered by this License only if the output, given its
+content, constitutes a covered work. This License acknowledges your
+rights of fair use or other equivalent, as provided by copyright law.
+
+ You may make, run and propagate covered works that you do not
+convey, without conditions so long as your license otherwise remains
+in force. You may convey covered works to others for the sole purpose
+of having them make modifications exclusively for you, or provide you
+with facilities for running those works, provided that you comply with
+the terms of this License in conveying all material for which you do
+not control copyright. Those thus making or running the covered works
+for you must do so exclusively on your behalf, under your direction
+and control, on terms that prohibit them from making any copies of
+your copyrighted material outside their relationship with you.
+
+ Conveying under any other circumstances is permitted solely under
+the conditions stated below. Sublicensing is not allowed; section 10
+makes it unnecessary.
+
+ 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
+
+ No covered work shall be deemed part of an effective technological
+measure under any applicable law fulfilling obligations under article
+11 of the WIPO copyright treaty adopted on 20 December 1996, or
+similar laws prohibiting or restricting circumvention of such
+measures.
+
+ When you convey a covered work, you waive any legal power to forbid
+circumvention of technological measures to the extent such circumvention
+is effected by exercising rights under this License with respect to
+the covered work, and you disclaim any intention to limit operation or
+modification of the work as a means of enforcing, against the work's
+users, your or third parties' legal rights to forbid circumvention of
+technological measures.
+
+ 4. Conveying Verbatim Copies.
+
+ You may convey verbatim copies of the Program's source code as you
+receive it, in any medium, provided that you conspicuously and
+appropriately publish on each copy an appropriate copyright notice;
+keep intact all notices stating that this License and any
+non-permissive terms added in accord with section 7 apply to the code;
+keep intact all notices of the absence of any warranty; and give all
+recipients a copy of this License along with the Program.
+
+ You may charge any price or no price for each copy that you convey,
+and you may offer support or warranty protection for a fee.
+
+ 5. Conveying Modified Source Versions.
+
+ You may convey a work based on the Program, or the modifications to
+produce it from the Program, in the form of source code under the
+terms of section 4, provided that you also meet all of these conditions:
+
+ a) The work must carry prominent notices stating that you modified
+ it, and giving a relevant date.
+
+ b) The work must carry prominent notices stating that it is
+ released under this License and any conditions added under section
+ 7. This requirement modifies the requirement in section 4 to
+ "keep intact all notices".
+
+ c) You must license the entire work, as a whole, under this
+ License to anyone who comes into possession of a copy. This
+ License will therefore apply, along with any applicable section 7
+ additional terms, to the whole of the work, and all its parts,
+ regardless of how they are packaged. This License gives no
+ permission to license the work in any other way, but it does not
+ invalidate such permission if you have separately received it.
+
+ d) If the work has interactive user interfaces, each must display
+ Appropriate Legal Notices; however, if the Program has interactive
+ interfaces that do not display Appropriate Legal Notices, your
+ work need not make them do so.
+
+ A compilation of a covered work with other separate and independent
+works, which are not by their nature extensions of the covered work,
+and which are not combined with it such as to form a larger program,
+in or on a volume of a storage or distribution medium, is called an
+"aggregate" if the compilation and its resulting copyright are not
+used to limit the access or legal rights of the compilation's users
+beyond what the individual works permit. Inclusion of a covered work
+in an aggregate does not cause this License to apply to the other
+parts of the aggregate.
+
+ 6. Conveying Non-Source Forms.
+
+ You may convey a covered work in object code form under the terms
+of sections 4 and 5, provided that you also convey the
+machine-readable Corresponding Source under the terms of this License,
+in one of these ways:
+
+ a) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by the
+ Corresponding Source fixed on a durable physical medium
+ customarily used for software interchange.
+
+ b) Convey the object code in, or embodied in, a physical product
+ (including a physical distribution medium), accompanied by a
+ written offer, valid for at least three years and valid for as
+ long as you offer spare parts or customer support for that product
+ model, to give anyone who possesses the object code either (1) a
+ copy of the Corresponding Source for all the software in the
+ product that is covered by this License, on a durable physical
+ medium customarily used for software interchange, for a price no
+ more than your reasonable cost of physically performing this
+ conveying of source, or (2) access to copy the
+ Corresponding Source from a network server at no charge.
+
+ c) Convey individual copies of the object code with a copy of the
+ written offer to provide the Corresponding Source. This
+ alternative is allowed only occasionally and noncommercially, and
+ only if you received the object code with such an offer, in accord
+ with subsection 6b.
+
+ d) Convey the object code by offering access from a designated
+ place (gratis or for a charge), and offer equivalent access to the
+ Corresponding Source in the same way through the same place at no
+ further charge. You need not require recipients to copy the
+ Corresponding Source along with the object code. If the place to
+ copy the object code is a network server, the Corresponding Source
+ may be on a different server (operated by you or a third party)
+ that supports equivalent copying facilities, provided you maintain
+ clear directions next to the object code saying where to find the
+ Corresponding Source. Regardless of what server hosts the
+ Corresponding Source, you remain obligated to ensure that it is
+ available for as long as needed to satisfy these requirements.
+
+ e) Convey the object code using peer-to-peer transmission, provided
+ you inform other peers where the object code and Corresponding
+ Source of the work are being offered to the general public at no
+ charge under subsection 6d.
+
+ A separable portion of the object code, whose source code is excluded
+from the Corresponding Source as a System Library, need not be
+included in conveying the object code work.
+
+ A "User Product" is either (1) a "consumer product", which means any
+tangible personal property which is normally used for personal, family,
+or household purposes, or (2) anything designed or sold for incorporation
+into a dwelling. In determining whether a product is a consumer product,
+doubtful cases shall be resolved in favor of coverage. For a particular
+product received by a particular user, "normally used" refers to a
+typical or common use of that class of product, regardless of the status
+of the particular user or of the way in which the particular user
+actually uses, or expects or is expected to use, the product. A product
+is a consumer product regardless of whether the product has substantial
+commercial, industrial or non-consumer uses, unless such uses represent
+the only significant mode of use of the product.
+
+ "Installation Information" for a User Product means any methods,
+procedures, authorization keys, or other information required to install
+and execute modified versions of a covered work in that User Product from
+a modified version of its Corresponding Source. The information must
+suffice to ensure that the continued functioning of the modified object
+code is in no case prevented or interfered with solely because
+modification has been made.
+
+ If you convey an object code work under this section in, or with, or
+specifically for use in, a User Product, and the conveying occurs as
+part of a transaction in which the right of possession and use of the
+User Product is transferred to the recipient in perpetuity or for a
+fixed term (regardless of how the transaction is characterized), the
+Corresponding Source conveyed under this section must be accompanied
+by the Installation Information. But this requirement does not apply
+if neither you nor any third party retains the ability to install
+modified object code on the User Product (for example, the work has
+been installed in ROM).
+
+ The requirement to provide Installation Information does not include a
+requirement to continue to provide support service, warranty, or updates
+for a work that has been modified or installed by the recipient, or for
+the User Product in which it has been modified or installed. Access to a
+network may be denied when the modification itself materially and
+adversely affects the operation of the network or violates the rules and
+protocols for communication across the network.
+
+ Corresponding Source conveyed, and Installation Information provided,
+in accord with this section must be in a format that is publicly
+documented (and with an implementation available to the public in
+source code form), and must require no special password or key for
+unpacking, reading or copying.
+
+ 7. Additional Terms.
+
+ "Additional permissions" are terms that supplement the terms of this
+License by making exceptions from one or more of its conditions.
+Additional permissions that are applicable to the entire Program shall
+be treated as though they were included in this License, to the extent
+that they are valid under applicable law. If additional permissions
+apply only to part of the Program, that part may be used separately
+under those permissions, but the entire Program remains governed by
+this License without regard to the additional permissions.
+
+ When you convey a copy of a covered work, you may at your option
+remove any additional permissions from that copy, or from any part of
+it. (Additional permissions may be written to require their own
+removal in certain cases when you modify the work.) You may place
+additional permissions on material, added by you to a covered work,
+for which you have or can give appropriate copyright permission.
+
+ Notwithstanding any other provision of this License, for material you
+add to a covered work, you may (if authorized by the copyright holders of
+that material) supplement the terms of this License with terms:
+
+ a) Disclaiming warranty or limiting liability differently from the
+ terms of sections 15 and 16 of this License; or
+
+ b) Requiring preservation of specified reasonable legal notices or
+ author attributions in that material or in the Appropriate Legal
+ Notices displayed by works containing it; or
+
+ c) Prohibiting misrepresentation of the origin of that material, or
+ requiring that modified versions of such material be marked in
+ reasonable ways as different from the original version; or
+
+ d) Limiting the use for publicity purposes of names of licensors or
+ authors of the material; or
+
+ e) Declining to grant rights under trademark law for use of some
+ trade names, trademarks, or service marks; or
+
+ f) Requiring indemnification of licensors and authors of that
+ material by anyone who conveys the material (or modified versions of
+ it) with contractual assumptions of liability to the recipient, for
+ any liability that these contractual assumptions directly impose on
+ those licensors and authors.
+
+ All other non-permissive additional terms are considered "further
+restrictions" within the meaning of section 10. If the Program as you
+received it, or any part of it, contains a notice stating that it is
+governed by this License along with a term that is a further
+restriction, you may remove that term. If a license document contains
+a further restriction but permits relicensing or conveying under this
+License, you may add to a covered work material governed by the terms
+of that license document, provided that the further restriction does
+not survive such relicensing or conveying.
+
+ If you add terms to a covered work in accord with this section, you
+must place, in the relevant source files, a statement of the
+additional terms that apply to those files, or a notice indicating
+where to find the applicable terms.
+
+ Additional terms, permissive or non-permissive, may be stated in the
+form of a separately written license, or stated as exceptions;
+the above requirements apply either way.
+
+ 8. Termination.
+
+ You may not propagate or modify a covered work except as expressly
+provided under this License. Any attempt otherwise to propagate or
+modify it is void, and will automatically terminate your rights under
+this License (including any patent licenses granted under the third
+paragraph of section 11).
+
+ However, if you cease all violation of this License, then your
+license from a particular copyright holder is reinstated (a)
+provisionally, unless and until the copyright holder explicitly and
+finally terminates your license, and (b) permanently, if the copyright
+holder fails to notify you of the violation by some reasonable means
+prior to 60 days after the cessation.
+
+ Moreover, your license from a particular copyright holder is
+reinstated permanently if the copyright holder notifies you of the
+violation by some reasonable means, this is the first time you have
+received notice of violation of this License (for any work) from that
+copyright holder, and you cure the violation prior to 30 days after
+your receipt of the notice.
+
+ Termination of your rights under this section does not terminate the
+licenses of parties who have received copies or rights from you under
+this License. If your rights have been terminated and not permanently
+reinstated, you do not qualify to receive new licenses for the same
+material under section 10.
+
+ 9. Acceptance Not Required for Having Copies.
+
+ You are not required to accept this License in order to receive or
+run a copy of the Program. Ancillary propagation of a covered work
+occurring solely as a consequence of using peer-to-peer transmission
+to receive a copy likewise does not require acceptance. However,
+nothing other than this License grants you permission to propagate or
+modify any covered work. These actions infringe copyright if you do
+not accept this License. Therefore, by modifying or propagating a
+covered work, you indicate your acceptance of this License to do so.
+
+ 10. Automatic Licensing of Downstream Recipients.
+
+ Each time you convey a covered work, the recipient automatically
+receives a license from the original licensors, to run, modify and
+propagate that work, subject to this License. You are not responsible
+for enforcing compliance by third parties with this License.
+
+ An "entity transaction" is a transaction transferring control of an
+organization, or substantially all assets of one, or subdividing an
+organization, or merging organizations. If propagation of a covered
+work results from an entity transaction, each party to that
+transaction who receives a copy of the work also receives whatever
+licenses to the work the party's predecessor in interest had or could
+give under the previous paragraph, plus a right to possession of the
+Corresponding Source of the work from the predecessor in interest, if
+the predecessor has it or can get it with reasonable efforts.
+
+ You may not impose any further restrictions on the exercise of the
+rights granted or affirmed under this License. For example, you may
+not impose a license fee, royalty, or other charge for exercise of
+rights granted under this License, and you may not initiate litigation
+(including a cross-claim or counterclaim in a lawsuit) alleging that
+any patent claim is infringed by making, using, selling, offering for
+sale, or importing the Program or any portion of it.
+
+ 11. Patents.
+
+ A "contributor" is a copyright holder who authorizes use under this
+License of the Program or a work on which the Program is based. The
+work thus licensed is called the contributor's "contributor version".
+
+ A contributor's "essential patent claims" are all patent claims
+owned or controlled by the contributor, whether already acquired or
+hereafter acquired, that would be infringed by some manner, permitted
+by this License, of making, using, or selling its contributor version,
+but do not include claims that would be infringed only as a
+consequence of further modification of the contributor version. For
+purposes of this definition, "control" includes the right to grant
+patent sublicenses in a manner consistent with the requirements of
this License.
- 7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
+ Each contributor grants you a non-exclusive, worldwide, royalty-free
+patent license under the contributor's essential patent claims, to
+make, use, sell, offer for sale, import and otherwise run, modify and
+propagate the contents of its contributor version.
+
+ In the following three paragraphs, a "patent license" is any express
+agreement or commitment, however denominated, not to enforce a patent
+(such as an express permission to practice a patent or covenant not to
+sue for patent infringement). To "grant" such a patent license to a
+party means to make such an agreement or commitment not to enforce a
+patent against the party.
+
+ If you convey a covered work, knowingly relying on a patent license,
+and the Corresponding Source of the work is not available for anyone
+to copy, free of charge and under the terms of this License, through a
+publicly available network server or other readily accessible means,
+then you must either (1) cause the Corresponding Source to be so
+available, or (2) arrange to deprive yourself of the benefit of the
+patent license for this particular work, or (3) arrange, in a manner
+consistent with the requirements of this License, to extend the patent
+license to downstream recipients. "Knowingly relying" means you have
+actual knowledge that, but for the patent license, your conveying the
+covered work in a country, or your recipient's use of the covered work
+in a country, would infringe one or more identifiable patents in that
+country that you have reason to believe are valid.
+
+ If, pursuant to or in connection with a single transaction or
+arrangement, you convey, or propagate by procuring conveyance of, a
+covered work, and grant a patent license to some of the parties
+receiving the covered work authorizing them to use, propagate, modify
+or convey a specific copy of the covered work, then the patent license
+you grant is automatically extended to all recipients of the covered
+work and works based on it.
+
+ A patent license is "discriminatory" if it does not include within
+the scope of its coverage, prohibits the exercise of, or is
+conditioned on the non-exercise of one or more of the rights that are
+specifically granted under this License. You may not convey a covered
+work if you are a party to an arrangement with a third party that is
+in the business of distributing software, under which you make payment
+to the third party based on the extent of your activity of conveying
+the work, and under which the third party grants, to any of the
+parties who would receive the covered work from you, a discriminatory
+patent license (a) in connection with copies of the covered work
+conveyed by you (or copies made from those copies), or (b) primarily
+for and in connection with specific products or compilations that
+contain the covered work, unless you entered into that arrangement,
+or that patent license was granted, prior to 28 March 2007.
+
+ Nothing in this License shall be construed as excluding or limiting
+any implied license or other defenses to infringement that may
+otherwise be available to you under applicable patent law.
+
+ 12. No Surrender of Others' Freedom.
+
+ If conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License. If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all. For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
+excuse you from the conditions of this License. If you cannot convey a
+covered work so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you may
+not convey it at all. For example, if you agree to terms that obligate you
+to collect a royalty for further conveying from those to whom you convey
+the Program, the only way you could satisfy both those terms and this
+License would be to refrain entirely from conveying the Program.
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
+ 13. Use with the GNU Affero General Public License.
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices. Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
+ Notwithstanding any other provision of this License, you have
+permission to link or combine any covered work with a work licensed
+under version 3 of the GNU Affero General Public License into a single
+combined work, and to convey the resulting work. The terms of this
+License will continue to apply to the part which is the covered work,
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
- 8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded. In such case, this License incorporates
-the limitation as if written in the body of this License.
+ 14. Revised Versions of this License.
- 9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time. Such new versions will
+ The Free Software Foundation may publish revised and/or new versions of
+the GNU General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
-Each version is given a distinguishing version number. If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation. If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
+ Each version is given a distinguishing version number. If the
+Program specifies that a certain numbered version of the GNU General
+Public License "or any later version" applies to it, you have the
+option of following the terms and conditions either of that numbered
+version or of any later version published by the Free Software
+Foundation. If the Program does not specify a version number of the
+GNU General Public License, you may choose any version ever published
+by the Free Software Foundation.
- 10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission. For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this. Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
+ If the Program specifies that a proxy can decide which future
+versions of the GNU General Public License can be used, that proxy's
+public statement of acceptance of a version permanently authorizes you
+to choose that version for the Program.
- NO WARRANTY
+ Later license versions may give you additional or different
+permissions. However, no additional obligations are imposed on any
+author or copyright holder as a result of your choosing to follow a
+later version.
- 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
+ 15. Disclaimer of Warranty.
- 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
+ THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
+APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
+HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
+OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
+THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
+IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
+ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
+
+ 16. Limitation of Liability.
+
+ IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
+THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
+GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
+USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
+DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
+PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
+EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
+SUCH DAMAGES.
+
+ 17. Interpretation of Sections 15 and 16.
+
+ If the disclaimer of warranty and limitation of liability provided
+above cannot be given local legal effect according to their terms,
+reviewing courts shall apply local law that most closely approximates
+an absolute waiver of all civil liability in connection with the
+Program, unless a warranty or assumption of liability accompanies a
+copy of the Program in return for a fee.
END OF TERMS AND CONDITIONS
-
- Appendix: How to Apply These Terms to Your New Programs
+
+ How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
@@ -287,15 +629,15 @@ free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
+state the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
- Copyright (C) 19yy
+ Copyright (C)
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -304,36 +646,31 @@ the "copyright" line and a pointer to where the full notice is found.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
- Gnomovision version 69, Copyright (C) 19yy name of author
- Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License. Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary. Here is a sample; alter the names:
+ You should also get your employer (if you work as a programmer) or school,
+if any, to sign a "copyright disclaimer" for the program, if necessary.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
- Yoyodyne, Inc., hereby disclaims all copyright interest in the program
- `Gnomovision' (which makes passes at compilers) written by James Hacker.
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
- , 1 April 1989
- Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs. If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library. If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/src/bin/findutils/Jamfile b/src/bin/findutils/Jamfile
index 217334b6a8..9ceab271a8 100644
--- a/src/bin/findutils/Jamfile
+++ b/src/bin/findutils/Jamfile
@@ -1,5 +1,6 @@
SubDir HAIKU_TOP src bin findutils ;
+SubInclude HAIKU_TOP src bin findutils gnulib ;
SubInclude HAIKU_TOP src bin findutils lib ;
SubInclude HAIKU_TOP src bin findutils find ;
SubInclude HAIKU_TOP src bin findutils locate ;
diff --git a/src/bin/findutils/README b/src/bin/findutils/README
index beff140830..be967a2224 100644
--- a/src/bin/findutils/README
+++ b/src/bin/findutils/README
@@ -1,12 +1,21 @@
This package contains the GNU find, xargs, and locate programs. find
-and xargs comply with POSIX 1003.2, as far as I know. They also
-support some additional options, some borrowed from Unix and some
-unique to GNU.
+and xargs comply with POSIX 1003.2, as far as I know (with the
+exception of the "+" modifier for the "-exec" action, which isn't
+implemented yet). They also support a large number of additional
+options, some borrowed from Unix and some unique to GNU.
See the file NEWS for a list of major changes in the current release.
See the file INSTALL for compilation and installation instructions.
+To verify the GPG signature of the release, you will need the public
+key of the findutils maintainer. You can download this from
+ftp://ftp.gnu.org/gnu/gnu-keyring.gpg. Alternatively, you could query
+a PGP keyserver, but you will need to use one that can cope with
+subkeys containing photos. Many older key servers cannot do this. I
+use subkeys.pgp.net. I think that one works. See also the
+"Downloading" section of http://www.gnu.org/software/findutils/.
+
Special configure options:
--with-afs
@@ -21,6 +30,13 @@ getpwuid or getgrgid when needed. Speeds up -nouser and -nogroup
unless you are running NIS or Hesiod, which make password and group
calls very expensive.
+--enable-debug
+ Produce output on the standard error output indicating what find is
+doing. This information includes details about how the command line
+has been parsed and what files have been stat()ed. This output is
+normally interesting only to the maintainer, and so is off by default.
+
+
To gain speed, GNU find avoids statting files whenever possible.
It does this by:
1. Checking the number of links to directories and not statting files
@@ -39,9 +55,5 @@ searching has been moved to a separate program, `locate'; the same
thing has been done in 4.4BSD. If you use locate, you should run the
included `updatedb' script from cron periodically (typically nightly).
-The `Makefile.am' files are used by an experimental program called
-AutoMake that is under development. It's not ready for general use
-yet, so don't worry about them.
-
Mail suggestions and bug reports for these programs to
-bug-gnu-utils@prep.ai.mit.edu.
+bug-findutils@gnu.org.
diff --git a/src/bin/findutils/config.h b/src/bin/findutils/config.h
index 31149417ac..2b8687f6ab 100644
--- a/src/bin/findutils/config.h
+++ b/src/bin/findutils/config.h
@@ -1,177 +1,1047 @@
-/* config.h. Generated automatically by configure. */
-/* config.h.in. Generated automatically from configure.in by autoheader. */
+/* config.h. Generated from config.h.in by configure. */
+/* config.h.in. Generated from configure.in by autoheader. */
-/* Define if on AIX 3.
- System headers sometimes define this.
- We just want to avoid a redefinition error message. */
-#ifndef _ALL_SOURCE
-/* #undef _ALL_SOURCE */
-#endif
+/* Define to the number of bits in type 'ptrdiff_t'. */
+#define BITSIZEOF_PTRDIFF_T 32
-/* Define if using alloca.c. */
-/* #undef C_ALLOCA */
+/* Define to the number of bits in type 'sig_atomic_t'. */
+#define BITSIZEOF_SIG_ATOMIC_T 32
-/* Define if the closedir function returns void instead of int. */
+/* Define to the number of bits in type 'size_t'. */
+#define BITSIZEOF_SIZE_T 32
+
+/* Define to the number of bits in type 'wchar_t'. */
+#define BITSIZEOF_WCHAR_T 16
+
+/* Define to the number of bits in type 'wint_t'. */
+#define BITSIZEOF_WINT_T 32
+
+/* Define if you want find -nouser and -nogroup to make tables of used UIDs
+ and GIDs at startup instead of using getpwuid or getgrgid when needed.
+ Speeds up -nouser and -nogroup unless you are running NIS or Hesiod, which
+ make password and group calls very expensive. */
+/* #undef CACHE_IDS */
+
+/* Define if chown is not POSIX compliant regarding IDs of -1. */
+#define CHOWN_FAILS_TO_HONOR_ID_OF_NEGATIVE_ONE 1
+
+/* Define if chown modifies symlinks. */
+/* #undef CHOWN_MODIFIES_SYMLINK */
+
+/* Define to 1 if the `closedir' function returns void instead of `int'. */
/* #undef CLOSEDIR_VOID */
-/* Define to empty if the keyword does not work. */
-/* #undef const */
-
-/* Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP systems.
- This function is required for alloca.c support on those systems. */
+/* Define to one of `_getb67', `GETB67', `getb67' for Cray-2 and Cray-YMP
+ systems. This function is required for `alloca.c' support on those systems.
+ */
/* #undef CRAY_STACKSEG_END */
-/* Define to `int' if doesn't define. */
-/* #undef gid_t */
+/* Define to 1 if using `alloca.c'. */
+/* #undef C_ALLOCA */
-/* Define if you have alloca, as a function or macro. */
+/* Define if you want to see find's innards */
+/* #undef DEBUG */
+
+/* Define if you want to see a message every time find calls the stat() system
+ call */
+/* #undef DEBUG_STAT */
+
+/* the name of the file descriptor member of DIR */
+/* #undef DIR_FD_MEMBER_NAME */
+
+#ifdef DIR_FD_MEMBER_NAME
+# define DIR_TO_FD(Dir_p) ((Dir_p)->DIR_FD_MEMBER_NAME)
+#else
+# define DIR_TO_FD(Dir_p) -1
+#endif
+
+
+/* Define to 1 if // is a file system root distinct from /. */
+/* #undef DOUBLE_SLASH_IS_DISTINCT_ROOT */
+
+/* Define if struct dirent has a member d_ino that actually works. */
+#define D_INO_IN_DIRENT 1
+
+/* Define to 1 if translation of program messages to the user's native
+ language is requested. */
+/* #undef ENABLE_NLS */
+
+/* Define if gnulib's fchdir() replacement is used. */
+/* #undef FCHDIR_REPLACEMENT */
+
+/* Define on systems for which file names may have a so-called `drive letter'
+ prefix, define this to compute the length of that prefix, including the
+ colon. */
+#define FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX 0
+
+/* Define if the backslash character may also serve as a file name component
+ separator. */
+#define FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR 0
+
+/* Define if a drive letter prefix denotes a relative path if it is not
+ followed by a file name component separator. */
+#define FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE 0
+
+/* Define if we are compiling GNU findutils */
+#define FINDUTILS 1
+
+/* Define to nothing if C supports flexible array members, and to 1 if it does
+ not. That way, with a declaration like `struct s { int n; double
+ d[FLEXIBLE_ARRAY_MEMBER]; };', the struct hack can be used with pre-C99
+ compilers. When computing the size of such an object, don't use 'sizeof
+ (struct s)' as it overestimates the size. Use 'offsetof (struct s, d)'
+ instead. Don't use 'offsetof (struct s, d[0])', as this doesn't work with
+ MSVC and with C++ compilers. */
+#define FLEXIBLE_ARRAY_MEMBER 1
+
+/* Define to make the limit macros in visible. */
+#define GL_TRIGGER_STDC_LIMIT_MACROS 1
+
+/* Define to 1 when using the gnulib module canonicalize. */
+#define GNULIB_CANONICALIZE 1
+
+/* Define to 1 when using the gnulib module close-stream. */
+#define GNULIB_CLOSE_STREAM 1
+
+/* Define to 1 when using the gnulib module fcntl-safer. */
+#define GNULIB_FCNTL_SAFER 1
+
+/* Define to 1 when using the gnulib module fopen-safer. */
+#define GNULIB_FOPEN_SAFER 1
+
+/* Define to indicate the 'malloc' module. */
+#define GNULIB_MALLOC_GNU 1
+
+/* Define to indicate the 'realloc' module. */
+#define GNULIB_REALLOC_GNU 1
+
+/* Define to 1 if you have the `alarm' function. */
+#define HAVE_ALARM 1
+
+/* Define to 1 if you have 'alloca' after including , a header that
+ may be supplied by this distribution. */
#define HAVE_ALLOCA 1
-/* Define if you have and it should be used (not on Ultrix). */
+/* Define HAVE_ALLOCA_H for backward compatibility with older code that
+ includes only if HAVE_ALLOCA_H is defined. */
#define HAVE_ALLOCA_H 1
-/* Define if you don't have vprintf but do have _doprnt. */
+/* Define to 1 if you have the `btowc' function. */
+#define HAVE_BTOWC 1
+
+/* Define to 1 if you have the `canonicalize_file_name' function. */
+/* #undef HAVE_CANONICALIZE_FILE_NAME */
+
+/* Define to 1 if you have the MacOS X function CFLocaleCopyCurrent in the
+ CoreFoundation framework. */
+/* #undef HAVE_CFLOCALECOPYCURRENT */
+
+/* Define to 1 if you have the MacOS X function CFPreferencesCopyAppValue in
+ the CoreFoundation framework. */
+/* #undef HAVE_CFPREFERENCESCOPYAPPVALUE */
+
+/* Define to 1 if your system has a working `chown' function. */
+/* #undef HAVE_CHOWN */
+
+/* Define if the GNU dcgettext() function is already present or preinstalled.
+ */
+/* #undef HAVE_DCGETTEXT */
+
+/* Define to 1 if you have the declaration of `canonicalize_file_name', and to
+ 0 if you don't. */
+#define HAVE_DECL_CANONICALIZE_FILE_NAME 0
+
+/* Define to 1 if you have the declaration of `dirfd', and to 0 if you don't.
+ */
+#define HAVE_DECL_DIRFD 1
+
+/* Define to 1 if you have the declaration of `fpurge', and to 0 if you don't.
+ */
+#define HAVE_DECL_FPURGE 1
+
+/* Define to 1 if you have the declaration of `getcwd', and to 0 if you don't.
+ */
+#define HAVE_DECL_GETCWD 1
+
+/* Define to 1 if you have the declaration of `getc_unlocked', and to 0 if you
+ don't. */
+#define HAVE_DECL_GETC_UNLOCKED 1
+
+/* Define to 1 if you have the declaration of `getdelim', and to 0 if you
+ don't. */
+#define HAVE_DECL_GETDELIM 0
+
+/* Define to 1 if you have the declaration of `getenv', and to 0 if you don't.
+ */
+#define HAVE_DECL_GETENV 1
+
+/* Define to 1 if you have the declaration of `getline', and to 0 if you
+ don't. */
+#define HAVE_DECL_GETLINE 0
+
+/* Define to 1 if you have the declaration of `imaxabs', and to 0 if you
+ don't. */
+#define HAVE_DECL_IMAXABS 1
+
+/* Define to 1 if you have the declaration of `imaxdiv', and to 0 if you
+ don't. */
+#define HAVE_DECL_IMAXDIV 1
+
+/* Define to 1 if you have the declaration of `isblank', and to 0 if you
+ don't. */
+#define HAVE_DECL_ISBLANK 1
+
+/* Define to 1 if you have the declaration of `memrchr', and to 0 if you
+ don't. */
+#define HAVE_DECL_MEMRCHR 0
+
+/* Define to 1 if you have the declaration of `mkdir', and to 0 if you don't.
+ */
+#define HAVE_DECL_MKDIR 1
+
+/* Define to 1 if you have the declaration of `strdup', and to 0 if you don't.
+ */
+#define HAVE_DECL_STRDUP 1
+
+/* Define to 1 if you have the declaration of `strerror', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_STRERROR */
+
+/* Define to 1 if you have the declaration of `strerror_r', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRERROR_R 1
+
+/* Define to 1 if you have the declaration of `strmode', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRMODE 0
+
+/* Define to 1 if you have the declaration of `strndup', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNDUP 0
+
+/* Define to 1 if you have the declaration of `strnlen', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRNLEN 1
+
+/* Define to 1 if you have the declaration of `strtoimax', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRTOIMAX 1
+
+/* Define to 1 if you have the declaration of `strtoll', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_STRTOLL */
+
+/* Define to 1 if you have the declaration of `strtoull', and to 0 if you
+ don't. */
+/* #undef HAVE_DECL_STRTOULL */
+
+/* Define to 1 if you have the declaration of `strtoumax', and to 0 if you
+ don't. */
+#define HAVE_DECL_STRTOUMAX 1
+
+/* Define to 1 if you have the declaration of `tzname', and to 0 if you don't.
+ */
+/* #undef HAVE_DECL_TZNAME */
+
+/* Define to 1 if you have the declaration of `__fpending', and to 0 if you
+ don't. */
+#define HAVE_DECL___FPENDING 0
+
+/* Define to 1 if you have the header file, and it defines `DIR'.
+ */
+#define HAVE_DIRENT_H 1
+
+/* Define to 1 if you have the `dirfd' function. */
+#define HAVE_DIRFD 1
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
/* #undef HAVE_DOPRNT */
-/* Define if you have the getmntent function. */
+/* Define to 1 if you have the `dup2' function. */
+#define HAVE_DUP2 1
+
+/* Define to 1 if you have the `endgrent' function. */
+#define HAVE_ENDGRENT 1
+
+/* Define to 1 if you have the `endmntent' function. */
+/* #undef HAVE_ENDMNTENT */
+
+/* Define to 1 if you have the `endpwent' function. */
+#define HAVE_ENDPWENT 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the `fchdir' function. */
+#define HAVE_FCHDIR 1
+
+/* Define to 1 if you have the `fchmodat' function. */
+/* #undef HAVE_FCHMODAT */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the `fdopendir' function. */
+/* #undef HAVE_FDOPENDIR */
+
+/* Define to 1 if you have the `flockfile' function. */
+/* #undef HAVE_FLOCKFILE */
+
+/* Define to 1 if you have the `forcefindlib' function. */
+/* #undef HAVE_FORCEFINDLIB */
+
+/* Define to 1 if you have the `fpurge' function. */
+#define HAVE_FPURGE 1
+
+/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */
+#define HAVE_FSEEKO 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_FS_INFO_H 1
+
+/* Define to 1 if you have the `fs_stat_dev' function. */
+#define HAVE_FS_STAT_DEV 1
+
+/* Define to 1 if you have the `funlockfile' function. */
+/* #undef HAVE_FUNLOCKFILE */
+
+/* Define to 1 if you have the `getcwd' function. */
+#define HAVE_GETCWD 1
+
+/* Define to 1 if you have the `getdelim' function. */
+#define HAVE_GETDELIM 1
+
+/* Define to 1 if you have the `getmntent' function. */
/* #undef HAVE_GETMNTENT */
-/* Define if your struct stat has st_blocks. */
-/* #undef HAVE_ST_BLOCKS */
+/* Define to 1 if you have the `getmntinfo' function. */
+/* #undef HAVE_GETMNTINFO */
-/* Define if your struct stat has st_rdev. */
-#define HAVE_ST_RDEV 1
+/* Define to 1 if you have the header file. */
+#define HAVE_GETOPT_H 1
-/* Define if you have the strftime function. */
+/* Define to 1 if you have the `getopt_long_only' function. */
+#define HAVE_GETOPT_LONG_ONLY 1
+
+/* Define to 1 if you have the `getpagesize' function. */
+#define HAVE_GETPAGESIZE 1
+
+/* Define if the GNU gettext() function is already present or preinstalled. */
+/* #undef HAVE_GETTEXT */
+
+/* Define to 1 if you have the `hasmntopt' function. */
+/* #undef HAVE_HASMNTOPT */
+
+/* Define if you have the iconv() function and it works. */
+#define HAVE_ICONV 1
+
+/* Define if your compiler supports the #include_next directive. */
+#define HAVE_INCLUDE_NEXT 1
+
+/* Define to 1 if the compiler supports one of the keywords 'inline',
+ '__inline__', '__inline' and effectively inlines functions marked as such.
+ */
+#define HAVE_INLINE 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_IO_H */
+
+/* Define to 1 if you have the `isblank' function. */
+#define HAVE_ISBLANK 1
+
+/* Define to 1 if you have the `iswcntrl' function. */
+#define HAVE_ISWCNTRL 1
+
+/* Define to 1 if you have the `iswctype' function. */
+#define HAVE_ISWCTYPE 1
+
+/* Define if you have and nl_langinfo(CODESET). */
+/* #undef HAVE_LANGINFO_CODESET */
+
+/* Define to 1 if you have the `lchmod' function. */
+/* #undef HAVE_LCHMOD */
+
+/* Define to 1 if you have the `lchown' function. */
+#define HAVE_LCHOWN 1
+
+/* Define to 1 if you have the `sun' library (-lsun). */
+/* #undef HAVE_LIBSUN */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the `listmntent' function. */
+/* #undef HAVE_LISTMNTENT */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_LOCALE_H 1
+
+/* Define to 1 if you support file names longer than 14 characters. */
+#define HAVE_LONG_FILE_NAMES 1
+
+/* Define to 1 if the system has the type `long long int'. */
+#define HAVE_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `lstat' function. */
+#define HAVE_LSTAT 1
+
+/* Define to 1 if your system has a GNU libc compatible `malloc' function, and
+ to 0 otherwise. */
+#define HAVE_MALLOC 1
+
+/* Define if the 'malloc' function is POSIX compliant. */
+#define HAVE_MALLOC_POSIX 1
+
+/* Define to 1 if you have the `mblen' function. */
+#define HAVE_MBLEN 1
+
+/* Define to 1 if you have the `mbrlen' function. */
+#define HAVE_MBRLEN 1
+
+/* Define to 1 if you have the `mbrtowc' function. */
+#define HAVE_MBRTOWC 1
+
+/* Define to 1 if you have the `mbsinit' function. */
+#define HAVE_MBSINIT 1
+
+/* Define to 1 if you have the `mbsrtowcs' function. */
+#define HAVE_MBSRTOWCS 1
+
+/* Define to 1 if declares mbstate_t. */
+#define HAVE_MBSTATE_T 1
+
+/* Define to 1 if you have the `memcmp' function. */
+#define HAVE_MEMCMP 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the `mempcpy' function. */
+/* #undef HAVE_MEMPCPY */
+
+/* Define to 1 if you have the `memrchr' function. */
+#define HAVE_MEMRCHR 1
+
+/* Define to 1 if you have the `memset' function. */
+#define HAVE_MEMSET 1
+
+/* Define to 1 if you have the `mkdirat' function. */
+/* #undef HAVE_MKDIRAT */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_MNTENT_H */
+
+/* Define to 1 if you have the header file, and it defines `DIR'. */
+/* #undef HAVE_NDIR_H */
+
+/* Define to 1 if you have the `next_dev' function. */
+#define HAVE_NEXT_DEV 1
+
+/* Define to 1 if you have the `openat' function. */
+/* #undef HAVE_OPENAT */
+
+/* Define to 1 if getcwd works, except it sometimes fails when it shouldn't,
+ setting errno to ERANGE, ENAMETOOLONG, or ENOENT. If __GETCWD_PREFIX is not
+ defined, it doesn't matter whether HAVE_PARTLY_WORKING_GETCWD is defined.
+ */
+/* #undef HAVE_PARTLY_WORKING_GETCWD */
+
+/* Define to 1 if you have the `pathconf' function. */
+#define HAVE_PATHCONF 1
+
+/* Define to 1 if you have the `pipe' function. */
+#define HAVE_PIPE 1
+
+/* Define to 1 if you have the `readlink' function. */
+#define HAVE_READLINK 1
+
+/* Define to 1 if your system has a GNU libc compatible `realloc' function,
+ and to 0 otherwise. */
+#define HAVE_REALLOC 1
+
+/* Define if the 'realloc' function is POSIX compliant. */
+#define HAVE_REALLOC_POSIX 1
+
+/* Define to 1 if you have the `resolvepath' function. */
+/* #undef HAVE_RESOLVEPATH */
+
+/* Define to 1 if you have the `rpmatch' function. */
+/* #undef HAVE_RPMATCH */
+
+/* Define to 1 if you have the `setlocale' function. */
+#define HAVE_SETLOCALE 1
+
+/* Define to 1 if you have the `setmntent' function. */
+/* #undef HAVE_SETMNTENT */
+
+/* Define to 1 if 'sig_atomic_t' is a signed integer type. */
+#define HAVE_SIGNED_SIG_ATOMIC_T 1
+
+/* Define to 1 if 'wchar_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_WCHAR_T */
+
+/* Define to 1 if 'wint_t' is a signed integer type. */
+/* #undef HAVE_SIGNED_WINT_T */
+
+/* Define to 1 if stdbool.h conforms to C99. */
+/* #undef HAVE_STDBOOL_H */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDDEF_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDIO_EXT_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDIO_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the `stpcpy' function. */
+#define HAVE_STPCPY 1
+
+/* Define to 1 if you have the `strdup' function. */
+#define HAVE_STRDUP 1
+
+/* Define to 1 if you have the `strerror' function. */
+#define HAVE_STRERROR 1
+
+/* Define to 1 if you have the `strerror_r' function. */
+#define HAVE_STRERROR_R 1
+
+/* Define to 1 if you have the `strftime' function. */
#define HAVE_STRFTIME 1
-/* Define if you have that is POSIX.1 compatible. */
+/* Define to 1 if you have the header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_STRING_H 1
+
+/* Define if you have the strndup() function and it works. */
+/* #undef HAVE_STRNDUP */
+
+/* Define to 1 if you have the `strspn' function. */
+#define HAVE_STRSPN 1
+
+/* Define to 1 if you have the `strstr' function. */
+#define HAVE_STRSTR 1
+
+/* Define to 1 if you have the `strtoimax' function. */
+#define HAVE_STRTOIMAX 1
+
+/* Define to 1 if you have the `strtol' function. */
+#define HAVE_STRTOL 1
+
+/* Define to 1 if you have the `strtoll' function. */
+#define HAVE_STRTOLL 1
+
+/* Define to 1 if you have the `strtoul' function. */
+#define HAVE_STRTOUL 1
+
+/* Define to 1 if you have the `strtoull' function. */
+#define HAVE_STRTOULL 1
+
+/* Define to 1 if you have the `strtoumax' function. */
+#define HAVE_STRTOUMAX 1
+
+/* Define to 1 if your 'struct dirent' has a d_type member */
+/* #undef HAVE_STRUCT_DIRENT_D_TYPE */
+
+/* Define to 1 if `f_fstypename' is member of `struct fsstat'. */
+/* #undef HAVE_STRUCT_FSSTAT_F_FSTYPENAME */
+
+/* Define to 1 if `f_fstypename' is member of `struct statfs'. */
+/* #undef HAVE_STRUCT_STATFS_F_FSTYPENAME */
+
+/* Define to 1 if `st_blocks' is member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_BLOCKS 1
+
+/* Define to 1 if `st_rdev' is member of `struct stat'. */
+#define HAVE_STRUCT_STAT_ST_RDEV 1
+
+/* Define to 1 if `tm_zone' is member of `struct tm'. */
+#define HAVE_STRUCT_TM_TM_ZONE 1
+
+/* Define to 1 if your `struct stat' has `st_blocks'. Deprecated, use
+ `HAVE_STRUCT_STAT_ST_BLOCKS' instead. */
+#define HAVE_ST_BLOCKS 1
+
+/* Define if struct stat has an st_dm_mode member. */
+/* #undef HAVE_ST_DM_MODE */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_BITYPES_H */
+
+/* Define to 1 if you have the header file, and it defines `DIR'.
+ */
+/* #undef HAVE_SYS_DIR_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_FS_TYPES_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_INTTYPES_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_MKDEV_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_MNTENT_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_MNTIO_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_MNTTAB_H */
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_MOUNT_H */
+
+/* Define to 1 if you have the header file, and it defines `DIR'.
+ */
+/* #undef HAVE_SYS_NDIR_H */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_PARAM_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_STATVFS_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_TIME_H 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the header file. */
+/* #undef HAVE_SYS_UCRED_H */
+
+/* Define to 1 if you have the header file. */
+#define HAVE_SYS_UTSNAME_H 1
+
+/* Define to 1 if you have that is POSIX.1 compatible. */
#define HAVE_SYS_WAIT_H 1
-/* Define if your struct tm has tm_zone. */
+/* Define to 1 if you have the header file. */
+#define HAVE_TIME_H 1
+
+/* Define if struct tm has the tm_gmtoff member. */
+#define HAVE_TM_GMTOFF 1
+
+/* Define to 1 if your `struct tm' has `tm_zone'. Deprecated, use
+ `HAVE_STRUCT_TM_TM_ZONE' instead. */
#define HAVE_TM_ZONE 1
-/* Define if you don't have tm_zone but do have the external array
- tzname. */
+/* Define to 1 if you don't have `tm_zone' but do have the external array
+ `tzname'. */
/* #undef HAVE_TZNAME */
-/* Define if you have the vprintf function. */
+/* Define to 1 if you have the `tzset' function. */
+#define HAVE_TZSET 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if the system has the type `unsigned long long int'. */
+#define HAVE_UNSIGNED_LONG_LONG_INT 1
+
+/* Define to 1 if you have the `vprintf' function. */
#define HAVE_VPRINTF 1
-/* Define if major, minor, and makedev are declared in . */
+/* Define to 1 if you have the `waitpid' function. */
+#define HAVE_WAITPID 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_WCHAR_H 1
+
+/* Define if you have the 'wchar_t' type. */
+#define HAVE_WCHAR_T 1
+
+/* Define to 1 if you have the `wcrtomb' function. */
+#define HAVE_WCRTOMB 1
+
+/* Define to 1 if you have the `wcscoll' function. */
+#define HAVE_WCSCOLL 1
+
+/* Define to 1 if you have the header file. */
+#define HAVE_WCTYPE_H 1
+
+/* Define if you have the 'wint_t' type. */
+#define HAVE_WINT_T 1
+
+/* Define to 1 if you have the `wmemchr' function. */
+#define HAVE_WMEMCHR 1
+
+/* Define to 1 if you have the `wmemcpy' function. */
+#define HAVE_WMEMCPY 1
+
+/* Define to 1 if you have the `wmempcpy' function. */
+#define HAVE_WMEMPCPY 1
+
+/* Define to 1 if O_NOATIME works. */
+#define HAVE_WORKING_O_NOATIME 0
+
+/* Define to 1 if O_NOFOLLOW works. */
+#define HAVE_WORKING_O_NOFOLLOW 0
+
+/* Define to 1 if the system has the type `_Bool'. */
+/* #undef HAVE__BOOL */
+
+/* Define to 1 if you have the `__fpending' function. */
+/* #undef HAVE___FPENDING */
+
+/* Define to 1 if you have the `__fpurge' function. */
+#define HAVE___FPURGE 1
+
+/* Define to 1 if you have the `__freading' function. */
+#define HAVE___FREADING 1
+
+#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR
+# define ISSLASH(C) ((C) == '/' || (C) == '\\')
+#else
+# define ISSLASH(C) ((C) == '/')
+#endif
+
+/* Define if you want to use the leaf optimisation (this can still be turned
+ off with -noleaf) */
+#define LEAF_OPTIMISATION 1
+
+/* Define to 1 if lseek does not detect pipes. */
+/* #undef LSEEK_PIPE_BROKEN */
+
+/* Define to 1 if `lstat' dereferences a symlink specified with a trailing
+ slash. */
+/* #undef LSTAT_FOLLOWS_SLASHED_SYMLINK */
+
+/* Define to 1 if `major', `minor', and `makedev' are declared in .
+ */
/* #undef MAJOR_IN_MKDEV */
-/* Define if major, minor, and makedev are declared in . */
+/* Define to 1 if `major', `minor', and `makedev' are declared in
+ . */
/* #undef MAJOR_IN_SYSMACROS */
-/* Define if on MINIX. */
-/* #undef _MINIX */
+/* If malloc(0) is != NULL, define this to 1. Otherwise define this to 0. */
+#define MALLOC_0_IS_NONNULL 1
-/* Define to `int' if doesn't define. */
-/* #undef pid_t */
+/* Define if there is no specific function for reading the list of mounted
+ file systems. fread will be used to read /etc/mnttab. (SVR2) */
+/* #undef MOUNTED_FREAD */
-/* Define if the system does not provide POSIX.1 features except
- with this defined. */
-/* #undef _POSIX_1_SOURCE */
+/* Define if (like SVR2) there is no specific function for reading the list of
+ mounted file systems, and your system has these header files:
+ and . (SVR3) */
+/* #undef MOUNTED_FREAD_FSTYP */
-/* Define if you need to in order for stat and other things to work. */
-/* #undef _POSIX_SOURCE */
+/* Define if there are functions named next_dev and fs_stat_dev for reading
+ the list of mounted file systems. (BeOS) */
+#define MOUNTED_FS_STAT_DEV 1
-/* Define to `unsigned' if doesn't define. */
-/* #undef size_t */
+/* Define if there is a function named getfsstat for reading the list of
+ mounted file systems. (DEC Alpha running OSF/1) */
+/* #undef MOUNTED_GETFSSTAT */
+
+/* Define if there is a function named getmnt for reading the list of mounted
+ file systems. (Ultrix) */
+/* #undef MOUNTED_GETMNT */
+
+/* Define if there is a function named getmntent for reading the list of
+ mounted file systems, and that function takes a single argument. (4.3BSD,
+ SunOS, HP-UX, Dynix, Irix) */
+/* #undef MOUNTED_GETMNTENT1 */
+
+/* Define if there is a function named getmntent for reading the list of
+ mounted file systems, and that function takes two arguments. (SVR4) */
+/* #undef MOUNTED_GETMNTENT2 */
+
+/* Define if there is a function named getmntinfo for reading the list of
+ mounted file systems and it returns an array of 'struct statfs'. (4.4BSD,
+ Darwin) */
+/* #undef MOUNTED_GETMNTINFO */
+
+/* Define if there is a function named getmntinfo for reading the list of
+ mounted file systems and it returns an array of 'struct statvfs'. (NetBSD
+ 3.0) */
+/* #undef MOUNTED_GETMNTINFO2 */
+
+/* Define if there is a function named listmntent that can be used to list all
+ mounted file systems. (UNICOS) */
+/* #undef MOUNTED_LISTMNTENT */
+
+/* Define if there is a function named mntctl that can be used to read the
+ list of mounted file systems, and there is a system header file that
+ declares `struct vmount.' (AIX) */
+/* #undef MOUNTED_VMOUNT */
+
+/* Name of package */
+#define PACKAGE "findutils"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "bug-findutils@gnu.org"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "GNU findutils"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "GNU findutils 4.2.33"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "findutils"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "4.2.33"
+
+/* the number of pending output bytes on stream `fp' */
+#define PENDING_OUTPUT_N_BYTES fp->_IO_write_ptr - fp->_IO_write_base
+
+/* Define if exists and defines unusable PRI* macros. */
+/* #undef PRI_MACROS_BROKEN */
+
+/* Define to 1 if the C compiler supports function prototypes. */
+#define PROTOTYPES 1
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'ptrdiff_t'. */
+#define PTRDIFF_T_SUFFIX l
+
+/* Define this to 1 if strerror is broken. */
+/* #undef REPLACE_STRERROR */
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'sig_atomic_t'. */
+#define SIG_ATOMIC_T_SUFFIX
+
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'size_t'. */
+#define SIZE_T_SUFFIX ul
/* If using the C implementation of alloca, define if you know the
direction of stack growth for your system; otherwise it will be
- automatically deduced at run-time.
+ automatically deduced at runtime.
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
- STACK_DIRECTION = 0 => direction of growth unknown
- */
+ STACK_DIRECTION = 0 => direction of growth unknown */
/* #undef STACK_DIRECTION */
-/* Define if the `S_IS*' macros in do not work properly. */
+/* Define to 1 if the `S_IS*' macros in do not work properly. */
/* #undef STAT_MACROS_BROKEN */
-/* Define if you have the ANSI C header files. */
+/* Define to 1 if you have the ANSI C header files. */
#define STDC_HEADERS 1
-/* Define if your declares struct tm. */
+/* Define to 1 if strerror_r returns char *. */
+/* #undef STRERROR_R_CHAR_P */
+
+/* Define to 1 if your declares `struct tm'. */
/* #undef TM_IN_SYS_TIME */
-/* Define to `int' if doesn't define. */
-/* #undef uid_t */
+/* Defined if you specify --enable-d_type-optimisation to configure. */
+#define USE_STRUCT_DIRENT_D_TYPE 1
-/* Define if you have the Andrew File System. */
-/* #undef AFS */
+/* Version number of package */
+#define VERSION "4.2.33"
-/* Define If you want find -nouser and -nogroup to make tables of
- used UIDs and GIDs at startup instead of using getpwuid or
- getgrgid when needed. Speeds up -nouser and -nogroup unless you
- are running NIS or Hesiod, which make password and group calls
- very expensive. */
-/* #undef CACHE_IDS */
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'wchar_t'. */
+#define WCHAR_T_SUFFIX
-/* Define to use SVR4 statvfs to get filesystem type. */
-/* #undef FSTYPE_STATVFS */
+/* Define to l, ll, u, ul, ull, etc., as suitable for constants of type
+ 'wint_t'. */
+#define WINT_T_SUFFIX u
-/* Define to use SVR3.2 statfs to get filesystem type. */
-/* #undef FSTYPE_USG_STATFS */
+/* Number of bits in a file offset, on hosts where this is settable. */
+/* #undef _FILE_OFFSET_BITS */
-/* Define to use AIX3 statfs to get filesystem type. */
-/* #undef FSTYPE_AIX_STATFS */
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
-/* Define to use 4.3BSD getmntent to get filesystem type. */
-/* #undef FSTYPE_MNTENT */
+/* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
+/* #undef _LARGEFILE_SOURCE */
-/* Define to use 4.4BSD and OSF1 statfs to get filesystem type. */
-/* #undef FSTYPE_STATFS */
+/* Define for large files, on AIX-style hosts. */
+/* #undef _LARGE_FILES */
-/* Define to use Ultrix getmnt to get filesystem type. */
-/* #undef FSTYPE_GETMNT */
+/* Define to 1 if on MINIX. */
+/* #undef _MINIX */
-/* Define to `unsigned long' if doesn't define. */
+/* Define to 2 if the system does not provide POSIX.1 features except with
+ this defined. */
+/* #undef _POSIX_1_SOURCE */
+
+/* Define to 1 if you need to in order for `stat' and other things to work. */
+/* #undef _POSIX_SOURCE */
+
+/* Define if you want regoff_t to be at least as wide POSIX requires. */
+#define _REGEX_LARGE_OFFSETS 1
+
+/* Enable extensions on AIX 3, Interix. */
+#ifndef _ALL_SOURCE
+# define _ALL_SOURCE 1
+#endif
+/* Enable GNU extensions on systems that have them. */
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE 1
+#endif
+/* Enable threading extensions on Solaris. */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# define _POSIX_PTHREAD_SEMANTICS 1
+#endif
+/* Enable extensions on HP NonStop. */
+#ifndef _TANDEM_SOURCE
+# define _TANDEM_SOURCE 1
+#endif
+/* Enable general extensions on Solaris. */
+#ifndef __EXTENSIONS__
+# define __EXTENSIONS__ 1
+#endif
+
+
+/* Define to rpl_ if the getopt replacement functions and variables should be
+ used. */
+/* #undef __GETOPT_PREFIX */
+
+/* Define to rpl_ if the openat replacement function should be used. */
+#define __OPENAT_PREFIX rpl_
+
+/* Define like PROTOTYPES; this can be used by system headers. */
+#define __PROTOTYPES 1
+
+/* Ensure that defines the limit macros, since gnulib's
+ relies on them. */
+#if defined __cplusplus && !defined __STDC_LIMIT_MACROS && GL_TRIGGER_STDC_LIMIT_MACROS
+# define __STDC_LIMIT_MACROS 1
+#endif
+
+
+/* Define to `unsigned long' if does not define. */
/* #undef dev_t */
-/* Define to `unsigned long' if doesn't define. */
+/* Define to rpl_fchownat if the replacement function should be used. */
+#define fchownat rpl_fchownat
+
+/* Define to a replacement function name for fnmatch(). */
+#define fnmatch gnu_fnmatch
+
+/* Define to `int' if doesn't define. */
+/* #undef gid_t */
+
+/* Define to `__inline__' or `__inline' if that's what the C compiler
+ calls it, or to nothing if 'inline' is not supported under any name. */
+#ifndef __cplusplus
+/* #undef inline */
+#endif
+
+/* Define to `unsigned long' if does not define. */
/* #undef ino_t */
-/* Define if you have the fchdir function. */
-#ifndef B_BEOS_VERSION
-#include
-#endif
-#if B_BEOS_VERSION > B_BEOS_VERSION_5
-#define HAVE_FCHDIR 1
+/* Define to rpl_malloc if the replacement function should be used. */
+/* #undef malloc */
+
+/* Define to a type if does not define. */
+/* #undef mbstate_t */
+
+/* Define to rpl_memcmp if the replacement function should be used. */
+/* #undef memcmp */
+
+/* Define to rpl_mktime if the replacement function should be used. */
+/* #undef mktime */
+
+/* Define to `int' if does not define. */
+/* #undef mode_t */
+
+/* Define to the name of the strftime replacement function. */
+#define my_strftime nstrftime
+
+/* Define to `int' if does not define. */
+/* #undef pid_t */
+
+/* Define to rpl_re_comp if the replacement should be used. */
+#define re_comp rpl_re_comp
+
+/* Define to rpl_re_compile_fastmap if the replacement should be used. */
+#define re_compile_fastmap rpl_re_compile_fastmap
+
+/* Define to rpl_re_compile_pattern if the replacement should be used. */
+#define re_compile_pattern rpl_re_compile_pattern
+
+/* Define to rpl_re_exec if the replacement should be used. */
+#define re_exec rpl_re_exec
+
+/* Define to rpl_re_match if the replacement should be used. */
+#define re_match rpl_re_match
+
+/* Define to rpl_re_match_2 if the replacement should be used. */
+#define re_match_2 rpl_re_match_2
+
+/* Define to rpl_re_search if the replacement should be used. */
+#define re_search rpl_re_search
+
+/* Define to rpl_re_search_2 if the replacement should be used. */
+#define re_search_2 rpl_re_search_2
+
+/* Define to rpl_re_set_registers if the replacement should be used. */
+#define re_set_registers rpl_re_set_registers
+
+/* Define to rpl_re_set_syntax if the replacement should be used. */
+#define re_set_syntax rpl_re_set_syntax
+
+/* Define to rpl_re_syntax_options if the replacement should be used. */
+#define re_syntax_options rpl_re_syntax_options
+
+/* Define to rpl_realloc if the replacement function should be used. */
+/* #undef realloc */
+
+/* Define to a replacement function name for realpath(). */
+#define realpath rpl_realpath
+
+/* Define to rpl_regcomp if the replacement should be used. */
+#define regcomp rpl_regcomp
+
+/* Define to rpl_regerror if the replacement should be used. */
+#define regerror rpl_regerror
+
+/* Define to rpl_regexec if the replacement should be used. */
+#define regexec rpl_regexec
+
+/* Define to rpl_regfree if the replacement should be used. */
+#define regfree rpl_regfree
+
+/* Define to the equivalent of the C99 'restrict' keyword, or to
+ nothing if this is not supported. Do not define if restrict is
+ supported directly. */
+#define restrict __restrict
+/* Work around a bug in Sun C++: it does not support _Restrict, even
+ though the corresponding Sun C compiler does, which causes
+ "#define restrict _Restrict" in the previous line. Perhaps some future
+ version of Sun C++ will work with _Restrict; if so, it'll probably
+ define __RESTRICT, just as Sun C does. */
+#if defined __SUNPRO_CC && !defined __RESTRICT
+# define _Restrict
#endif
-/* Define if you have the getcwd function. */
-#define HAVE_GETCWD 1
+/* Define to `unsigned int' if does not define. */
+/* #undef size_t */
-/* Define if you have the strerror function. */
-#define HAVE_STRERROR 1
+/* Define to `int' if does not define. */
+/* #undef ssize_t */
-/* Define if you have the header file. */
-#define HAVE_DIRENT_H 1
+/* Define to rpl_strnlen if the replacement function should be used. */
+/* #undef strnlen */
-/* Define if you have the header file. */
-#define HAVE_FCNTL_H 1
+/* Define to `int' if doesn't define. */
+/* #undef uid_t */
-/* Define if you have the header file. */
-#define HAVE_LIMITS_H 1
-
-/* Define if you have the header file. */
-/* #undef HAVE_NDIR_H */
-
-/* Define if you have the header file. */
-#define HAVE_STRING_H 1
-
-/* Define if you have the header file. */
-/* #undef HAVE_SYS_DIR_H */
-
-/* Define if you have the header file. */
-/* #undef HAVE_SYS_NDIR_H */
-
-/* Define if you have the header file. */
-#define HAVE_UNISTD_H 1
-
-/* Define if you have the sun library (-lsun). */
-/* #undef HAVE_LIBSUN */
+#define _IO_ferror_unlocked _IO_ferror_unlocked
diff --git a/src/bin/findutils/find/Jamfile b/src/bin/findutils/find/Jamfile
index 0b42e1c4b9..8f570f91b5 100644
--- a/src/bin/findutils/find/Jamfile
+++ b/src/bin/findutils/find/Jamfile
@@ -1,5 +1,6 @@
SubDir HAIKU_TOP src bin findutils find ;
+SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) gnulib lib ] ;
SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) lib ] ;
SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) ] ;
@@ -19,6 +20,6 @@ BinCommand find :
pred.c
tree.c
util.c
- : libfindutils.a : findutils.rdef ;
+ : libfindutils.a gnulibfindutils.a : findutils.rdef ;
SEARCH on [ FGristFiles findutils.rdef ] = [ FDirName $(SUBDIR) $(DOTDOT) ] ;
diff --git a/src/bin/findutils/find/defs.h b/src/bin/findutils/find/defs.h
index ec029de1d1..02d3650b88 100644
--- a/src/bin/findutils/find/defs.h
+++ b/src/bin/findutils/find/defs.h
@@ -1,19 +1,28 @@
/* defs.h -- data types and declarations.
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 91, 92, 93, 94, 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see .
+*/
+
+
+#ifndef INC_DEFS_H
+#define INC_DEFS_H 1
+
+#include
+#include
+#include
+#include
#if defined(HAVE_STRING_H) || defined(STDC_HEADERS)
#include
@@ -36,27 +45,106 @@ extern int errno;
#include
#endif
-#ifdef HAVE_UNISTD_H
+/* The presence of unistd.h is assumed by gnulib these days, so we
+ * might as well assume it too.
+ */
#include
-#endif
#include
-#include "regex.h"
-
-#if __STDC__
-# define P_(s) s
-#else
-# define P_(s) ()
+#if HAVE_LIMITS_H
+# include
+#endif
+#ifndef CHAR_BIT
+# define CHAR_BIT 8
#endif
+#if HAVE_INTTYPES_H
+# include
+#endif
+
+#include "regex.h"
+
+#ifndef S_IFLNK
+#define lstat stat
+#endif
+
+# ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+# endif
+
+int lstat PARAMS((const char *__path, struct stat *__statbuf));
+int stat PARAMS((const char *__path, struct stat *__statbuf));
+
+int optionl_stat PARAMS((const char *name, struct stat *p));
+int optionp_stat PARAMS((const char *name, struct stat *p));
+int optionh_stat PARAMS((const char *name, struct stat *p));
+
+int get_statinfo PARAMS((const char *pathname, const char *name, struct stat *p));
+
+
+
+#ifndef S_ISUID
+# define S_ISUID 0004000
+#endif
+#ifndef S_ISGID
+# define S_ISGID 0002000
+#endif
+#ifndef S_ISVTX
+# define S_ISVTX 0001000
+#endif
+#ifndef S_IRUSR
+# define S_IRUSR 0000400
+#endif
+#ifndef S_IWUSR
+# define S_IWUSR 0000200
+#endif
+#ifndef S_IXUSR
+# define S_IXUSR 0000100
+#endif
+#ifndef S_IRGRP
+# define S_IRGRP 0000040
+#endif
+#ifndef S_IWGRP
+# define S_IWGRP 0000020
+#endif
+#ifndef S_IXGRP
+# define S_IXGRP 0000010
+#endif
+#ifndef S_IROTH
+# define S_IROTH 0000004
+#endif
+#ifndef S_IWOTH
+# define S_IWOTH 0000002
+#endif
+#ifndef S_IXOTH
+# define S_IXOTH 0000001
+#endif
+
+#define MODE_WXUSR (S_IWUSR | S_IXUSR)
+#define MODE_R (S_IRUSR | S_IRGRP | S_IROTH)
+#define MODE_RW (S_IWUSR | S_IWGRP | S_IWOTH | MODE_R)
+#define MODE_RWX (S_IXUSR | S_IXGRP | S_IXOTH | MODE_RW)
+#define MODE_ALL (S_ISUID | S_ISGID | S_ISVTX | MODE_RWX)
+
+#if 1
+#include
+typedef bool boolean;
+#else
/* Not char because of type promotion; NeXT gcc can't handle it. */
typedef int boolean;
#define true 1
#define false 0
+#endif
-/* Pointer to function returning boolean. */
-typedef boolean (*PFB)();
+struct predicate;
+
+/* Pointer to a predicate function. */
+typedef boolean (*PRED_FUNC)(char *pathname, struct stat *stat_buf, struct predicate *pred_ptr);
/* The number of seconds in a day. */
#define DAYSECS 86400
@@ -70,6 +158,13 @@ enum comparison_type
COMP_EQ
};
+enum permissions_type
+{
+ PERM_AT_LEAST,
+ PERM_ANY,
+ PERM_EXACT
+};
+
enum predicate_type
{
NO_TYPE,
@@ -93,27 +188,63 @@ enum predicate_precedence
struct long_val
{
enum comparison_type kind;
- unsigned long l_val;
+ boolean negative; /* Defined only when representing time_t. */
+ uintmax_t l_val;
+};
+
+struct perm_val
+{
+ enum permissions_type kind;
+ mode_t val[2];
+};
+
+/* dir_id is used to support loop detection in find.c and
+ * also to support the -samefile test.
+ */
+struct dir_id
+{
+ ino_t ino;
+ dev_t dev;
};
struct size_val
{
enum comparison_type kind;
int blocksize;
- unsigned long size;
+ uintmax_t size;
};
+#define NEW_EXEC 1
+/*
+#undef NEW_EXEC
+*/
+
+#if !defined(NEW_EXEC)
struct path_arg
{
short offset; /* Offset in `vec' of this arg. */
short count; /* Number of path replacements in this arg. */
char *origarg; /* Arg with "{}" intact. */
};
+#endif
+
+#include "buildcmd.h"
struct exec_val
{
+#if defined(NEW_EXEC)
+ /* new-style */
+ boolean multiple; /* -exec {} \+ denotes multiple argument. */
+ struct buildcmd_control ctl;
+ struct buildcmd_state state;
+ char **replace_vec; /* Command arguments (for ";" style) */
+ int num_args;
+ boolean use_current_dir; /* If nonzero, don't chdir to start dir */
+ boolean close_stdin; /* If true, close stdin in the child. */
+#else
struct path_arg *paths; /* Array of args with path replacements. */
char **vec; /* Array of args to pass to program. */
+#endif
};
/* The format string for a -printf or -fprintf is chopped into one or
@@ -137,12 +268,14 @@ struct format_val
{
struct segment *segment; /* Linked list of segments. */
FILE *stream; /* Output stream to print on. */
+ boolean dest_is_tty; /* True if the destination is a terminal. */
+ struct quoting_options *quote_opts;
};
struct predicate
{
/* Pointer to the function that implements this predicate. */
- PFB pred_func;
+ PRED_FUNC pred_func;
/* Only used for debugging, but defined unconditionally so individual
modules can be compiled with -DDEBUG. */
@@ -156,12 +289,20 @@ struct predicate
/* The precedence of this node. Only has meaning for operators. */
enum predicate_precedence p_prec;
- /* True if this predicate node produces side effects. */
+ /* True if this predicate node produces side effects.
+ If side_effects are produced
+ then optimization will not be performed */
boolean side_effects;
+ /* True if this predicate node requires default print be turned off. */
+ boolean no_default_print;
+
/* True if this predicate node requires a stat system call to execute. */
boolean need_stat;
+ /* True if this predicate node requires knowledge of the file type. */
+ boolean need_type;
+
/* Information needed by the predicate processor.
Next to each member are listed the predicates that use it. */
union
@@ -169,19 +310,21 @@ struct predicate
char *str; /* fstype [i]lname [i]name [i]path */
struct re_pattern_buffer *regex; /* regex */
struct exec_val exec_vec; /* exec ok */
- struct long_val info; /* atime ctime mtime inum links */
+ struct long_val info; /* atime ctime gid inum links mtime
+ size uid */
struct size_val size; /* size */
uid_t uid; /* user */
gid_t gid; /* group */
time_t time; /* newer */
- unsigned long perm; /* perm */
- unsigned long type; /* type */
- FILE *stream; /* fprint fprint0 */
- struct format_val printf_vec; /* printf fprintf */
+ struct perm_val perm; /* perm */
+ struct dir_id fileid; /* samefile */
+ mode_t type; /* type */
+ FILE *stream; /* ls fls fprint0 */
+ struct format_val printf_vec; /* printf fprintf fprint */
} args;
/* The next predicate in the user input sequence,
- which repesents the order in which the user supplied the
+ which represents the order in which the user supplied the
predicates on the command line. */
struct predicate *pred_next;
@@ -190,30 +333,34 @@ struct predicate
processed. */
struct predicate *pred_left;
struct predicate *pred_right;
+
+ const struct parser_table* parser_entry;
};
+/* find.c. */
+int get_info PARAMS((const char *pathname, const char *name, struct stat *p, struct predicate *pred_ptr));
+int following_links(void);
+
+
/* find library function declarations. */
/* dirname.c */
-char *dirname P_((char *path));
+char *dirname PARAMS((char *path));
/* error.c */
-void error P_((int status, int errnum, char *message, ...));
+void error PARAMS((int status, int errnum, char *message, ...));
/* listfile.c */
-void list_file P_((char *name, char *relname, struct stat *statp, FILE *stream));
-char *get_link_name P_((char *name, char *relname));
-
-/* savedir.c */
-char *savedir P_((char *dir, unsigned name_size));
+void list_file PARAMS((char *name, char *relname, struct stat *statp, time_t current_time, int output_block_size, FILE *stream));
+char *get_link_name PARAMS((char *name, char *relname));
/* stpcpy.c */
#if !HAVE_STPCPY
-char *stpcpy P_((char *dest, const char *src));
+char *stpcpy PARAMS((char *dest, const char *src));
#endif
/* xgetcwd.c */
-char *xgetcwd P_((void));
+char *xgetcwd PARAMS((void));
/* xmalloc.c */
#if __STDC__
@@ -222,111 +369,243 @@ char *xgetcwd P_((void));
#define VOID char
#endif
-VOID *xmalloc P_((size_t n));
-VOID *xrealloc P_((VOID *p, size_t n));
-
-/* xstrdup.c */
-char *xstrdup P_((char *string));
-
/* find global function declarations. */
+/* find.c */
+/* SymlinkOption represents the choice of
+ * -P, -L or -P (default) on the command line.
+ */
+enum SymlinkOption
+ {
+ SYMLINK_NEVER_DEREF, /* Option -P */
+ SYMLINK_ALWAYS_DEREF, /* Option -L */
+ SYMLINK_DEREF_ARGSONLY /* Option -H */
+ };
+extern enum SymlinkOption symlink_handling; /* defined in find.c. */
+
+void set_follow_state PARAMS((enum SymlinkOption opt));
+void cleanup(void);
+
/* fstype.c */
-char *filesystem_type P_((char *path, char *relpath, struct stat *statp));
+char *filesystem_type PARAMS((const struct stat *statp, const char *path));
+char * get_mounted_filesystems (void);
+dev_t * get_mounted_devices PARAMS((size_t *));
+
+
+
+enum arg_type
+ {
+ ARG_OPTION, /* regular options like -maxdepth */
+ ARG_POSITIONAL_OPTION, /* options whose position is important (-follow) */
+ ARG_TEST, /* a like -name */
+ ARG_PUNCTUATION, /* like -o or ( */
+ ARG_ACTION /* like -print */
+ };
+
+
+struct parser_table;
+/* Pointer to a parser function. */
+typedef boolean (*PARSE_FUNC)(const struct parser_table *p,
+ char *argv[], int *arg_ptr);
+struct parser_table
+{
+ enum arg_type type;
+ char *parser_name;
+ PARSE_FUNC parser_func;
+ PRED_FUNC pred_func;
+};
/* parser.c */
-PFB find_parser P_((char *search_name));
-boolean parse_close P_((char *argv[], int *arg_ptr));
-boolean parse_open P_((char *argv[], int *arg_ptr));
-boolean parse_print P_((char *argv[], int *arg_ptr));
+const struct parser_table* find_parser PARAMS((char *search_name));
+boolean parse_open PARAMS((const struct parser_table* entry, char *argv[], int *arg_ptr));
+boolean parse_close PARAMS((const struct parser_table* entry, char *argv[], int *arg_ptr));
+boolean parse_print PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+void pred_sanity_check PARAMS((const struct predicate *predicates));
+void parse_begin_user_args PARAMS((char **args, int argno, const struct predicate *last, const struct predicate *predicates));
+void parse_end_user_args PARAMS((char **args, int argno, const struct predicate *last, const struct predicate *predicates));
+boolean parse_openparen PARAMS((const struct parser_table* entry, char *argv[], int *arg_ptr));
+boolean parse_closeparen PARAMS((const struct parser_table* entry, char *argv[], int *arg_ptr));
/* pred.c */
-boolean pred_amin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_and P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_anewer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_atime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_close P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_cmin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_cnewer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_comma P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_ctime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_empty P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_exec P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_false P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_fls P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_fprint P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_fprint0 P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_fprintf P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_fstype P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_gid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_group P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_ilname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_iname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_inum P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_ipath P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_links P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_lname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_ls P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_mmin P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_mtime P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_name P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_negate P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_newer P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_nogroup P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_nouser P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_ok P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_open P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_or P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_path P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_perm P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_print P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_print0 P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_prune P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_regex P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_size P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_true P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_type P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_uid P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_used P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_user P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-boolean pred_xtype P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
-char *find_pred_name P_((PFB pred_func));
+boolean pred_amin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_and PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_anewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_atime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_closeparen PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_cmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_cnewer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_comma PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_ctime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_delete PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_empty PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_exec PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_execdir PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_false PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_fls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_fprint PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_fprint0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_fprintf PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_fstype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_gid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_group PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_ilname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_iname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_inum PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_ipath PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_links PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_ls PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_mmin PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_mtime PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_name PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_negate PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_newer PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_nogroup PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_nouser PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_ok PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_okdir PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_openparen PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_or PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_path PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_perm PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_print PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_print0 PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_prune PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_quit PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_regex PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_samefile PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_size PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_true PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_type PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_uid PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_used PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_user PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+boolean pred_xtype PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr));
+
+
+
+int launch PARAMS((const struct buildcmd_control *ctl,
+ struct buildcmd_state *buildstate));
+
+
+char *find_pred_name PARAMS((PRED_FUNC pred_func));
+
+
+
#ifdef DEBUG
-void print_tree P_((struct predicate *node, int indent));
-void print_list P_((struct predicate *node));
+void print_tree PARAMS((FILE*, struct predicate *node, int indent));
+void print_list PARAMS((FILE*, struct predicate *node));
+void print_optlist PARAMS((FILE *fp, struct predicate *node));
#endif /* DEBUG */
/* tree.c */
-struct predicate *get_expr P_((struct predicate **input, int prev_prec));
-boolean opt_expr P_((struct predicate **eval_treep));
-boolean mark_stat P_((struct predicate *tree));
+struct predicate *
+get_expr PARAMS((struct predicate **input, short int prev_prec));
+boolean opt_expr PARAMS((struct predicate **eval_treep));
+boolean mark_stat PARAMS((struct predicate *tree));
+boolean mark_type PARAMS((struct predicate *tree));
/* util.c */
-char *basename P_((char *fname));
-struct predicate *get_new_pred P_((void));
-struct predicate *get_new_pred_chk_op P_((void));
-struct predicate *insert_primary P_((boolean (*pred_func )()));
-void usage P_((char *msg));
+struct predicate *get_new_pred PARAMS((const struct parser_table *entry));
+struct predicate *get_new_pred_chk_op PARAMS((const struct parser_table *entry));
+struct predicate *insert_primary PARAMS((const struct parser_table *entry));
+struct predicate *insert_primary_withpred PARAMS((const struct parser_table *entry, PRED_FUNC fptr));
+void usage PARAMS((char *msg));
extern char *program_name;
extern struct predicate *predicates;
extern struct predicate *last_pred;
-extern boolean do_dir_first;
-extern int maxdepth;
-extern int mindepth;
-extern int curdepth;
-extern time_t cur_day_start;
-extern boolean full_days;
-extern boolean no_leaf_check;
-extern boolean stay_on_filesystem;
-extern boolean stop_at_current_level;
-extern boolean have_stat;
-extern char *rel_pathname;
-#ifndef HAVE_FCHDIR
-extern char *starting_dir;
-#else
+
+struct options
+{
+ /* If true, process directory before contents. True unless -depth given. */
+ boolean do_dir_first;
+
+ /* If >=0, don't descend more than this many levels of subdirectories. */
+ int maxdepth;
+
+ /* If >=0, don't process files above this level. */
+ int mindepth;
+
+ /* If true, do not assume that files in directories with nlink == 2
+ are non-directories. */
+ boolean no_leaf_check;
+
+ /* If true, don't cross filesystem boundaries. */
+ boolean stay_on_filesystem;
+
+ /* If true, we ignore the problem where we find that a directory entry
+ * no longer exists by the time we get around to processing it.
+ */
+ boolean ignore_readdir_race;
+
+/* If true, we issue warning messages
+ */
+ boolean warnings;
+ time_t start_time; /* Time at start of execution. */
+
+ /* Seconds between 00:00 1/1/70 and either one day before now
+ (the default), or the start of today (if -daystart is given). */
+ time_t cur_day_start;
+
+ /* If true, cur_day_start has been adjusted to the start of the day. */
+ boolean full_days;
+
+ int output_block_size; /* Output block size. */
+
+ enum SymlinkOption symlink_handling;
+
+
+ /* Pointer to the function used to stat files. */
+ int (*xstat) (const char *name, struct stat *statbuf);
+
+
+ /* Indicate if we can implement safely_chdir() using the O_NOFOLLOW
+ * flag to open(2).
+ */
+ boolean open_nofollow_available;
+
+ /* The variety of regular expression that we support.
+ * The default is POSIX Basic Regular Expressions, but this
+ * can be changed with the positional option, -regextype.
+ */
+ int regex_options;
+};
+extern struct options options;
+
+
+struct state
+{
+ /* Current depth; 0 means current path is a command line arg. */
+ int curdepth;
+
+ /* If true, we have called stat on the current path. */
+ boolean have_stat;
+
+ /* If true, we know the type of the current path. */
+ boolean have_type;
+ mode_t type; /* this is the actual type */
+
+ /* The file being operated on, relative to the current directory.
+ Used for stat, readlink, remove, and opendir. */
+ char *rel_pathname;
+
+ /* Length of current path. */
+ int path_length;
+
+ /* If true, don't descend past current directory.
+ Can be set by -prune, -maxdepth, and -xdev/-mount. */
+ boolean stop_at_current_level;
+
+ /* Status value to return to system. */
+ int exit_status;
+};
+extern struct state state;
+
+extern char const *starting_dir;
extern int starting_desc;
+#if ! defined HAVE_FCHDIR && ! defined fchdir
+# define fchdir(fd) (-1)
+#endif
+
#endif
-extern int exit_status;
-extern int path_length;
-extern int (*xstat) ();
-extern boolean dereference;
diff --git a/src/bin/findutils/find/find.1 b/src/bin/findutils/find/find.1
index d6280d4046..9be362f5e0 100644
--- a/src/bin/findutils/find/find.1
+++ b/src/bin/findutils/find/find.1
@@ -1,13 +1,14 @@
-.TH FIND 1L \" -*- nroff -*-
+.TH FIND 1 \" -*- nroff -*-
.SH NAME
find \- search for files in a directory hierarchy
.SH SYNOPSIS
-.B find
-[path...] [expression]
+.B find
+[\-H] [\-L] [\-P] [path...] [expression]
.SH DESCRIPTION
This manual page
documents the GNU version of
.BR find .
+GNU
.B find
searches the directory tree rooted at each given file name by
evaluating the given expression from left to right, according to the
@@ -17,41 +18,162 @@ known (the left hand side is false for \fIand\fR operations, true for
.B find
moves on to the next file name.
.PP
-The first argument that begins with `\-', `(', `)', `,', or `!' is taken
-to be the beginning of the expression; any arguments before it are
-paths to search, and any arguments after it are the rest of the
-expression. If no paths are given, the current directory is used. If
-no expression is given, the expression `\-print' is used.
+If you are using
+.B find
+in an environment where security is important (for example if you are
+using it to seach directories that are writable by other users), you
+should read the "Security Considerations" chapter of the findutils
+documentation, which is called \fBFinding Files\fP and comes with
+findutils. That document also includes a lot more detail
+and discussion than this manual page, so you may find it a more useful
+source of information.
+.SH OPTIONS
+The `\-H', `\-L' and `\-P' options control the treatment of symbolic
+links. Command-line arguments following these are taken to be names
+of files or directories to be examined, up to the first argument that
+begins with `\-', `(', `)', `,', or `!'. That argument and any
+following arguments are taken to be the expression describing what is
+to be searched for. If no paths are given, the current directory is
+used. If no expression is given, the expression `\-print' is used
+(but you should probably consider using `\-print0' instead, anyway).
.PP
+This manual page talks about `options' within the expression list.
+These options control the behaviour of
.B find
-exits with status 0 if all files are processed successfully, greater
-than 0 if errors occur.
-.SH EXPRESSIONS
+but are specified immediately after the last path name. The three
+`real' options `\-H', `\-L' and `\-P' must appear before the first
+path name, if at all.
+.IP \-P
+Never follow symbolic links. This is the default behaviour. When
+.B find
+examines or prints information a file, and the file is a symbolic
+link, the information used shall be taken from the properties of the
+symbolic link itself.
+
+.IP \-L
+Follow symbolic links. When
+.B find
+examines or prints information about files, the information used shall
+be taken from the properties of the file to which the link points, not
+from the link itself (unless it is a broken symbolic link or
+.B find
+is unable to examine the file to which the link points). Use of this
+option implies \-noleaf. If you later use the \-P option, \-noleaf
+will still be in effect. If \-L is in effect and
+.B find
+discovers a symbolic link to a subdirectory during its search,
+the subdirectory pointed to by the symbolic link will be searched.
+.IP
+When the \-L option is in effect, the \-type predicate will always
+match against the type of the file that a symbolic link points to
+rather than the link itself (unless the symbolic link is broken).
+Using \-L causes the \-lname and \-ilname predicates always to return
+false.
+
+.IP \-H
+Do not follow symbolic links, except while processing the command
+line arguments. When
+.B find
+examines or prints information about files, the information used
+shall be taken from the properties of the symbolic link itself. The
+only exception to this behaviour is when a file specified on the
+command line is a symbolic link, and the link can be resolved. For
+that situation, the information used is taken from whatever the link
+points to (that is, the link is followed). The information about the
+link itself is used as a fallback if the file pointed to by the
+symbolic link cannot be examined. If \-H is in effect and one of the
+paths specified on the command line is a symbolic link to a directory,
+the contents of that directory will be examined (though of course
+\-maxdepth 0 would prevent this).
.P
+If more than one of \-H, \-L and \-P is specified, each overrides the
+others; the last one appearing on the command line takes effect.
+Since it is the default, the \-P option should be considered to be in
+effect unless either \-H or \-L is specified.
+
+GNU
+.B find
+frequently stats files during the processing of the command line
+itself, before any searching has begun. These options also affect how
+those arguments are processed. Specifically, there are a number of
+tests that compare files listed on the command line against a file we
+are currently considering. In each case, the file specified on the
+command line will have been examined and some of its properties will
+have been saved. If the named file is in fact a symbolic link, and
+the \-P option is in effect (or if neither \-H nor \-L were
+specified), the information used for the comparison will be taken from
+the properties of the symbolic link. Otherwise, it will be taken from
+the properties of the file the link points to. If
+.B find
+cannot follow the link (for example because it has insufficient
+privileges or the link points to a nonexistent file) the properties of
+the link itself will be used.
+.P
+When the \-H or \-L options are in effect, any symbolic links listed
+as the argument of \-newer will be dereferenced, and the timestamp
+will be taken from the file to which the symbolic link points. The
+same consideration applies to \-anewer and \-cnewer.
+
+The \-follow option has a similar effect to \-L, though it takes
+effect at the point where it appears (that is, if \-L is not used but
+\-follow is, any symbolic links appearing after \-follow on the
+command line will be dereferenced, and those before it will not).
+
+.P
+.SH EXPRESSIONS
The expression is made up of options (which affect overall operation
-rather than the processing of a specific file, and always return true),
-tests (which return a true or false value), and actions (which have side
-effects and return a true or false value), all separated by operators.
-\-and is assumed where the operator is omitted. If the expression contains
-no actions other than \-prune, \-print is performed on all files
-for which the expression is true.
+rather than the processing of a specific file, and always return
+true), tests (which return a true or false value), and actions (which
+have side effects and return a true or false value), all separated by
+operators. \-and is assumed where the operator is omitted.
+
+If the expression contains no actions other than \-prune, \-print is
+performed on all files for which the expression is true.
+
.SS OPTIONS
.P
-All options always return true. They always take effect, rather than
-being processed only when their place in the expression is reached.
-Therefore, for clarity, it is best to place them at the beginning of
-the expression.
+All options always return true. Except for \-follow and \-daystart,
+the options affect all tests, including tests specified before the
+option. This is because the options are processed when the command
+line is parsed, while the tests don't do anything until files are
+examined. The \-follow and \-daystart options are different in this
+respect, and have an effect only on tests which appear later in the
+command line. Therefore, for clarity, it is best to place them at the
+beginning of the expression. A warning is issued if you don't do
+this.
.IP \-daystart
Measure times (for \-amin, \-atime, \-cmin, \-ctime, \-mmin, and \-mtime)
-from the beginning of today rather than from 24 hours ago.
+from the beginning of today rather than from 24 hours ago. This
+option only affects tests which appear later on the command line.
.IP \-depth
Process each directory's contents before the directory itself.
+.IP \-d
+A synonym for \-depth, for compatibility with FreeBSD, NetBSD, MacOS X and OpenBSD.
.IP \-follow
-Dereference symbolic links. Implies \-noleaf.
+Deprecated; use the \-L option instead. Dereference symbolic links.
+Implies \-noleaf. The \-follow option affects only those tests which
+appear after it on the command line. Unless the \-H or \-L option has
+been specified, the position of the \-follow option changes the
+behaviour of the \-newer predicate; any files listed as the argument
+of \-newer will be dereferenced if they are symbolic links. The same
+consideration applies to \-anewer and \-cnewer. Similarly, the \-type
+predicate will always match against the type of the file that a
+symbolic link points to rather than the link itself. Using \-follow
+causes the \-lname and \-ilname predicates always to return false.
.IP "\-help, \-\-help"
Print a summary of the command-line usage of
.B find
and exit.
+.IP \-ignore_readdir_race
+Normally, \fBfind\fR will emit an error message when it fails to stat a file.
+If you give this option and a file is deleted between the time \fBfind\fR
+reads the name of the file from the directory and the time it tries to stat
+the file, no error message will be issued. This also applies to files
+or directories whose names are given on the command line. This option takes
+effect at the time the command line is read, which means that you cannot search
+one part of the filesystem with this option on and part of it with this option
+off (if you need to do that, you will need to issue two \fBfind\fR commands
+instead, one with the option and one without it).
.IP "\-maxdepth \fIlevels\fR"
Descend at most \fIlevels\fR (a non-negative integer) levels of
directories below the command line arguments. `\-maxdepth 0' means
@@ -64,6 +186,8 @@ the command line arguments.
Don't descend directories on other filesystems. An alternate name for
\-xdev, for compatibility with some other versions of
.BR find .
+.IP \-noignore_readdir_race
+Turns off the effect of \-ignore_readdir_race.
.IP "\-noleaf"
Do not optimize by assuming that directories contain 2 fewer
subdirectories than their hard link count. This option is needed when
@@ -79,10 +203,27 @@ than the directory's link count, it knows that the rest of the entries
in the directory are non-directories (`leaf' files in the directory
tree). If only the files' names need to be examined, there is no need
to stat them; this gives a significant increase in search speed.
+.IP "\-regextype \fItype\fR"
+Changes the regular expression syntax understood by
+.B \-regex
+and
+.B \-iregex
+tests which occur later on the command line. Currently-implemented
+types are emacs (this is the default), posix-awk, posix-basic,
+posix-egrep and posix-extended.
+
.IP "\-version, \-\-version"
Print the \fBfind\fR version number and exit.
+.IP "\-warn, \-nowarn"
+Turn warning messages on or off. These warnings apply only to the
+command line usage, not to any conditions that
+.B find
+might encounter when it searches directories. The default behaviour
+corresponds to \-warn if standard input is a tty, and to \-nowarn
+otherwise.
.IP \-xdev
Don't descend directories on other filesystems.
+
.SS TESTS
.P
Numeric arguments can be specified as
@@ -98,19 +239,33 @@ for exactly
.IP "\-amin \fIn\fR"
File was last accessed \fIn\fR minutes ago.
.IP "\-anewer \fIfile\fR"
-File was last accessed more recently than \fIfile\fR was modified.
-\-anewer is affected by \-follow only if \-follow comes before
-\-anewer on the command line.
+File was last accessed more recently than \fIfile\fR was modified. If
+\fIfile\fR is a symbolic link and the \-H option or the \-L option is
+in effect, the access time of the file it points to is always
+used.
.IP "\-atime \fIn\fR"
-File was last accessed \fIn\fR*24 hours ago.
+File was last accessed \fIn\fR*24 hours ago.
+When find figures out how many 24-hour periods ago the file
+was last accessed, any fractional part is ignored, so to match
+.B \-atime
+.BR +1 ,
+a file has to have been accessed at least
+.I two
+days ago.
.IP "\-cmin \fIn\fR"
File's status was last changed \fIn\fR minutes ago.
.IP "\-cnewer \fIfile\fR"
-File's status was last changed more recently than \fIfile\fR was modified.
-\-cnewer is affected by \-follow only if \-follow comes before
-\-cnewer on the command line.
+File's status was last changed more recently than \fIfile\fR was
+modified. If \fIfile\fR is a symbolic link and the \-H option or the
+\-L option is in effect, the status-change time of the file it points
+to is always used.
+
.IP "\-ctime \fIn\fR"
File's status was last changed \fIn\fR*24 hours ago.
+See the comments for
+.B \-atime
+to understand how rounding affects the interpretation of file status
+change times.
.IP \-empty
File is empty and is either a regular file or a directory.
.IP \-false
@@ -127,75 +282,157 @@ File's numeric group ID is \fIn\fR.
File belongs to group \fIgname\fR (numeric group ID allowed).
.IP "\-ilname \fIpattern\fR"
Like \-lname, but the match is case insensitive.
+If the \-L option or the \-follow option is in effect, this test
+returns false unless the symbolic link is broken.
.IP "\-iname \fIpattern\fR"
Like \-name, but the match is case insensitive. For example, the
patterns `fo*' and `F??' match the file names `Foo', `FOO', `foo',
-`fOo', etc.
+`fOo', etc. In these patterns, unlike filename expansion by the
+shell, an initial '.' can be matched by '*'. That is,
+.B find \-name *bar
+will match the file `.foobar'. Please note that you should quote
+patterns as a matter of course, otherwise the shell will expand any
+wildcard characters in them.
+
.IP "\-inum \fIn\fR"
-File has inode number \fIn\fR.
+File has inode number \fIn\fR. It is normally easier to use the
+.B \-samefile
+test instead.
.IP "\-ipath \fIpattern\fR"
-Like \-path, but the match is case insensitive.
+Behaves in the same way as \-iwholename. This option is deprecated,
+so please do not use it.
.IP "\-iregex \fIpattern\fR"
Like \-regex, but the match is case insensitive.
+.IP "\-iwholename \fIpattern\fR"
+Like \-wholename, but the match is case insensitive.
.IP "\-links \fIn\fR"
File has \fIn\fR links.
.IP "\-lname \fIpattern\fR"
File is a symbolic link whose contents match shell pattern
\fIpattern\fR. The metacharacters do not treat `/' or `.' specially.
+If the \-L option or the \-follow option is in effect, this test
+returns false unless the symbolic link is broken.
.IP "\-mmin \fIn\fR"
File's data was last modified \fIn\fR minutes ago.
.IP "\-mtime \fIn\fR"
File's data was last modified \fIn\fR*24 hours ago.
+See the comments for
+.B \-atime
+to understand how rounding affects the interpretation of file
+modification times.
.IP "\-name \fIpattern\fR"
Base of file name (the path with the leading directories removed)
matches shell pattern \fIpattern\fR. The metacharacters (`*', `?',
-and `[]') do not match a `.' at the start of the base name. To ignore
-a directory and the files under it, use \-prune; see an example in the
-description of \-path.
+and `[]') match a `.' at the start of the base name (this is a change
+in findutils-4.2.2; see section STANDARDS CONFORMANCE below). To ignore a
+directory and the files under it, use \-prune; see an example in the
+description of \-wholename. Braces are not recognised as being
+special, despite the fact that some shells including Bash imbue braces
+with a special meaning in shell patterns. The filename matching is
+performed with the use of the
+.BR fnmatch (3)
+library function. Don't forget to enclose the pattern in quotes
+in order to protect it from expansion by the shell.
+
.IP "\-newer \fIfile\fR"
-File was modified more recently than \fIfile\fR.
-\-newer is affected by \-follow only if \-follow comes before
-\-newer on the command line.
+File was modified more recently than \fIfile\fR. If \fIfile\fR is a
+symbolic link and the \-H option or the \-L option is in effect, the
+modification time of the file it points to is always used.
.IP \-nouser
No user corresponds to file's numeric user ID.
.IP \-nogroup
No group corresponds to file's numeric group ID.
.IP "\-path \fIpattern\fR"
-File name matches shell pattern \fIpattern\fR. The metacharacters do
-not treat `/' or `.' specially; so, for example,
-.br
-.in +1i
-find . \-path './sr*sc'
-.br
-.in -1i
-will print an entry for a directory called './src/misc' (if one
-exists). To ignore a whole directory tree, use \-prune rather than
-checking every file in the tree. For example, to skip the
-directory `src/emacs' and all files and directories under it, and
-print the names of the other files found, do something like this:
-.br
-.in +1i
-find . \-path './src/emacs' -prune -o -print
-.br
-.in -1i
+See \-wholename. The predicate \-path is also supported by HP-UX
+.BR find .
.IP "\-perm \fImode\fR"
File's permission bits are exactly \fImode\fR (octal or symbolic).
-Symbolic modes use mode 0 as a point of departure.
+Since an exact match is required, if you want to use this form for
+symbolic modes, you may have to specify a rather complex mode string.
+For example '\-perm g=w' will only match files which have mode 0020
+(that is, ones for which group write permission is the only permission
+set). It is more likely that you will want to use the '/' or '-'
+forms, for example '\-perm \-g=w', which matches any file with group
+write permission. See the
+.B EXAMPLES
+section for some illustrative examples.
.IP "\-perm \-\fImode\fR"
All of the permission bits \fImode\fR are set for the file.
+Symbolic modes are accepted in this form, and this is usually the way
+in which would want to use them. You must specify 'u', 'g' or 'o' if
+you use a symbolic mode. See the
+.B EXAMPLES
+section for some illustrative examples.
+.IP "\-perm /\fImode\fR"
+Any of the permission bits \fImode\fR are set for the file. Symbolic
+modes are accepted in this form. You must specify 'u', 'g' or 'o' if
+you use a symbolic mode. See the
+.B EXAMPLES
+section for some illustrative examples. If no permission bits in
+.I mode
+are set, this test currently matches no files. However, it will soon
+be changed to match any file (the idea is to be more consistent with
+the behaviour of
+.B perm
+.BR \-000 ).
.IP "\-perm +\fImode\fR"
-Any of the permission bits \fImode\fR are set for the file.
+Deprecated, old way of searching for files with any of the permission
+bits in \fImode\fR set. You should use
+.B \-perm \fI/mode\fR
+instead. Trying to use the '+' syntax with symbolic modes will yield
+surprising results. For example, '+u+x' is a valid symbolic mode
+(equivalent to +u,+x, i.e. 0111) and will therefore not be evaluated
+as
+.B \-perm +\fImode\fR
+but instead as the exact mode specifier
+.B \-perm \fImode\fR
+and so it matches files with exact permissions 0111 instead of files with any
+execute bit set. If you found this paragraph confusing, you're not
+alone - just use
+.B \-perm /\fImode\fR.
+This form of the
+.B \-perm
+test is deprecated because the POSIX specification requires the
+interpretation of a leading '+' as being part of a symbolic mode, and
+so we switched to using '/' instead.
+
.IP "\-regex \fIpattern\fR"
File name matches regular expression \fIpattern\fR. This is a match
on the whole path, not a search. For example, to match a file named
`./fubar3', you can use the regular expression `.*bar.' or `.*b.*3',
-but not `b.*r3'.
-.IP "\-size \fIn\fR[bckw]"
-File uses \fIn\fP units of space. The units are 512-byte blocks by
-default or if `b' follows \fIn\fP, bytes if `c' follows \fIn\fP,
-kilobytes if `k' follows \fIn\fP, or 2-byte words if `w' follows \fIn\fP.
+but not `f.*r3'. The regular expressions understood by
+.B find
+are by default Emacs Regular Expressions, but this can be
+changed with the
+.B \-regextype
+option.
+.IP "\-samefile \fIname\fR"
+File refers to the same inode as \fIname\fR. When \-L is in effect,
+this can include symbolic links.
+.IP "\-size \fIn\fR[cwbkMG]"
+File uses \fIn\fP units of space. The following suffixes
+can be used:
+.RS
+.IP `b'
+for 512-byte blocks (this is the default if no suffix is used)
+.IP `c'
+for bytes
+.IP `w'
+for two-byte words
+.IP `k'
+for Kilobytes (units of 1024 bytes)
+.IP `M'
+for Megabytes (units of 1048576 bytes)
+.IP `G'
+for Gigabytes (units of 1073741824 bytes)
+.RE
+.IP
The size does not count indirect blocks, but it does count blocks in
-sparse files that are not actually allocated.
+sparse files that are not actually allocated. Bear in mind that the
+`%k' and `%b' format specifiers of \-printf handle sparse files
+differently. The `b' suffix always denotes 512-byte blocks and never
+1 Kilobyte blocks, which is different to the behaviour of \-ls.
+
.IP \-true
Always true.
.IP "\-type \fIc\fR"
@@ -212,9 +449,13 @@ named pipe (FIFO)
.IP f
regular file
.IP l
-symbolic link
+symbolic link; this is never true if the \-L option or the \-follow
+option is in effect, unless the symbolic link is broken. If you want
+to search for symbolic links when \-L is in effect, use \-xtype.
.IP s
socket
+.IP D
+door (Solaris)
.RE
.IP "\-uid \fIn\fR"
File's numeric user ID is \fIn\fR.
@@ -222,13 +463,37 @@ File's numeric user ID is \fIn\fR.
File was last accessed \fIn\fR days after its status was last changed.
.IP "\-user \fIuname\fR"
File is owned by user \fIuname\fR (numeric user ID allowed).
+.IP "\-wholename \fIpattern\fR"
+File name matches shell pattern \fIpattern\fR. The metacharacters do
+not treat `/' or `.' specially; so, for example,
+.br
+.in +1i
+find . \-wholename './sr*sc'
+.br
+.in -1i
+will print an entry for a directory called './src/misc' (if one
+exists). To ignore a whole directory tree, use \-prune rather than
+checking every file in the tree. For example, to skip the
+directory `src/emacs' and all files and directories under it, and
+print the names of the other files found, do something like this:
+.br
+.in +1i
+find . \-wholename './src/emacs' \-prune \-o \-print
+.br
+.in -1i
.IP "\-xtype \fIc\fR"
The same as \-type unless the file is a symbolic link. For symbolic
-links: if \-follow has not been given, true if the file is a link to a
-file of type \fIc\fR; if \-follow has been given, true if \fIc\fR is
-`l'. In other words, for symbolic links, \-xtype checks the type of
-the file that \-type does not check.
+links: if the \-H or \-P option was specified, true if the file is a
+link to a file of type \fIc\fR; if the \-L option has been given, true
+if \fIc\fR is `l'. In other words, for symbolic links, \-xtype checks
+the type of the file that \-type does not check.
+
.SS ACTIONS
+.IP "\-delete\fR"
+Delete files; true if removal succeeded. If the removal failed, an
+error message is issued. Use of this action automatically turns on
+the '\-depth' option.
+
.IP "\-exec \fIcommand\fR ;"
Execute \fIcommand\fR; true if 0 status is returned. All following
arguments to
@@ -240,36 +505,113 @@ command, not just in arguments where it is alone, as in some versions
of
.BR find .
Both of these constructions might need to be escaped (with a `\e') or
-quoted to protect them from expansion by the shell. The command is
-executed in the starting directory.
+quoted to protect them from expansion by the shell. See the
+.B EXAMPLES
+section for examples of the use of the `\-exec' option. The specified
+command is run once for each matched file.
+The command is executed in the starting directory. There are
+unavoidable security problems surrounding use of the \-exec option;
+you should use the \-execdir option instead.
+
+.IP "\-exec \fIcommand\fR {} +"
+This variant of the \-exec option runs the specified command on the
+selected files, but the command line is built by appending each
+selected file name at the end; the total number of invocations of the
+command will be much less than the number of matched files. The
+command line is built in much the same way that
+.B xargs
+builds its command lines. Only one instance of '{}' is allowed within
+the command. The command is executed in the starting directory.
+
+.IP "\-execdir \fIcommand\fR ;"
+.IP "\-execdir \fIcommand\fR {} +"
+Like \-exec, but the specified command is run from the subdirectory
+containing the matched file, which is not normally the directory in
+which you started
+.BR find .
+This a much more secure method for invoking commands, as it avoids
+race conditions during resolution of the paths to the matched files.
+As with the \-exec option, the '+' form of \-execdir will build a
+command line to process more than one matched file, but any given
+invocation of
+.I command
+will only list files that exist in the same subdirectory. If you use
+this option, you must ensure that your
+.B $PATH
+environment variable does not reference the current directory;
+otherwise, an attacker can run any commands they like by leaving an
+appropriately-named file in a directory in which you will run
+\-execdir.
+
.IP "\-fls \fIfile\fR"
True; like \-ls but write to \fIfile\fR like \-fprint.
+The output file is always created, even if the predicate is never
+matched.
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
+
.IP "\-fprint \fIfile\fR"
True; print the full file name into file \fIfile\fR. If \fIfile\fR
does not exist when \fBfind\fR is run, it is created; if it does
exist, it is truncated. The file names ``/dev/stdout'' and
``/dev/stderr'' are handled specially; they refer to the standard
output and standard error output, respectively.
+The output file is always created, even if the predicate is never matched.
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
.IP "\-fprint0 \fIfile\fR"
True; like \-print0 but write to \fIfile\fR like \-fprint.
+The output file is always created, even if the predicate is never matched.
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
.IP "\-fprintf \fIfile\fR \fIformat\fR"
True; like \-printf but write to \fIfile\fR like \-fprint.
+The output file is always created, even if the predicate is never matched.
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
.IP "\-ok \fIcommand\fR ;"
Like \-exec but ask the user first (on the standard input); if the
response does not start with `y' or `Y', do not run the command, and
-return false.
+return false. If the command is run, its standard input is redirected
+from
+.BR /dev/null .
+
.IP \-print
-True; print the full file name on the standard output, followed by a newline.
+True; print the full file name on the standard output, followed by a
+newline. If you are piping the output of
+.B find
+into another program and there is the faintest possibility that the files
+which you are searching for might contain a newline, then you should
+seriously consider using the `\-print0' option instead of `\-print'.
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
+.IP "\-okdir \fIcommand\fR ;"
+Like \-execdir but ask the user first (on the standard input); if the
+response does not start with `y' or `Y', do not run the command, and
+return false. If the command is run, its standard input is redirected
+from
+.BR /dev/null .
.IP \-print0
True; print the full file name on the standard output, followed by a
-null character. This allows file names that contain newlines to be
-correctly interpreted by programs that process the \fBfind\fR output.
+null character (instead of the newline character that `\-print' uses).
+This allows file names that contain newlines or other types of white
+space to be correctly interpreted by programs that process the
+\fBfind\fR output. This option corresponds to the `\-0' option of
+.BR xargs .
.IP "\-printf \fIformat\fR"
True; print \fIformat\fR on the standard output, interpreting `\e'
escapes and `%' directives. Field widths and precisions can be
-specified as with the `printf' C function. Unlike \-print, \-printf
-does not add a newline at the end of the string. The escapes and
-directives are:
+specified as with the `printf' C function. Please note that many of
+the fields are printed as %s rather than %d, and this may mean that
+flags don't work as you might expect. This also means that the `\-'
+flag does work (it forces fields to be left-aligned). Unlike \-print,
+\-printf does not add a newline at the end of the string. The escapes
+and directives are:
.RS
.IP \ea
Alarm bell.
@@ -287,8 +629,12 @@ Carriage return.
Horizontal tab.
.IP \ev
Vertical tab.
+.IP \e\0
+ASCII NUL.
.IP \e\e
A literal backslash (`\e').
+.IP \eNNN
+The character whose ASCII code is NNN (octal).
.PP
A `\e' character followed by any other character is treated as an
ordinary character, so they both are printed.
@@ -301,7 +647,7 @@ File's last access time in the format specified by \fIk\fR, which is
either `@' or a directive for the C `strftime' function. The possible
values for \fIk\fR are listed below; some of them might not be
available on all systems, due to differences in `strftime' between
-systems.
+systems.
.RS
.IP @
seconds since Jan. 1, 1970, 00:00 GMT.
@@ -325,6 +671,10 @@ time, 12-hour (hh:mm:ss [AP]M)
second (00..61)
.IP T
time, 24-hour (hh:mm:ss)
+.IP +
+Date and time, separated by '+', for example `2004\-04\-28+22:22:05'.
+The time is given in the current timezone (which may be affected by
+setting the TZ environment variable). This is a GNU extension.
.IP X
locale's time representation (H:M:S)
.IP Z
@@ -365,7 +715,9 @@ last two digits of year (00..99)
year (1970...)
.RE
.IP %b
-File's size in 512-byte blocks (rounded up).
+The amount of disk space used for this file in 512-byte blocks. Since disk
+space is allocated in multiples of the filesystem block size this is usually
+greater than %s/512, but it can also be smaller if the file is a sparse file.
.IP %c
File's last status change time in the format returned by the C `ctime'
function.
@@ -375,6 +727,9 @@ which is the same as for %A.
.IP %d
File's depth in the directory tree; 0 means the file is a command line
argument.
+.IP %D
+The device number on which the file exists (the st_dev field of struct
+stat), in decimal.
.IP %f
File's name with any leading directories removed (only the last element).
.IP %F
@@ -386,16 +741,31 @@ File's group name, or numeric group ID if the group has no name.
File's numeric group ID.
.IP %h
Leading directories of file's name (all but the last element).
+If the file name contains no slashes (since it is in the current
+directory) the %h specifier expands to ".".
.IP %H
Command line argument under which file was found.
.IP %i
File's inode number (in decimal).
.IP %k
-File's size in 1K blocks (rounded up).
+The amount of disk space used for this file in 1K blocks. Since disk space is
+allocated in multiples of the filesystem block size this is usually greater
+than %s/1024, but it can also be smaller if the file is a sparse file.
.IP %l
Object of symbolic link (empty string if file is not a symbolic link).
.IP %m
-File's permission bits (in octal).
+File's permission bits (in octal). This option uses the 'traditional'
+numbers which most Unix implementations use, but if your particular
+implementation uses an unusual ordering of octal permissions bits, you
+will see a difference between the actual value of the file's mode and
+the output of %m. Normally you will want to have a leading
+zero on this number, and to do this, you should use the
+.B #
+flag (as in, for example, '%#m').
+.IP %M
+File's permissions (in symbolic form, as for
+.BR ls ).
+This directive is supported in findutils 4.2.5 and later.
.IP %n
Number of hard links to file.
.IP %p
@@ -415,18 +785,119 @@ which is the same as for %A.
File's user name, or numeric user ID if the user has no name.
.IP %U
File's numeric user ID.
+.IP %y
+File's type (like in ls \-l), U=unknown type (shouldn't happen)
+.IP %Y
+File's type (like %y), plus follow symlinks: L=loop, N=nonexistent
.PP
-A `%' character followed by any other character is discarded (but the
-other character is printed).
+A `%' character followed by any other character is discarded, but the
+other character is printed (don't rely on this, as further format
+characters may be introduced). A `%' at the end of the format
+argument causes undefined behaviour since there is no following
+character. In some locales, it may hide your door keys, while in
+others it may remove the final page from the novel you are reading.
+
+The %m and %d directives support the
+.B #
+,
+.B 0
+and
+.B +
+flags, but the other directives do not, even if they
+print numbers. Numeric directives that do not support these flags
+include
+.BR G ,
+.BR U ,
+.BR b ,
+.BR D ,
+.B k
+and
+.BR n .
+The `\-' format flag is supported and changes the alignment of a field
+from right-justified (which is the default) to left-justified.
+.PP
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
+
+
.RE
.IP \-prune
-If \-depth is not given, true; do not descend the current directory.
+If \-depth is not given, true; if the file is a directory, do not descend
+into it.
.br
If \-depth is given, false; no effect.
+
+.IP "\-quit"
+Exit immediately. No child processes will be left running, but no more
+paths specified on the command line will be processed. For example,
+.B find /tmp/foo /tmp/bar \-print \-quit
+will print only
+.BR /tmp/foo .
+Any command lines which have been built up with
+.B \-execdir ... {} +
+will be invoked before
+.B find
+exits. The exit status may or may not be zero, depending on whether
+an error has already occurred.
+
.IP \-ls
True; list current file in `ls \-dils' format on standard output.
The block counts are of 1K blocks, unless the environment variable
POSIXLY_CORRECT is set, in which case 512-byte blocks are used.
+See the
+.B UNUSUAL FILENAMES
+section for information about how unusual characters in filenames are handled.
+
+
+.SS UNUSUAL FILENAMES
+Many of the actions of
+.B find
+result in the printing of data which is under the control of other
+users. This includes file names, sizes, modification times and so
+forth. File names are a potential problem since they can contain any
+character except '\\0' and '/'. Unusual characters in file names can
+do unexpected and often undesirable things to your terminal (for
+example, changing the settings of your function keys on some
+terminals). Unusual characters are handled differently by various
+actions, as described below.
+.IP "\-print0, \-fprint0\"
+Always print the exact filename, unchanged, even if the output is
+going to a terminal.
+.IP "\-ls, \-fls"
+Unusual characters are always escaped. White space, backslash, and
+double quote characters are printed using C-style escaping (for
+example '\\f', '\\"'). Other unusual characters are printed using an
+octal escape. Other printable characters (for \-ls and \-fls these are
+the characters between octal 041 and 0176) are printed as-is.
+.IP "\-printf, \-fprintf"
+If the output is not going to a terminal, it is printed as-is.
+Otherwise, the result depends on which directive is in use. The
+directives %D, %F, %g, %G, %H, %Y, and %y expand to values which are
+not under control of files' owners, and so are printed as-is. The
+directives %a, %b, %c, %d, %i, %k, %m, %M, %n, %s, %t, %u and %U have
+values which are under the control of files' owners but which cannot
+be used to send arbitrary data to the terminal, and so these are
+printed as-is. The directives %f, %h, %l, %p and %P are quoted. This
+quoting is performed in the same way as for GNU
+.BR ls .
+This is not the same quoting mechanism as the one used for \-ls and
+\-fls. If you are able to decide what format to use for the output
+of
+.B find
+then it is normally better to use '\\0' as a terminator
+than to use newline, as file names can contain white space and newline
+characters.
+.IP "\-print, \-fprint"
+Quoting is handled in the same way as for \-printf and \-fprintf.
+If you are using
+.B find
+in a script or in a situation where the matched files might have
+arbitrary names, you should consider using \-print0 instead of
+\-print.
+.P
+The \-ok and \-okdir actions print the current filename as-is. This
+may change in a future release.
.SS OPERATORS
.P
Listed in order of decreasing precedence:
@@ -435,21 +906,356 @@ Force precedence.
.IP "! \fIexpr\fR"
True if \fIexpr\fR is false.
.IP "\-not \fIexpr\fR"
-Same as ! \fIexpr\fR.
+Same as ! \fIexpr\fR, but not POSIX compliant.
.IP "\fIexpr1 expr2\fR"
-And (implied); \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
+Two expressions in a row are taken to be joined with an
+implied "and"; \fIexpr2\fR is not evaluated if \fIexpr1\fR is false.
.IP "\fIexpr1\fR \-a \fIexpr2\fR"
Same as \fIexpr1 expr2\fR.
.IP "\fIexpr1\fR \-and \fIexpr2\fR"
-Same as \fIexpr1 expr2\fR.
+Same as \fIexpr1 expr2\fR, but not POSIX compliant.
.IP "\fIexpr1\fR \-o \fIexpr2\fR"
Or; \fIexpr2\fR is not evaluated if \fIexpr1\fR is true.
.IP "\fIexpr1\fR \-or \fIexpr2\fR"
-Same as \fIexpr1\fR \-o \fIexpr2\fR.
+Same as \fIexpr1\fR \-o \fIexpr2\fR, but not POSIX compliant.
.IP "\fIexpr1\fR , \fIexpr2\fR"
List; both \fIexpr1\fR and \fIexpr2\fR are always evaluated.
The value of \fIexpr1\fR is discarded; the value of the list is the
-value of \fIexpr2\fR.
+value of \fIexpr2\fR.
+The comma operator can be useful for searching for several
+different types of thing, but traversing the filesystem hierarchy only
+once. The
+.B \-fprintf
+action can be used to list the various matched items into several
+different output files.
+
+
+.SH "STANDARDS CONFORMANCE"
+The following options are specified in the POSIX standard
+(IEEE Std 1003.1, 2003 Edition):
+.IP "\-H"
+This option is supported.
+.IP "\-L"
+This option is supported.
+.IP "\-name"
+This option is supported, but POSIX conformance depends on the
+POSIX conformance of the system's
+.BR fnmatch (3)
+library function. As of findutils-4.2.2, shell metacharacters
+('*'. '?' or '[]' for example) will match a leading '.', because
+IEEE PASC interpretation 126 requires this. This is a change from
+previous versions of findutils.
+.IP "\-type"
+Supported. POSIX specifies `b', `c', `d', `l', `p', `f' and `s'.
+GNU find also supports `D', representing a Door, where the OS provides these.
+
+.IP "\-ok"
+Supported. Interpretation of the response is not locale-dependent
+(see ENVIRONMENT VARIABLES).
+
+.IP "\-newer"
+Supported. If the file specified is a symbolic link, it is always
+dereferenced. This is a change from previous behaviour, which used to
+take the relevant time from the symbolic link; see the HISTORY section
+below.
+
+.IP "Other predicates"
+The predicates
+`\-atime',
+`\-ctime',
+`\-depth',
+`\-group',
+`\-links',
+`\-mtime',
+`\-nogroup',
+`\-nouser',
+`\-perm',
+`\-print',
+`\-prune',
+`\-size',
+`\-user' and
+`\-xdev',
+are all supported.
+
+.P
+The POSIX standard specifies parentheses `(', `)', negation `!' and the
+`and' and `or' operators (`\-a', `\-o').
+.P
+All other options, predicates, expressions and so forth are extensions
+beyond the POSIX standard. Many of these extensions are not unique to
+GNU find, however.
+.P
+The POSIX standard requires that
+.IP
+The
+.B find
+utility shall detect infinite loops; that is, entering a
+previously visited directory that is an ancestor of the last file
+encountered. When it detects an infinite loop, find shall write a
+diagnostic message to standard error and shall either recover its
+position in the hierarchy or terminate.
+.P
+The link count of directories which contain entries which are hard
+links to an ancestor will often be lower than they otherwise should
+be. This can mean that GNU find will sometimes optimise away the
+visiting of a subdirectory which is actually a link to an ancestor.
+Since
+.B find
+does not actually enter such a subdirectory, it is allowed to avoid
+emitting a diagnostic message. Although this behaviour may be
+somewhat confusing, it is unlikely that anybody actually depends on
+this behaviour. If the leaf optimisation has been turned off with
+.BR \-noleaf ,
+the directory entry will always be examined and the diagnostic message
+will be issued where it is appropriate. Symbolic links cannot be used
+to create filesystem cycles as such, but if the \-L option or the
+\-follow option is in use, a diagnostic message is issued when
+.B find
+encounters a loop of symbolic links. As with loops containing hard
+links, the leaf optimisation will often mean that
+.B find
+knows that it doesn't need to call
+.I stat()
+or
+.I chdir()
+on the symbolic link, so this diagnostic is frequently not necessary.
+.P
+The \-d option is supported for compatibility with various BSD systems,
+but you should use the POSIX-compliant option \-depth instead.
+.P
+The POSIXLY_CORRECT environment variable does not affect the behaviour
+of the \-regex or \-iregex tests because those tests aren't specified in
+the POSIX standard.
+.SH "ENVIRONMENT VARIABLES"
+.IP LANG
+Provides a default value for the internationalization variables that
+are unset or null.
+.IP LC_ALL
+If set to a non-empty string value, override the values of all the
+other internationalization variables.
+.IP LC_COLLATE
+The POSIX standard specifies that this variable affects the pattern
+matching to be used for the `\-name' option. GNU find uses the
+.BR fnmatch (3)
+library function, and so support for `LC_COLLATE' depends on the
+system library.
+.IP
+POSIX also specifies that the `LC_COLLATE' environment
+variable affects the interpretation of the user's response to the
+query issued by `\-ok', but this is not the case for GNU find.
+.IP LC_CTYPE
+This variable affects the treatment of character classes used with
+the `\-name' test, if the system's
+.BR fnmatch (3)
+library function supports this. It has no effect on the behaviour
+of the `\-ok' expression.
+.IP LC_MESSAGES
+Determines the locale to be used for internationalised messages.
+.IP NLSPATH
+Determines the location of the internationalisation message catalogues.
+.IP PATH
+Affects the directories which are searched to find the executables
+invoked by `\-exec', `\-execdir', `\-ok' and `\-okdir'.
+.IP POSIXLY_CORRECT
+Determines the block size used by `\-ls' and `\-fls'.
+If `POSIXLY_CORRECT' is set, blocks are units of 512 bytes. Otherwise
+they are units of 1024 bytes.
+.IP TZ
+Affects the time zone used for some of the time-related format
+directives of \-printf and \-fprintf.
+.SH "EXAMPLES"
+.nf
+.B find /tmp \-name core \-type f \-print | xargs /bin/rm \-f
+
+.fi
+Find files named
+.B core
+in or below the directory
+.B /tmp
+and delete them. Note that this will work incorrectly if there are
+any filenames containing newlines, single or double quotes, or spaces.
+.P
+.B find /tmp \-name core \-type f \-print0 | xargs \-0 /bin/rm \-f
+
+.fi
+Find files named
+.B core
+in or below the directory
+.B /tmp
+and delete them, processing filenames in such a way that file or
+directory names containing single or double quotes, spaces or newlines
+are correctly handled. The
+.B \-name
+test comes before the
+.B \-type
+test in order to avoid having to call
+.B stat(2)
+on every file.
+
+.P
+.nf
+.B find . \-type f \-exec file '{}' \e\;
+
+.fi
+Runs `file' on every file in or below the current directory. Notice
+that the braces are enclosed in single quote marks to protect them
+from interpretation as shell script punctuation. The semicolon is
+similarly protected by the use of a backslash, though ';' could have
+been used in that case also.
+
+.P
+.nf
+.B find / \t\e( \-perm \-4000 \-fprintf /root/suid.txt '%#m %u %p\en' \e) , \e
+.B \t\t\e( \-size +100M \-fprintf /root/big.txt '%\-10s %p\en' \e)
+
+.fi
+Traverse the filesystem just once, listing setuid files and
+directories into
+.B /root/suid.txt
+and large files into
+.BR /root/big.txt .
+
+.P
+.nf
+.B find $HOME \-mtime 0
+
+.fi
+Search for files in your home directory which have been modified in
+the last twenty-four hours. This command works this way because the
+time since each file was last modified is divided by 24 hours and any
+remainder is discarded. That means that to match
+.B \-mtime
+.BR 0 ,
+a file will have to have a modification in the past which is less than
+24 hours ago.
+
+
+.P
+.nf
+.B find . \-perm 664
+
+.fi
+Search for files which have read and write permission for their owner,
+and group, but which other users can read but not write to. Files
+which meet these criteria but have other permissions bits set (for
+example if someone can execute the file) will not be matched.
+
+.P
+.nf
+.B find . \-perm -664
+
+.fi
+Search for files which have read and write permission for their owner
+and group, and which other users can read, without regard to the
+presence of any extra permission bits (for example the executable
+bit). This will match a file which has mode 0777, for example.
+
+.P
+.nf
+.B find . \-perm /222
+
+.fi
+Search for files which are writable by somebody (their owner, or
+their group, or anybody else).
+
+.P
+.nf
+.B find . \-perm /220
+.B find . \-perm /u+w,g+w
+.B find . \-perm /u=w,g=w
+
+.fi
+All three of these commands do the same thing, but the first one uses
+the octal representation of the file mode, and the other two use the
+symbolic form. These commands all search for files which are
+writable by either their owner or their group. The files don't have
+to be writable by both the owner and group to be matched; either will
+do.
+
+.P
+.nf
+.B find . \-perm -220
+.B find . \-perm \-g+w,u+w
+
+.fi
+Both these commands do the same thing; search for files which are
+writable by both their owner and their group.
+
+.P
+.nf
+.B find . \-perm \-444 \-perm /222 ! \-perm /111
+.B find . \-perm \-a+r \-perm /a+w ! \-perm /a+x
+
+.fi
+These two commands both search for files that are readable for
+everybody (\-perm \-444 or \-perm \-a+r), have at least on write bit
+set (\-perm /222 or \-perm /a+w) but are not executable for anybody (!
+\-perm /111 and ! \-perm /a+x respectively)
+
+.SH EXIT STATUS
+.PP
+.B find
+exits with status 0 if all files are processed successfully, greater
+than 0 if errors occur. This is deliberately a very broad
+description, but if the return value is non-zero, you should not rely
+on the correctness of the results of
+.BR find .
+
.SH "SEE ALSO"
-\fBlocate\fP(1L), \fBlocatedb\fP(5L), \fBupdatedb\fP(1L), \fBxargs\fP(1L)
-\fBFinding Files\fP (on-line in Info, or printed)
+\fBlocate\fP(1), \fBlocatedb\fP(5), \fBupdatedb\fP(1), \fBxargs\fP(1),
+\fBchmod\fP(1), \fBfnmatch\fP(3), \fBregex\fP(7), \fBstat\fP(2),
+\fBlstat\fP(2), \fBls\fP(1), \fBprintf\fP(3), \fBstrftime\fP(3),
+\fBctime\fP(3), \fBFinding Files\fP (on-line in Info, or printed).
+.SH "HISTORY"
+As of findutils-4.2.2, shell metacharacters ('*'. '?' or '[]' for
+example) used in filename patterns will match a leading '.', because
+IEEE POSIX interpretation 126 requires this.
+.SH "NON-BUGS"
+.nf
+.B $ find . \-name *.c \-print
+find: paths must precede expression
+Usage: find [-H] [-L] [-P] [path...] [expression]
+.fi
+.P
+This happens because
+.I *.c
+has been expanded by the shell
+resulting in
+.B find
+actually receiving a command line like this:
+.nf
+
+.B find . \-name bigram.c code.c frcode.c locate.c \-print
+
+.fi
+That command is of course not going to work. Instead of doing things
+this way, you should enclose the pattern in quotes:
+.nf
+.B $ find . \-name \'*.c\' \-print
+.fi
+
+.SH "BUGS"
+.P
+The test
+.B \-perm /000
+currently matches no files, but for greater consistency with
+.B \-perm
+.BR \-000 ,
+this will be changed to match all files; this change will probably be
+made in early 2006. Meanwhile, a warning message is given if you do this.
+.P
+There are security problems inherent in the behaviour that the POSIX
+standard specifies for
+.BR find ,
+which therefore cannot be fixed. For example, the \-exec action is
+inherently insecure, and \-execdir should be used instead.
+Please see \fBFinding Files\fP for more information.
+.P
+The best way to report a bug is to use the form at
+http://savannah.gnu.org/bugs/?group=findutils.
+The reason for this is that you will then be able to track progress in
+fixing the problem. Other comments about \fBfind\fP(1) and about
+the findutils package in general can be sent to the
+.I bug\-findutils
+mailing list. To join the list, send email to
+.IR bug\-findutils\-request@gnu.org .
diff --git a/src/bin/findutils/find/find.c b/src/bin/findutils/find/find.c
index 361f2c416c..7fb06a91f5 100644
--- a/src/bin/findutils/find/find.c
+++ b/src/bin/findutils/find/find.c
@@ -1,53 +1,97 @@
/* find -- search for files in a directory hierarchy
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 91, 92, 93, 94, 2000,
+ 2003, 2004, 2005, 2007 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
-
+ along with this program. If not, see .
+*/
/* GNU find was written by Eric Decker ,
- with enhancements by David MacKenzie ,
+ with enhancements by David MacKenzie ,
Jay Plett ,
and Tim Wood .
The idea for -print0 and xargs -0 came from
- Dan Bernstein . */
+ Dan Bernstein .
+ Improvements have been made by James Youngman .
+*/
+
+
+#include "defs.h"
+
+#define USE_SAFE_CHDIR 1
+#undef STAT_MOUNTPOINTS
+
+
+#include
+#include
+
-#include
-#include
-#include
-#include
#ifdef HAVE_FCNTL_H
#include
#else
#include
#endif
-#include "defs.h"
-#include "modetype.h"
-#ifndef S_IFLNK
-#define lstat stat
+#ifdef HAVE_SYS_UTSNAME_H
+#include
#endif
-int lstat ();
-int stat ();
+#include "../gnulib/lib/xalloc.h"
+#include "../gnulib/lib/human.h"
+#include "../gnulib/lib/canonicalize.h"
+#include "closein.h"
+#include
+#include "savedirinfo.h"
+#include "buildcmd.h"
+#include "dirname.h"
+#include "quote.h"
+#include "quotearg.h"
+
+#ifdef HAVE_LOCALE_H
+#include
+#endif
+
+#if ENABLE_NLS
+# include
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#define textdomain(Domain)
+#define bindtextdomain(Package, Directory)
+#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
+#endif
#define apply_predicate(pathname, stat_buf_ptr, node) \
(*(node)->pred_func)((pathname), (stat_buf_ptr), (node))
-static void process_top_path P_((char *pathname));
-static int process_path P_((char *pathname, char *name, boolean leaf, char *parent));
-static void process_dir P_((char *pathname, char *name, int pathlen, struct stat *statp, char *parent));
-static boolean no_side_effects P_((struct predicate *pred));
+#ifdef STAT_MOUNTPOINTS
+static void init_mounted_dev_list(int mandatory);
+#endif
+
+static void process_top_path PARAMS((char *pathname, mode_t mode));
+static int process_path PARAMS((char *pathname, char *name, boolean leaf, char *parent, mode_t type));
+static void process_dir PARAMS((char *pathname, char *name, int pathlen, struct stat *statp, char *parent));
+
+static void complete_pending_execdirs(struct predicate *p);
+static void complete_pending_execs (struct predicate *p);
+
+
+
+static boolean default_prints PARAMS((struct predicate *pred));
/* Name this program was run with. */
char *program_name;
@@ -59,136 +103,462 @@ struct predicate *predicates;
struct predicate *last_pred;
/* The root of the evaluation tree. */
-static struct predicate *eval_tree;
+static struct predicate *eval_tree = NULL;
-/* If true, process directory before contents. True unless -depth given. */
-boolean do_dir_first;
-/* If >=0, don't descend more than this many levels of subdirectories. */
-int maxdepth;
+struct options options;
+struct state state;
-/* If >=0, don't process files above this level. */
-int mindepth;
+/* The full path of the initial working directory, or "." if
+ STARTING_DESC is nonnegative. */
+char const *starting_dir = ".";
-/* Current depth; 0 means current path is a command line arg. */
-int curdepth;
-
-/* Seconds between 00:00 1/1/70 and either one day before now
- (the default), or the start of today (if -daystart is given). */
-time_t cur_day_start;
-
-/* If true, cur_day_start has been adjusted to the start of the day. */
-boolean full_days;
-
-/* If true, do not assume that files in directories with nlink == 2
- are non-directories. */
-boolean no_leaf_check;
-
-/* If true, don't cross filesystem boundaries. */
-boolean stay_on_filesystem;
-
-/* If true, don't descend past current directory.
- Can be set by -prune, -maxdepth, and -xdev/-mount. */
-boolean stop_at_current_level;
-
-#ifndef HAVE_FCHDIR
-/* The full path of the initial working directory. */
-char *starting_dir;
-#else
/* A file descriptor open to the initial working directory.
Doing it this way allows us to work when the i.w.d. has
unreadable parents. */
int starting_desc;
-#endif
-/* If true, we have called stat on the current path. */
-boolean have_stat;
+/* The stat buffer of the initial working directory. */
+struct stat starting_stat_buf;
-/* The file being operated on, relative to the current directory.
- Used for stat, readlink, and opendir. */
-char *rel_pathname;
+enum ChdirSymlinkHandling
+ {
+ SymlinkHandleDefault, /* Normally the right choice */
+ SymlinkFollowOk /* see comment in process_top_path() */
+ };
-/* Length of current path. */
-int path_length;
-/* true if following symlinks. Should be consistent with xstat. */
-boolean dereference;
+enum TraversalDirection
+ {
+ TraversingUp,
+ TraversingDown
+ };
-/* Pointer to the function used to stat files. */
-int (*xstat) ();
+enum WdSanityCheckFatality
+ {
+ FATAL_IF_SANITY_CHECK_FAILS,
+ RETRY_IF_SANITY_CHECK_FAILS,
+ NON_FATAL_IF_SANITY_CHECK_FAILS
+ };
-/* Status value to return to system. */
-int exit_status;
-
-#ifdef DEBUG_STAT
-static int
-debug_stat (file, bufp)
- char *file;
- struct stat *bufp;
+
+int
+following_links(void)
{
+ switch (options.symlink_handling)
+ {
+ case SYMLINK_ALWAYS_DEREF:
+ return 1;
+ case SYMLINK_DEREF_ARGSONLY:
+ return (state.curdepth == 0);
+ case SYMLINK_NEVER_DEREF:
+ default:
+ return 0;
+ }
+}
+
+
+static int
+fallback_stat(const char *name, struct stat *p, int prev_rv)
+{
+ /* Our original stat() call failed. Perhaps we can't follow a
+ * symbolic link. If that might be the problem, lstat() the link.
+ * Otherwise, admit defeat.
+ */
+ switch (errno)
+ {
+ case ENOENT:
+ case ENOTDIR:
+#ifdef DEBUG_STAT
+ fprintf(stderr, "fallback_stat(): stat(%s) failed; falling back on lstat()\n", name);
+#endif
+ return lstat(name, p);
+
+ case EACCES:
+ case EIO:
+ case ELOOP:
+ case ENAMETOOLONG:
+#ifdef EOVERFLOW
+ case EOVERFLOW: /* EOVERFLOW is not #defined on UNICOS. */
+#endif
+ default:
+ return prev_rv;
+ }
+}
+
+
+/* optionh_stat() implements the stat operation when the -H option is
+ * in effect.
+ *
+ * If the item to be examined is a command-line argument, we follow
+ * symbolic links. If the stat() call fails on the command-line item,
+ * we fall back on the properties of the symbolic link.
+ *
+ * If the item to be examined is not a command-line argument, we
+ * examine the link itself.
+ */
+int
+optionh_stat(const char *name, struct stat *p)
+{
+ if (0 == state.curdepth)
+ {
+ /* This file is from the command line; deference the link (if it
+ * is a link).
+ */
+ int rv = stat(name, p);
+ if (0 == rv)
+ return 0; /* success */
+ else
+ return fallback_stat(name, p, rv);
+ }
+ else
+ {
+ /* Not a file on the command line; do not dereference the link.
+ */
+ return lstat(name, p);
+ }
+}
+
+/* optionl_stat() implements the stat operation when the -L option is
+ * in effect. That option makes us examine the thing the symbolic
+ * link points to, not the symbolic link itself.
+ */
+int
+optionl_stat(const char *name, struct stat *p)
+{
+ int rv = stat(name, p);
+ if (0 == rv)
+ return 0; /* normal case. */
+ else
+ return fallback_stat(name, p, rv);
+}
+
+/* optionp_stat() implements the stat operation when the -P option is
+ * in effect (this is also the default). That option makes us examine
+ * the symbolic link itself, not the thing it points to.
+ */
+int
+optionp_stat(const char *name, struct stat *p)
+{
+ return lstat(name, p);
+}
+
+#ifdef DEBUG_STAT
+static uintmax_t stat_count = 0u;
+
+static int
+debug_stat (const char *file, struct stat *bufp)
+{
+ ++stat_count;
fprintf (stderr, "debug_stat (%s)\n", file);
- return lstat (file, bufp);
+ switch (options.symlink_handling)
+ {
+ case SYMLINK_ALWAYS_DEREF:
+ return optionl_stat(file, bufp);
+ case SYMLINK_DEREF_ARGSONLY:
+ return optionh_stat(file, bufp);
+ case SYMLINK_NEVER_DEREF:
+ return optionp_stat(file, bufp);
+ }
}
#endif /* DEBUG_STAT */
-void
-main (argc, argv)
- int argc;
- char *argv[];
+void
+set_follow_state(enum SymlinkOption opt)
+{
+ switch (opt)
+ {
+ case SYMLINK_ALWAYS_DEREF: /* -L */
+ options.xstat = optionl_stat;
+ options.no_leaf_check = true;
+ break;
+
+ case SYMLINK_NEVER_DEREF: /* -P (default) */
+ options.xstat = optionp_stat;
+ /* Can't turn no_leaf_check off because the user might have specified
+ * -noleaf anyway
+ */
+ break;
+
+ case SYMLINK_DEREF_ARGSONLY: /* -H */
+ options.xstat = optionh_stat;
+ options.no_leaf_check = true;
+ }
+
+ options.symlink_handling = opt;
+
+ /* For DEBUG_STAT, the choice is made at runtime within debug_stat()
+ * by checking the contents of the symlink_handling variable.
+ */
+#if defined(DEBUG_STAT)
+ options.xstat = debug_stat;
+#endif /* !DEBUG_STAT */
+}
+
+
+/* Complete any outstanding commands.
+ */
+void
+cleanup(void)
+{
+ if (eval_tree)
+ {
+ complete_pending_execs(eval_tree);
+ complete_pending_execdirs(eval_tree);
+ }
+}
+
+/* Get the stat information for a file, if it is
+ * not already known.
+ */
+int
+get_statinfo (const char *pathname, const char *name, struct stat *p)
+{
+ if (!state.have_stat && (*options.xstat) (name, p) != 0)
+ {
+ if (!options.ignore_readdir_race || (errno != ENOENT) )
+ {
+ error (0, errno, "%s", pathname);
+ state.exit_status = 1;
+ }
+ return -1;
+ }
+ state.have_stat = true;
+ state.have_type = true;
+ state.type = p->st_mode;
+ return 0;
+}
+
+/* Get the stat/type information for a file, if it is
+ * not already known.
+ */
+int
+get_info (const char *pathname,
+ const char *name,
+ struct stat *p,
+ struct predicate *pred_ptr)
+{
+ /* If we need the full stat info, or we need the type info but don't
+ * already have it, stat the file now.
+ */
+ (void) name;
+ if (pred_ptr->need_stat)
+ {
+ return get_statinfo(pathname, state.rel_pathname, p);
+ }
+ if ((pred_ptr->need_type && (0 == state.have_type)))
+ {
+ return get_statinfo(pathname, state.rel_pathname, p);
+ }
+ return 0;
+}
+
+/* Determine if we can use O_NOFOLLOW.
+ */
+#if defined(O_NOFOLLOW)
+static boolean
+check_nofollow(void)
+{
+ struct utsname uts;
+ float release;
+
+ if (0 == uname(&uts))
+ {
+ /* POSIX requires that atof() ignore "unrecognised suffixes". */
+ release = atof(uts.release);
+
+ if (0 == strcmp("Linux", uts.sysname))
+ {
+ /* Linux kernels 2.1.126 and earlier ignore the O_NOFOLLOW flag. */
+ return release >= 2.2; /* close enough */
+ }
+ else if (0 == strcmp("FreeBSD", uts.sysname))
+ {
+ /* FreeBSD 3.0-CURRENT and later support it */
+ return release >= 3.1;
+ }
+ }
+
+ /* Well, O_NOFOLLOW was defined, so we'll try to use it. */
+ return true;
+}
+#endif
+
+int
+main (int argc, char **argv)
{
int i;
- PFB parse_function; /* Pointer to who is to do the parsing. */
+ const struct parser_table *entry_close, *entry_print, *entry_open;
+ const struct parser_table *parse_entry; /* Pointer to the parsing table entry for this expression. */
struct predicate *cur_pred;
char *predicate_name; /* Name of predicate being parsed. */
+ int end_of_leading_options = 0; /* First arg after any -H/-L etc. */
+
program_name = argv[0];
+ /* We call check_nofollow() before setlocale() because the numbers
+ * for which we check (in the results of uname) definitiely have "."
+ * as the decimal point indicator even under locales for which that
+ * is not normally true. Hence atof() would do the wrong thing
+ * if we call it after setlocale().
+ */
+#ifdef O_NOFOLLOW
+ options.open_nofollow_available = check_nofollow();
+#else
+ options.open_nofollow_available = false;
+#endif
+
+ options.regex_options = RE_SYNTAX_EMACS;
+
+#ifdef HAVE_SETLOCALE
+ setlocale (LC_ALL, "");
+#endif
+ bindtextdomain (PACKAGE, LOCALEDIR);
+ textdomain (PACKAGE);
+ atexit (close_stdin);
+
+
+ if (isatty(0))
+ {
+ options.warnings = true;
+ }
+ else
+ {
+ options.warnings = false;
+ }
+
+
predicates = NULL;
last_pred = NULL;
- do_dir_first = true;
- maxdepth = mindepth = -1;
- cur_day_start = time ((time_t *) 0) - DAYSECS;
- full_days = false;
- no_leaf_check = false;
- stay_on_filesystem = false;
- exit_status = 0;
- dereference = false;
-#ifdef DEBUG_STAT
- xstat = debug_stat;
-#else /* !DEBUG_STAT */
- xstat = lstat;
+ options.do_dir_first = true;
+ options.maxdepth = options.mindepth = -1;
+ options.start_time = time (NULL);
+ options.cur_day_start = options.start_time - DAYSECS;
+ options.full_days = false;
+ options.stay_on_filesystem = false;
+ options.ignore_readdir_race = false;
+
+ state.exit_status = 0;
+
+#if defined(DEBUG_STAT)
+ options.xstat = debug_stat;
#endif /* !DEBUG_STAT */
+ if (getenv("POSIXLY_CORRECT"))
+ options.output_block_size = 512;
+ else
+ options.output_block_size = 1024;
+
+ if (getenv("FIND_BLOCK_SIZE"))
+ {
+ error (1, 0, _("The environment variable FIND_BLOCK_SIZE is not supported, the only thing that affects the block size is the POSIXLY_CORRECT environment variable"));
+ }
+
+#if LEAF_OPTIMISATION
+ /* The leaf optimisation is enabled. */
+ options.no_leaf_check = false;
+#else
+ /* The leaf optimisation is disabled. */
+ options.no_leaf_check = true;
+#endif
+
+ set_follow_state(SYMLINK_NEVER_DEREF); /* The default is equivalent to -P. */
+
#ifdef DEBUG
- printf ("cur_day_start = %s", ctime (&cur_day_start));
+ fprintf (stderr, "cur_day_start = %s", ctime (&options.cur_day_start));
#endif /* DEBUG */
- /* Find where in ARGV the predicates begin. */
- for (i = 1; i < argc && strchr ("-!(),", argv[i][0]) == NULL; i++)
- /* Do nothing. */ ;
+ /* Check for -P, -H or -L options. */
+ for (i=1; (end_of_leading_options = i) < argc; ++i)
+ {
+ if (0 == strcmp("-H", argv[i]))
+ {
+ /* Meaning: dereference symbolic links on command line, but nowhere else. */
+ set_follow_state(SYMLINK_DEREF_ARGSONLY);
+ }
+ else if (0 == strcmp("-L", argv[i]))
+ {
+ /* Meaning: dereference all symbolic links. */
+ set_follow_state(SYMLINK_ALWAYS_DEREF);
+ }
+ else if (0 == strcmp("-P", argv[i]))
+ {
+ /* Meaning: never dereference symbolic links (default). */
+ set_follow_state(SYMLINK_NEVER_DEREF);
+ }
+ else if (0 == strcmp("--", argv[i]))
+ {
+ /* -- signifies the end of options. */
+ end_of_leading_options = i+1; /* Next time start with the next option */
+ break;
+ }
+ else
+ {
+ /* Hmm, must be one of
+ * (a) A path name
+ * (b) A predicate
+ */
+ end_of_leading_options = i; /* Next time start with this option */
+ break;
+ }
+ }
+ /* We are now processing the part of the "find" command line
+ * after the -H/-L options (if any).
+ */
+
+ /* fprintf(stderr, "rest: optind=%ld\n", (long)optind); */
+
+ /* Find where in ARGV the predicates begin. */
+ for (i = end_of_leading_options; i < argc && strchr ("-!(),", argv[i][0]) == NULL; i++)
+ {
+ /* fprintf(stderr, "Looks like %s is not a predicate\n", argv[i]); */
+ /* Do nothing. */ ;
+ }
+
/* Enclose the expression in `( ... )' so a default -print will
apply to the whole expression. */
- parse_open (argv, &argc);
+ entry_open = find_parser("(");
+ entry_close = find_parser(")");
+ entry_print = find_parser("print");
+ assert(entry_open != NULL);
+ assert(entry_close != NULL);
+ assert(entry_print != NULL);
+
+ parse_openparen (entry_open, argv, &argc);
+ parse_begin_user_args(argv, argc, last_pred, predicates);
+ pred_sanity_check(last_pred);
+
/* Build the input order list. */
while (i < argc)
{
if (strchr ("-!(),", argv[i][0]) == NULL)
- usage ("paths must precede expression");
+ usage (_("paths must precede expression"));
predicate_name = argv[i];
- parse_function = find_parser (predicate_name);
- if (parse_function == NULL)
- error (1, 0, "invalid predicate `%s'", predicate_name);
+ parse_entry = find_parser (predicate_name);
+ if (parse_entry == NULL)
+ {
+ /* Command line option not recognized */
+ error (1, 0, _("invalid predicate `%s'"), predicate_name);
+ }
+
i++;
- if (!(*parse_function) (argv, &i))
+ if (!(*(parse_entry->parser_func)) (parse_entry, argv, &i))
{
if (argv[i] == NULL)
- error (1, 0, "missing argument to `%s'", predicate_name);
+ /* Command line option requires an argument */
+ error (1, 0, _("missing argument to `%s'"), predicate_name);
else
- error (1, 0, "invalid argument `%s' to `%s'",
+ error (1, 0, _("invalid argument `%s' to `%s'"),
argv[i], predicate_name);
}
+
+ pred_sanity_check(last_pred);
+ pred_sanity_check(predicates); /* XXX: expensive */
}
+ parse_end_user_args(argv, argc, last_pred, predicates);
+
if (predicates->pred_next == NULL)
{
/* No predicates that do something other than set a global variable
@@ -196,34 +566,52 @@ main (argc, argv)
cur_pred = predicates;
predicates = last_pred = predicates->pred_next;
free ((char *) cur_pred);
- parse_print (argv, &argc);
+ parse_print (entry_print, argv, &argc);
+ pred_sanity_check(last_pred);
+ pred_sanity_check(predicates); /* XXX: expensive */
}
- else if (!no_side_effects (predicates->pred_next))
+ else if (!default_prints (predicates->pred_next))
{
/* One or more predicates that produce output were given;
remove the unneeded initial `('. */
cur_pred = predicates;
predicates = predicates->pred_next;
+ pred_sanity_check(predicates); /* XXX: expensive */
free ((char *) cur_pred);
}
else
{
/* `( user-supplied-expression ) -print'. */
- parse_close (argv, &argc);
- parse_print (argv, &argc);
+ parse_closeparen (entry_close, argv, &argc);
+ pred_sanity_check(last_pred);
+ parse_print (entry_print, argv, &argc);
+ pred_sanity_check(last_pred);
+ pred_sanity_check(predicates); /* XXX: expensive */
}
#ifdef DEBUG
- printf ("Predicate List:\n");
- print_list (predicates);
+ fprintf (stderr, "Predicate List:\n");
+ print_list (stderr, predicates);
#endif /* DEBUG */
+ /* do a sanity check */
+ pred_sanity_check(predicates);
+
/* Done parsing the predicates. Build the evaluation tree. */
cur_pred = predicates;
eval_tree = get_expr (&cur_pred, NO_PREC);
+
+ /* Check if we have any left-over predicates (this fixes
+ * Debian bug #185202).
+ */
+ if (cur_pred != NULL)
+ {
+ error (1, 0, _("unexpected extra predicate"));
+ }
+
#ifdef DEBUG
- printf ("Eval Tree:\n");
- print_tree (eval_tree, 0);
+ fprintf (stderr, "Eval Tree:\n");
+ print_tree (stderr, eval_tree, 0);
#endif /* DEBUG */
/* Rearrange the eval tree in optimal-predicate order. */
@@ -231,74 +619,888 @@ main (argc, argv)
/* Determine the point, if any, at which to stat the file. */
mark_stat (eval_tree);
+ /* Determine the point, if any, at which to determine file type. */
+ mark_type (eval_tree);
#ifdef DEBUG
- printf ("Optimized Eval Tree:\n");
- print_tree (eval_tree, 0);
+ fprintf (stderr, "Optimized Eval Tree:\n");
+ print_tree (stderr, eval_tree, 0);
+ fprintf (stderr, "Optimized command line:\n");
+ print_optlist(stderr, eval_tree);
+ fprintf(stderr, "\n");
#endif /* DEBUG */
-#ifndef HAVE_FCHDIR
- starting_dir = xgetcwd ();
- if (starting_dir == NULL)
- error (1, errno, "cannot get current directory");
-#else
- starting_desc = open (".", O_RDONLY);
- if (starting_desc < 0)
- error (1, errno, "cannot open current directory");
-#endif
-
- /* If no paths are given, default to ".". */
- for (i = 1; i < argc && strchr ("-!(),", argv[i][0]) == NULL; i++)
- process_top_path (argv[i]);
- if (i == 1)
- process_top_path (".");
-
- exit (exit_status);
-}
-
-/* Descend PATHNAME, which is a command-line argument. */
-
-static void
-process_top_path (pathname)
- char *pathname;
-{
- struct stat stat_buf;
-
- curdepth = 0;
- path_length = strlen (pathname);
-
- /* We stat each pathname given on the command-line twice --
- once here and once in process_path. It's not too bad, though,
- since the kernel can read the stat information out of its inode
- cache the second time. */
- if ((*xstat) (pathname, &stat_buf) == 0 && S_ISDIR (stat_buf.st_mode))
+ /* safely_chdir() needs to check that it has ended up in the right place.
+ * To avoid bailing out when something gets automounted, it checks if
+ * the target directory appears to have had a directory mounted on it as
+ * we chdir()ed. The problem with this is that in order to notice that
+ * a filesystem was mounted, we would need to lstat() all the mount points.
+ * That strategy loses if our machine is a client of a dead NFS server.
+ *
+ * Hence if safely_chdir() and wd_sanity_check() can manage without needing
+ * to know the mounted device list, we do that.
+ */
+ if (!options.open_nofollow_available)
{
- if (chdir (pathname) < 0)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return;
- }
- process_path (pathname, ".", false, ".");
-#ifndef HAVE_FCHDIR
- if (chdir (starting_dir) < 0)
- error (1, errno, "%s", starting_dir);
-#else
- if (fchdir (starting_desc))
- error (1, errno, "cannot return to starting directory");
+#ifdef STAT_MOUNTPOINTS
+ init_mounted_dev_list(0);
#endif
}
- else
- process_path (pathname, pathname, false, ".");
+
+
+ starting_desc = open (".", O_RDONLY);
+ if (0 <= starting_desc && fchdir (starting_desc) != 0)
+ {
+ close (starting_desc);
+ starting_desc = -1;
+ }
+ if (starting_desc < 0)
+ {
+ starting_dir = xgetcwd ();
+ if (! starting_dir)
+ error (1, errno, _("cannot get current directory"));
+ }
+ if ((*options.xstat) (".", &starting_stat_buf) != 0)
+ error (1, errno, _("cannot get current directory"));
+
+ /* If no paths are given, default to ".". */
+ for (i = end_of_leading_options; i < argc && strchr ("-!(),", argv[i][0]) == NULL; i++)
+ {
+ process_top_path (argv[i], 0);
+ }
+
+ /* If there were no path arguments, default to ".". */
+ if (i == end_of_leading_options)
+ {
+ /*
+ * We use a temporary variable here because some actions modify
+ * the path temporarily. Hence if we use a string constant,
+ * we get a coredump. The best example of this is if we say
+ * "find -printf %H" (note, not "find . -printf %H").
+ */
+ char defaultpath[2] = ".";
+ process_top_path (defaultpath, 0);
+ }
+
+ /* If "-exec ... {} +" has been used, there may be some
+ * partially-full command lines which have been built,
+ * but which are not yet complete. Execute those now.
+ */
+ cleanup();
+ return state.exit_status;
}
+
+static char *
+specific_dirname(const char *dir)
+{
+ char dirbuf[1024];
+
+ if (0 == strcmp(".", dir))
+ {
+ /* OK, what's '.'? */
+ if (NULL != getcwd(dirbuf, sizeof(dirbuf)))
+ {
+ return strdup(dirbuf);
+ }
+ else
+ {
+ return strdup(dir);
+ }
+ }
+ else
+ {
+ char *result = canonicalize_filename_mode(dir, CAN_EXISTING);
+ if (NULL == result)
+ return strdup(dir);
+ else
+ return result;
+ }
+}
+
+
+
+/* Return non-zero if FS is the name of a filesystem that is likely to
+ * be automounted
+ */
+static int
+fs_likely_to_be_automounted(const char *fs)
+{
+ return ( (0==strcmp(fs, "nfs")) || (0==strcmp(fs, "autofs")) || (0==strcmp(fs, "subfs")));
+}
+
+
+
+#ifdef STAT_MOUNTPOINTS
+static dev_t *mounted_devices = NULL;
+static size_t num_mounted_devices = 0u;
+
+
+static void
+init_mounted_dev_list(int mandatory)
+{
+ assert(NULL == mounted_devices);
+ assert(0 == num_mounted_devices);
+ mounted_devices = get_mounted_devices(&num_mounted_devices);
+ if (mandatory && (NULL == mounted_devices))
+ {
+ error(1, 0, "Cannot read list of mounted devices.");
+ }
+}
+
+static void
+refresh_mounted_dev_list(void)
+{
+ if (mounted_devices)
+ {
+ free(mounted_devices);
+ mounted_devices = 0;
+ }
+ num_mounted_devices = 0u;
+ init_mounted_dev_list(1);
+}
+
+
+/* Search for device DEV in the array LIST, which is of size N. */
+static int
+dev_present(dev_t dev, const dev_t *list, size_t n)
+{
+ if (list)
+ {
+ while (n-- > 0u)
+ {
+ if ( (*list++) == dev )
+ return 1;
+ }
+ }
+ return 0;
+}
+
+enum MountPointStateChange
+ {
+ MountPointRecentlyMounted,
+ MountPointRecentlyUnmounted,
+ MountPointStateUnchanged
+ };
+
+
+
+static enum MountPointStateChange
+get_mount_state(dev_t newdev)
+{
+ int new_is_present, new_was_present;
+
+ new_was_present = dev_present(newdev, mounted_devices, num_mounted_devices);
+ refresh_mounted_dev_list();
+ new_is_present = dev_present(newdev, mounted_devices, num_mounted_devices);
+
+ if (new_was_present == new_is_present)
+ return MountPointStateUnchanged;
+ else if (new_is_present)
+ return MountPointRecentlyMounted;
+ else
+ return MountPointRecentlyUnmounted;
+}
+
+
+
+/* We stat()ed a directory, chdir()ed into it (we know this
+ * since direction is TraversingDown), stat()ed it again,
+ * and noticed that the device numbers are different. Check
+ * if the filesystem was recently mounted.
+ *
+ * If it was, it looks like chdir()ing into the directory
+ * caused a filesystem to be mounted. Maybe automount is
+ * running. Anyway, that's probably OK - but it happens
+ * only when we are moving downward.
+ *
+ * We also allow for the possibility that a similar thing
+ * has happened with the unmounting of a filesystem. This
+ * is much rarer, as it relies on an automounter timeout
+ * occurring at exactly the wrong moment.
+ */
+static enum WdSanityCheckFatality
+dirchange_is_fatal(const char *specific_what,
+ enum WdSanityCheckFatality isfatal,
+ int silent,
+ struct stat *newinfo)
+{
+ enum MountPointStateChange transition = get_mount_state(newinfo->st_dev);
+ switch (transition)
+ {
+ case MountPointRecentlyUnmounted:
+ isfatal = NON_FATAL_IF_SANITY_CHECK_FAILS;
+ if (!silent)
+ {
+ error (0, 0,
+ _("Warning: filesystem %s has recently been unmounted."),
+ specific_what);
+ }
+ break;
+
+ case MountPointRecentlyMounted:
+ isfatal = NON_FATAL_IF_SANITY_CHECK_FAILS;
+ if (!silent)
+ {
+ error (0, 0,
+ _("Warning: filesystem %s has recently been mounted."),
+ specific_what);
+ }
+ break;
+
+ case MountPointStateUnchanged:
+ /* leave isfatal as it is */
+ break;
+ }
+
+ return isfatal;
+}
+
+
+#endif
+
+
+
+/* Examine the results of the stat() of a directory from before we
+ * entered or left it, with the results of stat()ing it afterward. If
+ * these are different, the filesystem tree has been modified while we
+ * were traversing it. That might be an attempt to use a race
+ * condition to persuade find to do something it didn't intend
+ * (e.g. an attempt by an ordinary user to exploit the fact that root
+ * sometimes runs find on the whole filesystem). However, this can
+ * also happen if automount is running (certainly on Solaris). With
+ * automount, moving into a directory can cause a filesystem to be
+ * mounted there.
+ *
+ * To cope sensibly with this, we will raise an error if we see the
+ * device number change unless we are chdir()ing into a subdirectory,
+ * and the directory we moved into has been mounted or unmounted "recently".
+ * Here "recently" means since we started "find" or we last re-read
+ * the /etc/mnttab file.
+ *
+ * If the device number does not change but the inode does, that is a
+ * problem.
+ *
+ * If the device number and inode are both the same, we are happy.
+ *
+ * If a filesystem is (un)mounted as we chdir() into the directory, that
+ * may mean that we're now examining a section of the filesystem that might
+ * have been excluded from consideration (via -prune or -quit for example).
+ * Hence we print a warning message to indicate that the output of find
+ * might be inconsistent due to the change in the filesystem.
+ */
+static boolean
+wd_sanity_check(const char *thing_to_stat,
+ const char *progname,
+ const char *what,
+ dev_t old_dev,
+ ino_t old_ino,
+ struct stat *newinfo,
+ int parent,
+ int line_no,
+ enum TraversalDirection direction,
+ enum WdSanityCheckFatality isfatal,
+ boolean *changed) /* output parameter */
+{
+ const char *fstype;
+ char *specific_what = NULL;
+ int silent = 0;
+ const char *current_dir = ".";
+
+ *changed = false;
+
+ if ((*options.xstat) (current_dir, newinfo) != 0)
+ error (1, errno, "%s", thing_to_stat);
+
+ if (old_dev != newinfo->st_dev)
+ {
+ *changed = true;
+ specific_what = specific_dirname(what);
+ fstype = filesystem_type(newinfo, current_dir);
+ silent = fs_likely_to_be_automounted(fstype);
+
+ /* This condition is rare, so once we are here it is
+ * reasonable to perform an expensive computation to
+ * determine if we should continue or fail.
+ */
+ if (TraversingDown == direction)
+ {
+#ifdef STAT_MOUNTPOINTS
+ isfatal = dirchange_is_fatal(specific_what,isfatal,silent,newinfo);
+#else
+ isfatal = RETRY_IF_SANITY_CHECK_FAILS;
+#endif
+ }
+
+ switch (isfatal)
+ {
+ case FATAL_IF_SANITY_CHECK_FAILS:
+ {
+ fstype = filesystem_type(newinfo, current_dir);
+ error (1, 0,
+ _("%s%s changed during execution of %s (old device number %ld, new device number %ld, filesystem type is %s) [ref %ld]"),
+ specific_what,
+ parent ? "/.." : "",
+ progname,
+ (long) old_dev,
+ (long) newinfo->st_dev,
+ fstype,
+ line_no);
+ /*NOTREACHED*/
+ return false;
+ }
+
+ case NON_FATAL_IF_SANITY_CHECK_FAILS:
+ {
+ /* Since the device has changed under us, the inode number
+ * will almost certainly also be different. However, we have
+ * already decided that this is not a problem. Hence we return
+ * without checking the inode number.
+ */
+ free(specific_what);
+ return true;
+ }
+
+ case RETRY_IF_SANITY_CHECK_FAILS:
+ return false;
+ }
+ }
+
+ /* Device number was the same, check if the inode has changed. */
+ if (old_ino != newinfo->st_ino)
+ {
+ *changed = true;
+ specific_what = specific_dirname(what);
+ fstype = filesystem_type(newinfo, current_dir);
+
+ error ((isfatal == FATAL_IF_SANITY_CHECK_FAILS) ? 1 : 0,
+ 0, /* no relevant errno value */
+ _("%s%s changed during execution of %s (old inode number %ld, new inode number %ld, filesystem type is %s) [ref %ld]"),
+ specific_what,
+ parent ? "/.." : "",
+ progname,
+ (long) old_ino,
+ (long) newinfo->st_ino,
+ fstype,
+ line_no);
+ free(specific_what);
+ return false;
+ }
+
+ return true;
+}
+
+enum SafeChdirStatus
+ {
+ SafeChdirOK,
+ SafeChdirFailSymlink,
+ SafeChdirFailNotDir,
+ SafeChdirFailStat,
+ SafeChdirFailWouldBeUnableToReturn,
+ SafeChdirFailChdirFailed,
+ SafeChdirFailNonexistent,
+ SafeChdirFailDestUnreadable
+ };
+
+/* Safely perform a change in directory. We do this by calling
+ * lstat() on the subdirectory, using chdir() to move into it, and
+ * then lstat()ing ".". We compare the results of the two stat calls
+ * to see if they are consistent. If not, we sound the alarm.
+ *
+ * If following_links() is true, we do follow symbolic links.
+ */
+static enum SafeChdirStatus
+safely_chdir_lstat(const char *dest,
+ enum TraversalDirection direction,
+ struct stat *statbuf_dest,
+ enum ChdirSymlinkHandling symlink_follow_option,
+ boolean *did_stat)
+{
+ struct stat statbuf_arrived;
+ int rv, dotfd=-1;
+ int saved_errno; /* specific_dirname() changes errno. */
+ boolean rv_set = false;
+ boolean statflag = false;
+ int tries = 0;
+ enum WdSanityCheckFatality isfatal = RETRY_IF_SANITY_CHECK_FAILS;
+
+ saved_errno = errno = 0;
+
+ dotfd = open(".", O_RDONLY);
+
+ /* We jump back to here if wd_sanity_check()
+ * recoverably triggers an alert.
+ */
+ retry:
+ ++tries;
+
+ if (dotfd >= 0)
+ {
+ /* Stat the directory we're going to. */
+ if (0 == options.xstat(dest, statbuf_dest))
+ {
+ statflag = true;
+
+#ifdef S_ISLNK
+ /* symlink_follow_option might be set to SymlinkFollowOk, which
+ * would allow us to chdir() into a symbolic link. This is
+ * only useful for the case where the directory we're
+ * chdir()ing into is the basename of a command line
+ * argument, for example where "foo/bar/baz" is specified on
+ * the command line. When -P is in effect (the default),
+ * baz will not be followed if it is a symlink, but if bar
+ * is a symlink, it _should_ be followed. Hence we need the
+ * ability to override the policy set by following_links().
+ */
+ if (!following_links() && S_ISLNK(statbuf_dest->st_mode))
+ {
+ /* We're not supposed to be following links, but this is
+ * a link. Check symlink_follow_option to see if we should
+ * make a special exception.
+ */
+ if (symlink_follow_option == SymlinkFollowOk)
+ {
+ /* We need to re-stat() the file so that the
+ * sanity check can pass.
+ */
+ if (0 != stat(dest, statbuf_dest))
+ {
+ rv = SafeChdirFailNonexistent;
+ rv_set = true;
+ saved_errno = errno;
+ goto fail;
+ }
+ statflag = true;
+ }
+ else
+ {
+ /* Not following symlinks, so the attempt to
+ * chdir() into a symlink should be prevented.
+ */
+ rv = SafeChdirFailSymlink;
+ rv_set = true;
+ saved_errno = 0; /* silence the error message */
+ goto fail;
+ }
+ }
+#endif
+#ifdef S_ISDIR
+ /* Although the immediately following chdir() would detect
+ * the fact that this is not a directory for us, this would
+ * result in an extra system call that fails. Anybody
+ * examining the system-call trace should ideally not be
+ * concerned that something is actually failing.
+ */
+ if (!S_ISDIR(statbuf_dest->st_mode))
+ {
+ rv = SafeChdirFailNotDir;
+ rv_set = true;
+ saved_errno = 0; /* silence the error message */
+ goto fail;
+ }
+#endif
+#ifdef DEBUG_STAT
+ fprintf(stderr, "safely_chdir(): chdir(\"%s\")\n", dest);
+#endif
+ if (0 == chdir(dest))
+ {
+ /* check we ended up where we wanted to go */
+ boolean changed = false;
+ if (!wd_sanity_check(".", program_name, ".",
+ statbuf_dest->st_dev,
+ statbuf_dest->st_ino,
+ &statbuf_arrived,
+ 0, __LINE__, direction,
+ isfatal,
+ &changed))
+ {
+ /* Only allow one failure. */
+ if (RETRY_IF_SANITY_CHECK_FAILS == isfatal)
+ {
+ if (0 == fchdir(dotfd))
+ {
+ isfatal = FATAL_IF_SANITY_CHECK_FAILS;
+ goto retry;
+ }
+ else
+ {
+ /* Failed to return to original directory,
+ * but we know that the current working
+ * directory is not the one that we intend
+ * to be in. Since fchdir() failed, we
+ * can't recover from this and so this error
+ * is fatal.
+ */
+ error(1, errno,
+ "failed to return to parent directory");
+ }
+ }
+ else
+ {
+ /* XXX: not sure what to use as an excuse here. */
+ rv = SafeChdirFailNonexistent;
+ rv_set = true;
+ saved_errno = 0;
+ goto fail;
+ }
+ }
+
+ close(dotfd);
+ return SafeChdirOK;
+ }
+ else
+ {
+ saved_errno = errno;
+ if (ENOENT == saved_errno)
+ {
+ rv = SafeChdirFailNonexistent;
+ rv_set = true;
+ if (options.ignore_readdir_race)
+ errno = 0; /* don't issue err msg */
+ }
+ else if (ENOTDIR == saved_errno)
+ {
+ /* This can happen if the we stat a directory,
+ * and then filesystem activity changes it into
+ * a non-directory.
+ */
+ saved_errno = 0; /* don't issue err msg */
+ rv = SafeChdirFailNotDir;
+ rv_set = true;
+ }
+ else
+ {
+ rv = SafeChdirFailChdirFailed;
+ rv_set = true;
+ }
+ goto fail;
+ }
+ }
+ else
+ {
+ saved_errno = errno;
+ rv = SafeChdirFailStat;
+ rv_set = true;
+
+ if ( (ENOENT == saved_errno) || (0 == state.curdepth))
+ saved_errno = 0; /* don't issue err msg */
+ goto fail;
+ }
+ }
+ else
+ {
+ /* We do not have read permissions on "." */
+ rv = SafeChdirFailWouldBeUnableToReturn;
+ rv_set = true;
+ goto fail;
+ }
+
+ /* This is the success path, so we clear errno. The caller probably
+ * won't be calling error() anyway.
+ */
+ saved_errno = 0;
+
+ /* We use the same exit path for success or failure.
+ * which has occurred is recorded in RV.
+ */
+ fail:
+ /* We do not call error() as this would result in a duplicate error
+ * message when the caller does the same thing.
+ */
+ if (saved_errno)
+ errno = saved_errno;
+
+ if (dotfd >= 0)
+ {
+ close(dotfd);
+ dotfd = -1;
+ }
+
+ *did_stat = statflag;
+ assert(rv_set);
+ return rv;
+}
+
+#if defined(O_NOFOLLOW)
+/* Safely change working directory to the specified subdirectory. If
+ * we are not allowed to follow symbolic links, we use open() with
+ * O_NOFOLLOW, followed by fchdir(). This ensures that we don't
+ * follow symbolic links (of course, we do follow them if the -L
+ * option is in effect).
+ */
+static enum SafeChdirStatus
+safely_chdir_nofollow(const char *dest,
+ enum TraversalDirection direction,
+ struct stat *statbuf_dest,
+ enum ChdirSymlinkHandling symlink_follow_option,
+ boolean *did_stat)
+{
+ int extraflags, fd;
+ extraflags = 0;
+
+ *did_stat = false;
+
+ switch (symlink_follow_option)
+ {
+ case SymlinkFollowOk:
+ extraflags = 0;
+ break;
+
+ case SymlinkHandleDefault:
+ if (following_links())
+ extraflags = 0;
+ else
+ extraflags = O_NOFOLLOW;
+ break;
+ }
+
+ errno = 0;
+ fd = open(dest, O_RDONLY|extraflags);
+ if (fd < 0)
+ {
+ switch (errno)
+ {
+ case ELOOP:
+ return SafeChdirFailSymlink; /* This is why we use O_NOFOLLOW */
+ case ENOENT:
+ return SafeChdirFailNonexistent;
+ default:
+ return SafeChdirFailDestUnreadable;
+ }
+ }
+
+ errno = 0;
+ if (0 == fchdir(fd))
+ {
+ close(fd);
+ return SafeChdirOK;
+ }
+ else
+ {
+ int saved_errno = errno;
+ close(fd);
+ errno = saved_errno;
+
+ switch (errno)
+ {
+ case ENOTDIR:
+ return SafeChdirFailNotDir;
+
+ case EACCES:
+ case EBADF: /* Shouldn't happen */
+ case EINTR:
+ case EIO:
+ default:
+ return SafeChdirFailChdirFailed;
+ }
+ }
+}
+#endif
+
+static enum SafeChdirStatus
+safely_chdir(const char *dest,
+ enum TraversalDirection direction,
+ struct stat *statbuf_dest,
+ enum ChdirSymlinkHandling symlink_follow_option,
+ boolean *did_stat)
+{
+ /* We're about to leave a directory. If there are any -execdir
+ * argument lists which have been built but have not yet been
+ * processed, do them now because they must be done in the same
+ * directory.
+ */
+ complete_pending_execdirs(eval_tree);
+
+#if defined(O_NOFOLLOW)
+ if (options.open_nofollow_available)
+ {
+ enum SafeChdirStatus result;
+ result = safely_chdir_nofollow(dest, direction, statbuf_dest,
+ symlink_follow_option, did_stat);
+ if (SafeChdirFailDestUnreadable != result)
+ {
+ return result;
+ }
+ else
+ {
+ /* Savannah bug #15384: fall through to use safely_chdir_lstat
+ * if the directory is not readable.
+ */
+ /* Do nothing. */
+ }
+ }
+#endif
+ /* Even if O_NOFOLLOW is available, we may need to use the alternative
+ * method, since parent of the start point may be executable but not
+ * readable.
+ */
+ return safely_chdir_lstat(dest, direction, statbuf_dest,
+ symlink_follow_option, did_stat);
+}
+
+
+
+/* Safely go back to the starting directory. */
+static void
+chdir_back (void)
+{
+ struct stat stat_buf;
+ boolean dummy;
+
+ if (starting_desc < 0)
+ {
+#ifdef DEBUG_STAT
+ fprintf(stderr, "chdir_back(): chdir(\"%s\")\n", starting_dir);
+#endif
+
+#ifdef STAT_MOUNTPOINTS
+ /* We will need the mounted device list. Get it now if we don't
+ * already have it.
+ */
+ if (NULL == mounted_devices)
+ init_mounted_dev_list(1);
+#endif
+
+ if (chdir (starting_dir) != 0)
+ error (1, errno, "%s", starting_dir);
+
+ wd_sanity_check(starting_dir,
+ program_name,
+ starting_dir,
+ starting_stat_buf.st_dev,
+ starting_stat_buf.st_ino,
+ &stat_buf, 0, __LINE__,
+ TraversingUp,
+ FATAL_IF_SANITY_CHECK_FAILS,
+ &dummy);
+ }
+ else
+ {
+#ifdef DEBUG_STAT
+ fprintf(stderr, "chdir_back(): chdir()\n");
+#endif
+ if (fchdir (starting_desc) != 0)
+ error (1, errno, "%s", starting_dir);
+ }
+}
+
+/* Move to the parent of a given directory and then call a function,
+ * restoring the cwd. Don't bother changing directory if the
+ * specified directory is a child of "." or is the root directory.
+ */
+static void
+at_top (char *pathname,
+ mode_t mode,
+ struct stat *pstat,
+ void (*action)(char *pathname,
+ char *basename,
+ int mode,
+ struct stat *pstat))
+{
+ int dirchange;
+ char *parent_dir = dir_name (pathname);
+ char *base = last_component (pathname);
+
+ state.curdepth = 0;
+ state.path_length = strlen (pathname);
+
+ if (0 == *base
+ || 0 == strcmp(parent_dir, "."))
+ {
+ dirchange = 0;
+ base = pathname;
+ }
+ else
+ {
+ enum TraversalDirection direction;
+ enum SafeChdirStatus chdir_status;
+ struct stat st;
+ boolean did_stat = false;
+
+ dirchange = 1;
+ if (0 == strcmp(base, ".."))
+ direction = TraversingUp;
+ else
+ direction = TraversingDown;
+
+ /* We pass SymlinkFollowOk to safely_chdir(), which allows it to
+ * chdir() into a symbolic link. This is only useful for the
+ * case where the directory we're chdir()ing into is the
+ * basename of a command line argument, for example where
+ * "foo/bar/baz" is specified on the command line. When -P is
+ * in effect (the default), baz will not be followed if it is a
+ * symlink, but if bar is a symlink, it _should_ be followed.
+ * Hence we need the ability to override the policy set by
+ * following_links().
+ */
+ chdir_status = safely_chdir(parent_dir, direction, &st, SymlinkFollowOk, &did_stat);
+ if (SafeChdirOK != chdir_status)
+ {
+ const char *what = (SafeChdirFailWouldBeUnableToReturn == chdir_status) ? "." : parent_dir;
+ if (errno)
+ error (0, errno, "%s", what);
+ else
+ error (0, 0, "Failed to safely change directory into `%s'",
+ parent_dir);
+
+ /* We can't process this command-line argument. */
+ state.exit_status = 1;
+ return;
+ }
+ }
+
+ free (parent_dir);
+ parent_dir = NULL;
+
+ action(pathname, base, mode, pstat);
+
+ if (dirchange)
+ {
+ chdir_back();
+ }
+}
+
+
+static void do_process_top_dir(char *pathname,
+ char *base,
+ int mode,
+ struct stat *pstat)
+{
+ process_path (pathname, base, false, ".", mode);
+ complete_pending_execdirs(eval_tree);
+}
+
+static void do_process_predicate(char *pathname,
+ char *base,
+ int mode,
+ struct stat *pstat)
+{
+ state.rel_pathname = base;
+ apply_predicate (pathname, pstat, eval_tree);
+}
+
+
+
+
+/* Descend PATHNAME, which is a command-line argument.
+
+ Actions like -execdir assume that we are in the
+ parent directory of the file we're examining,
+ and on entry to this function our working directory
+ is whatever it was when find was invoked. Therefore
+ If PATHNAME is "." we just leave things as they are.
+ Otherwise, we figure out what the parent directory is,
+ and move to that.
+*/
+static void
+process_top_path (char *pathname, mode_t mode)
+{
+ at_top(pathname, mode, NULL, do_process_top_dir);
+}
+
+
/* Info on each directory in the current tree branch, to avoid
getting stuck in symbolic link loops. */
-struct dir_id
-{
- ino_t ino;
- dev_t dev;
-};
static struct dir_id *dir_ids = NULL;
/* Entries allocated in `dir_ids'. */
static int dir_alloc = 0;
@@ -308,6 +1510,114 @@ static int dir_curr = -1;
/* (Arbitrary) number of entries to grow `dir_ids' by. */
#define DIR_ALLOC_STEP 32
+
+
+/* We've detected a filesystem loop. This is caused by one of
+ * two things:
+ *
+ * 1. Option -L is in effect and we've hit a symbolic link that
+ * points to an ancestor. This is harmless. We won't traverse the
+ * symbolic link.
+ *
+ * 2. We have hit a real cycle in the directory hierarchy. In this
+ * case, we issue a diagnostic message (POSIX requires this) and we
+ * skip that directory entry.
+ */
+static void
+issue_loop_warning(const char *name, const char *pathname, int level)
+{
+ struct stat stbuf_link;
+ if (lstat(name, &stbuf_link) != 0)
+ stbuf_link.st_mode = S_IFREG;
+
+ if (S_ISLNK(stbuf_link.st_mode))
+ {
+ error(0, 0,
+ _("Symbolic link `%s' is part of a loop in the directory hierarchy; we have already visited the directory to which it points."),
+ pathname);
+ }
+ else
+ {
+ int distance = 1 + (dir_curr-level);
+ /* We have found an infinite loop. POSIX requires us to
+ * issue a diagnostic. Usually we won't get to here
+ * because when the leaf optimisation is on, it will cause
+ * the subdirectory to be skipped. If /a/b/c/d is a hard
+ * link to /a/b, then the link count of /a/b/c is 2,
+ * because the ".." entry of /b/b/c/d points to /a, not
+ * to /a/b/c.
+ */
+ error(0, 0,
+ _("Filesystem loop detected; `%s' has the same device number and inode as a directory which is %d %s."),
+ pathname,
+ distance,
+ (distance == 1 ?
+ _("level higher in the filesystem hierarchy") :
+ _("levels higher in the filesystem hierarchy")));
+ }
+}
+
+/* Take a "mode" indicator and fill in the files of 'state'.
+ */
+static int
+digest_mode(mode_t mode,
+ const char *pathname,
+ const char *name,
+ struct stat *pstat,
+ boolean leaf)
+{
+ /* If we know the type of the directory entry, and it is not a
+ * symbolic link, we may be able to avoid a stat() or lstat() call.
+ */
+ if (mode)
+ {
+ if (S_ISLNK(mode) && following_links())
+ {
+ /* mode is wrong because we should have followed the symlink. */
+ if (get_statinfo(pathname, name, pstat) != 0)
+ return 0;
+ mode = state.type = pstat->st_mode;
+ state.have_type = true;
+ }
+ else
+ {
+ state.have_type = true;
+ pstat->st_mode = state.type = mode;
+ }
+ }
+ else
+ {
+ /* Mode is not yet known; may have to stat the file unless we
+ * can deduce that it is not a directory (which is all we need to
+ * know at this stage)
+ */
+ if (leaf)
+ {
+ state.have_stat = false;
+ state.have_type = false;;
+ state.type = 0;
+ }
+ else
+ {
+ if (get_statinfo(pathname, name, pstat) != 0)
+ return 0;
+
+ /* If -L is in effect and we are dealing with a symlink,
+ * st_mode is the mode of the pointed-to file, while mode is
+ * the mode of the directory entry (S_IFLNK). Hence now
+ * that we have the stat information, override "mode".
+ */
+ state.type = pstat->st_mode;
+ state.have_type = true;
+ }
+ }
+
+ /* success. */
+ return 1;
+}
+
+
+
/* Recursively descend path PATHNAME, applying the predicates.
LEAF is true if PATHNAME is known to be in a directory that has no
more unexamined subdirectories, and therefore it is not a directory.
@@ -323,11 +1633,8 @@ static int dir_curr = -1;
Return nonzero iff PATHNAME is a directory. */
static int
-process_path (pathname, name, leaf, parent)
- char *pathname;
- char *name;
- boolean leaf;
- char *parent;
+process_path (char *pathname, char *name, boolean leaf, char *parent,
+ mode_t mode)
{
struct stat stat_buf;
static dev_t root_dev; /* Device ID of current argument pathname. */
@@ -335,40 +1642,46 @@ process_path (pathname, name, leaf, parent)
/* Assume it is a non-directory initially. */
stat_buf.st_mode = 0;
+ state.rel_pathname = name;
+ state.type = 0;
+ state.have_stat = false;
+ state.have_type = false;
- rel_pathname = name;
-
- if (leaf)
- have_stat = false;
- else
+ if (!digest_mode(mode, pathname, name, &stat_buf, leaf))
+ return 0;
+
+ if (!S_ISDIR (state.type))
{
- if ((*xstat) (name, &stat_buf) != 0)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return 0;
- }
- have_stat = true;
- }
-
- if (!S_ISDIR (stat_buf.st_mode))
- {
- if (curdepth >= mindepth)
+ if (state.curdepth >= options.mindepth)
apply_predicate (pathname, &stat_buf, eval_tree);
return 0;
}
/* From here on, we're working on a directory. */
- stop_at_current_level = maxdepth >= 0 && curdepth >= maxdepth;
+
+ /* Now we really need to stat the directory, even if we know the
+ * type, because we need information like struct stat.st_rdev.
+ */
+ if (get_statinfo(pathname, name, &stat_buf) != 0)
+ return 0;
+
+ state.have_stat = true;
+ mode = state.type = stat_buf.st_mode; /* use full info now that we have it. */
+ state.stop_at_current_level =
+ options.maxdepth >= 0
+ && state.curdepth >= options.maxdepth;
/* If we've already seen this directory on this branch,
don't descend it again. */
for (i = 0; i <= dir_curr; i++)
if (stat_buf.st_ino == dir_ids[i].ino &&
stat_buf.st_dev == dir_ids[i].dev)
- stop_at_current_level = true;
-
+ {
+ state.stop_at_current_level = true;
+ issue_loop_warning(name, pathname, i);
+ }
+
if (dir_alloc <= ++dir_curr)
{
dir_alloc += DIR_ALLOC_STEP;
@@ -378,28 +1691,126 @@ process_path (pathname, name, leaf, parent)
dir_ids[dir_curr].ino = stat_buf.st_ino;
dir_ids[dir_curr].dev = stat_buf.st_dev;
- if (stay_on_filesystem)
+ if (options.stay_on_filesystem)
{
- if (curdepth == 0)
+ if (state.curdepth == 0)
root_dev = stat_buf.st_dev;
else if (stat_buf.st_dev != root_dev)
- stop_at_current_level = true;
+ state.stop_at_current_level = true;
}
- if (do_dir_first && curdepth >= mindepth)
+ if (options.do_dir_first && state.curdepth >= options.mindepth)
apply_predicate (pathname, &stat_buf, eval_tree);
- if (stop_at_current_level == false)
+#ifdef DEBUG
+ fprintf(stderr, "pathname = %s, stop_at_current_level = %d\n",
+ pathname, state.stop_at_current_level);
+#endif /* DEBUG */
+
+ if (state.stop_at_current_level == false)
/* Scan directory on disk. */
process_dir (pathname, name, strlen (pathname), &stat_buf, parent);
- if (do_dir_first == false && curdepth >= mindepth)
- apply_predicate (pathname, &stat_buf, eval_tree);
+ if (options.do_dir_first == false && state.curdepth >= options.mindepth)
+ {
+ /* The fields in 'state' are now out of date. Correct them.
+ */
+ if (!digest_mode(mode, pathname, name, &stat_buf, leaf))
+ return 0;
+
+ if (0 == dir_curr)
+ {
+ at_top(pathname, mode, &stat_buf, do_process_predicate);
+ }
+ else
+ {
+ do_process_predicate(pathname, name, mode, &stat_buf);
+ }
+ }
dir_curr--;
return 1;
}
+
+/* Examine the predicate list for instances of -execdir or -okdir
+ * which have been terminated with '+' (build argument list) rather
+ * than ';' (singles only). If there are any, run them (this will
+ * have no effect if there are no arguments waiting).
+ */
+static void
+complete_pending_execdirs(struct predicate *p)
+{
+#if defined(NEW_EXEC)
+ if (NULL == p)
+ return;
+
+ complete_pending_execdirs(p->pred_left);
+
+ if (p->pred_func == pred_execdir || p->pred_func == pred_okdir)
+ {
+ /* It's an exec-family predicate. p->args.exec_val is valid. */
+ if (p->args.exec_vec.multiple)
+ {
+ struct exec_val *execp = &p->args.exec_vec;
+
+ /* This one was terminated by '+' and so might have some
+ * left... Run it if necessary.
+ */
+ if (execp->state.todo)
+ {
+ /* There are not-yet-executed arguments. */
+ launch (&execp->ctl, &execp->state);
+ }
+ }
+ }
+
+ complete_pending_execdirs(p->pred_right);
+#else
+ /* nothing to do. */
+ return;
+#endif
+}
+
+/* Examine the predicate list for instances of -exec which have been
+ * terminated with '+' (build argument list) rather than ';' (singles
+ * only). If there are any, run them (this will have no effect if
+ * there are no arguments waiting).
+ */
+static void
+complete_pending_execs(struct predicate *p)
+{
+#if defined(NEW_EXEC)
+ if (NULL == p)
+ return;
+
+ complete_pending_execs(p->pred_left);
+
+ /* It's an exec-family predicate then p->args.exec_val is valid
+ * and we can check it.
+ */
+ if (p->pred_func == pred_exec && p->args.exec_vec.multiple)
+ {
+ struct exec_val *execp = &p->args.exec_vec;
+
+ /* This one was terminated by '+' and so might have some
+ * left... Run it if necessary. Set state.exit_status if
+ * there are any problems.
+ */
+ if (execp->state.todo)
+ {
+ /* There are not-yet-executed arguments. */
+ launch (&execp->ctl, &execp->state);
+ }
+ }
+
+ complete_pending_execs(p->pred_right);
+#else
+ /* nothing to do. */
+ return;
+#endif
+}
+
/* Scan directory PATHNAME and recurse through process_path for each entry.
@@ -407,36 +1818,40 @@ process_path (pathname, name, leaf, parent)
NAME is PATHNAME relative to the current directory.
- STATP is the results of *xstat on it.
+ STATP is the results of *options.xstat on it.
PARENT is the path of the parent of NAME, relative to find's
starting directory. */
static void
-process_dir (pathname, name, pathlen, statp, parent)
- char *pathname;
- char *name;
- int pathlen;
- struct stat *statp;
- char *parent;
+process_dir (char *pathname, char *name, int pathlen, struct stat *statp, char *parent)
{
- char *name_space; /* Names of files in PATHNAME. */
int subdirs_left; /* Number of unexamined subdirs in PATHNAME. */
+ boolean subdirs_unreliable; /* if true, cannot use dir link count as subdir limif (if false, it may STILL be unreliable) */
+ int idx; /* Which entry are we on? */
+ struct stat stat_buf;
- subdirs_left = statp->st_nlink - 2; /* Account for name and ".". */
+ struct savedir_dirinfo *dirinfo;
- errno = 0;
- /* On some systems (VAX 4.3BSD+NFS), NFS mount points have st_size < 0. */
- name_space = savedir (name, statp->st_size > 0 ? statp->st_size : 512);
- if (name_space == NULL)
+ if (statp->st_nlink < 2)
{
- if (errno)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- }
- else
- error (1, 0, "virtual memory exhausted");
+ subdirs_unreliable = true;
+ }
+ else
+ {
+ subdirs_unreliable = false; /* not necessarily right */
+ subdirs_left = statp->st_nlink - 2; /* Account for name and ".". */
+ }
+
+ errno = 0;
+ dirinfo = xsavedir(name, 0);
+
+
+ if (dirinfo == NULL)
+ {
+ assert(errno != 0);
+ error (0, errno, "%s", pathname);
+ state.exit_status = 1;
}
else
{
@@ -446,7 +1861,8 @@ process_dir (pathname, name, pathlen, statp, parent)
unsigned cur_path_size; /* Bytes allocated for `cur_path'. */
register unsigned file_len; /* Length of each path to process. */
register unsigned pathname_len; /* PATHLEN plus trailing '/'. */
-
+ boolean did_stat = false;
+
if (pathname[pathlen - 1] == '/')
pathname_len = pathlen + 1; /* For '\0'; already have '/'. */
else
@@ -454,15 +1870,75 @@ process_dir (pathname, name, pathlen, statp, parent)
cur_path_size = 0;
cur_path = NULL;
- if (strcmp (name, ".") && chdir (name) < 0)
+ /* We're about to leave the directory. If there are any
+ * -execdir argument lists which have been built but have not
+ * yet been processed, do them now because they must be done in
+ * the same directory.
+ */
+ complete_pending_execdirs(eval_tree);
+
+ if (strcmp (name, "."))
{
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return;
+ enum SafeChdirStatus status = safely_chdir (name, TraversingDown, &stat_buf, SymlinkHandleDefault, &did_stat);
+ switch (status)
+ {
+ case SafeChdirOK:
+ /* If there had been a change but wd_sanity_check()
+ * accepted it, we need to accept that on the
+ * way back up as well, so modify our record
+ * of what we think we should see later.
+ * If there was no change, the assignments are a no-op.
+ *
+ * However, before performing the assignment, we need to
+ * check that we have the stat information. If O_NOFOLLOW
+ * is available, safely_chdir() will not have needed to use
+ * stat(), and so stat_buf will just contain random data.
+ */
+ if (!did_stat)
+ {
+ /* If there is a link we need to follow it. Hence
+ * the direct call to stat() not through (options.xstat)
+ */
+ if (0 != stat(".", &stat_buf))
+ break; /* skip the assignment. */
+ }
+ dir_ids[dir_curr].dev = stat_buf.st_dev;
+ dir_ids[dir_curr].ino = stat_buf.st_ino;
+
+ break;
+
+ case SafeChdirFailWouldBeUnableToReturn:
+ error (0, errno, ".");
+ state.exit_status = 1;
+ break;
+
+ case SafeChdirFailNonexistent:
+ case SafeChdirFailDestUnreadable:
+ case SafeChdirFailStat:
+ case SafeChdirFailNotDir:
+ case SafeChdirFailChdirFailed:
+ error (0, errno, "%s", pathname);
+ state.exit_status = 1;
+ return;
+
+ case SafeChdirFailSymlink:
+ error (0, 0,
+ _("warning: not following the symbolic link %s"),
+ pathname);
+ state.exit_status = 1;
+ return;
+ }
}
- for (namep = name_space; *namep; namep += file_len - pathname_len + 1)
+ for (idx=0; idx < dirinfo->size; ++idx)
{
+ /* savedirinfo() may return dirinfo=NULL if extended information
+ * is not available.
+ */
+ mode_t mode = (dirinfo->entries[idx].flags & SavedirHaveFileType) ?
+ dirinfo->entries[idx].type_info : 0;
+ namep = dirinfo->entries[idx].name;
+
/* Append this directory entry's name to the path being searched. */
file_len = pathname_len + strlen (namep);
if (file_len > cur_path_size)
@@ -478,62 +1954,125 @@ process_dir (pathname, name, pathlen, statp, parent)
cur_name = cur_path + pathname_len - 1;
strcpy (cur_name, namep);
- curdepth++;
- if (!no_leaf_check)
- /* Normal case optimization.
- On normal Unix filesystems, a directory that has no
- subdirectories has two links: its name, and ".". Any
- additional links are to the ".." entries of its
- subdirectories. Once we have processed as many
- subdirectories as there are additional links, we know
- that the rest of the entries are non-directories --
- in other words, leaf files. */
- subdirs_left -= process_path (cur_path, cur_name,
- subdirs_left == 0, pathname);
- else
- /* There might be weird (e.g., CD-ROM or MS-DOS) filesystems
- mounted, which don't have Unix-like directory link counts. */
- process_path (cur_path, cur_name, false, pathname);
- curdepth--;
- }
-
- if (strcmp (name, "."))
- {
- if (!dereference)
+ state.curdepth++;
+ if (!options.no_leaf_check && !subdirs_unreliable)
{
- if (chdir ("..") < 0)
- /* We could go back and do the next command-line arg instead,
- maybe using longjmp. */
- error (1, errno, "%s", parent);
+ if (mode && S_ISDIR(mode) && (subdirs_left == 0))
+ {
+ /* This is a subdirectory, but the number of directories we
+ * have found now exceeds the number we would expect given
+ * the hard link count on the parent. This is likely to be
+ * a bug in the filesystem driver (e.g. Linux's
+ * /proc filesystem) or may just be a fact that the OS
+ * doesn't really handle hard links with Unix semantics.
+ * In the latter case, -noleaf should be used routinely.
+ */
+ error(0, 0, _("WARNING: Hard link count is wrong for %s: this may be a bug in your filesystem driver. Automatically turning on find's -noleaf option. Earlier results may have failed to include directories that should have been searched."),
+ pathname);
+ state.exit_status = 1; /* We know the result is wrong, now */
+ options.no_leaf_check = true; /* Don't make same
+ mistake again */
+ subdirs_left = 1; /* band-aid for this iteration. */
+ }
+
+ /* Normal case optimization. On normal Unix
+ filesystems, a directory that has no subdirectories
+ has two links: its name, and ".". Any additional
+ links are to the ".." entries of its subdirectories.
+ Once we have processed as many subdirectories as
+ there are additional links, we know that the rest of
+ the entries are non-directories -- in other words,
+ leaf files. */
+ subdirs_left -= process_path (cur_path, cur_name,
+ subdirs_left == 0, pathname,
+ mode);
}
else
{
-#ifndef HAVE_FCHDIR
- if (chdir (starting_dir) || chdir (parent))
- error (1, errno, "%s", parent);
-#else
- if (fchdir (starting_desc) || chdir (parent))
- error (1, errno, "%s", parent);
-#endif
+ /* There might be weird (e.g., CD-ROM or MS-DOS) filesystems
+ mounted, which don't have Unix-like directory link counts. */
+ process_path (cur_path, cur_name, false, pathname, mode);
+ }
+
+ state.curdepth--;
+ }
+
+
+ /* We're about to leave the directory. If there are any
+ * -execdir argument lists which have been built but have not
+ * yet been processed, do them now because they must be done in
+ * the same directory.
+ */
+ complete_pending_execdirs(eval_tree);
+
+
+ if (strcmp (name, "."))
+ {
+ enum SafeChdirStatus status;
+ struct dir_id did;
+ boolean did_stat = false;
+
+ /* We could go back and do the next command-line arg
+ instead, maybe using longjmp. */
+ char const *dir;
+ boolean deref = following_links() ? true : false;
+
+ if ( (state.curdepth>0) && !deref)
+ dir = "..";
+ else
+ {
+ chdir_back ();
+ dir = parent;
+ }
+
+ status = safely_chdir (dir, TraversingUp, &stat_buf, SymlinkHandleDefault, &did_stat);
+ switch (status)
+ {
+ case SafeChdirOK:
+ break;
+
+ case SafeChdirFailWouldBeUnableToReturn:
+ error (1, errno, ".");
+ return;
+
+ case SafeChdirFailNonexistent:
+ case SafeChdirFailDestUnreadable:
+ case SafeChdirFailStat:
+ case SafeChdirFailSymlink:
+ case SafeChdirFailNotDir:
+ case SafeChdirFailChdirFailed:
+ error (1, errno, "%s", pathname);
+ return;
+ }
+
+ if (dir_curr > 0)
+ {
+ did.dev = dir_ids[dir_curr-1].dev;
+ did.ino = dir_ids[dir_curr-1].ino;
+ }
+ else
+ {
+ did.dev = starting_stat_buf.st_dev;
+ did.ino = starting_stat_buf.st_ino;
}
}
if (cur_path)
free (cur_path);
- free (name_space);
+ free_dirinfo(dirinfo);
}
}
-/* Return true if there are no side effects in any of the predicates in
- predicate list PRED, false if there are any. */
+/* Return true if there are no predicates with no_default_print in
+ predicate list PRED, false if there are any.
+ Returns true if default print should be performed */
static boolean
-no_side_effects (pred)
- struct predicate *pred;
+default_prints (struct predicate *pred)
{
while (pred != NULL)
{
- if (pred->side_effects)
+ if (pred->no_default_print)
return (false);
pred = pred->pred_next;
}
diff --git a/src/bin/findutils/find/fstype.c b/src/bin/findutils/find/fstype.c
index 56492a50c9..45c712ecca 100644
--- a/src/bin/findutils/find/fstype.c
+++ b/src/bin/findutils/find/fstype.c
@@ -1,10 +1,10 @@
/* fstype.c -- determine type of filesystems that files are on
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 91, 92, 93, 94, 2000, 2003, 2004, 2005 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,144 +12,109 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see .
+*/
+
+/* Written by David MacKenzie .
+ *
+ * Converted to use gnulib's read_file_system_list()
+ * by James Youngman (which saves a lot
+ * of manual hacking of configure.in).
+ */
-/* Written by David MacKenzie . */
#include
-#include
-#include
-#include
-#include "defs.h"
-#include "modetype.h"
#include
+#include
+#include
+
+#ifdef HAVE_SYS_TYPES_H
+#include
+#endif
+
+/* The presence of unistd.h is assumed by gnulib these days, so we
+ * might as well assume it too.
+ */
+#include
+
+#ifdef HAVE_SYS_MNTIO_H
+#ifdef HAVE_FCNTL_H
+#include
+#endif
+#include
+#endif
+#ifdef HAVE_SYS_MKDEV_H
+#include
+#endif
+
#ifdef STDC_HEADERS
#include
#else
extern int errno;
#endif
-char *strdup ();
-char *strstr ();
+#include "defs.h"
+#include "../gnulib/lib/dirname.h"
+#include "xalloc.h"
+#include "modetype.h"
-static char *filesystem_type_uncached P_((char *path, char *relpath, struct stat *statp));
-static int xatoi P_((char *cp));
+/* Need declaration of function `xstrtoumax' */
+#include "../gnulib/lib/xstrtol.h"
-#ifdef FSTYPE_MNTENT /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
-#include
-#if !defined(MOUNTED)
-# if defined(MNT_MNTTAB) /* HP-UX. */
-# define MOUNTED MNT_MNTTAB
-# endif
-# if defined(MNTTABNAME) /* Dynix. */
-# define MOUNTED MNTTABNAME
-# endif
+#include "extendbuf.h"
+#include "mountlist.h"
+
+
+
+#if ENABLE_NLS
+# include
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
#endif
-#ifdef FSTYPE_GETMNT /* Ultrix. */
-#include
-#include
-#include
+static char *filesystem_type_uncached PARAMS((const struct stat *statp, const char *path));
+
+
+/* Get MNTTYPE_IGNORE if it is available. */
+#if HAVE_MNTENT_H
+# include
+#endif
+#if HAVE_SYS_MNTTAB_H
+# include
+# include
#endif
-#ifdef FSTYPE_USG_STATFS /* SVR3. */
-#include
-#include
-#endif
-#ifdef FSTYPE_STATVFS /* SVR4. */
-#include
-#include
-#endif
-#ifdef FSTYPE_STATFS /* 4.4BSD. */
-#include /* NetBSD needs this. */
-#include
-#ifndef MFSNAMELEN /* NetBSD defines this. */
-static char *
-fstype_to_string (t)
- short t;
+
+static void
+free_file_system_list(struct mount_entry *p)
{
-#ifdef INITMOUNTNAMES /* Defined in 4.4BSD, not in NET/2. */
- static char *mn[] = INITMOUNTNAMES;
- if (t >= 0 && t <= MOUNT_MAXTYPE)
- return mn[t];
- else
- return "?";
-#else /* !INITMOUNTNAMES */
- switch (t)
+ while (p)
{
- case MOUNT_UFS:
- return "ufs";
- case MOUNT_NFS:
- return "nfs";
-#ifdef MOUNT_PC
- case MOUNT_PC:
- return "pc";
-#endif
-#ifdef MOUNT_MFS
- case MOUNT_MFS:
- return "mfs";
-#endif
-#ifdef MOUNT_LO
- case MOUNT_LO:
- return "lofs";
-#endif
-#ifdef MOUNT_TFS
- case MOUNT_TFS:
- return "tfs";
-#endif
-#ifdef MOUNT_TMP
- case MOUNT_TMP:
- return "tmp";
-#endif
-#ifdef MOUNT_MSDOS
- case MOUNT_MSDOS:
- return "msdos";
-#endif
-#ifdef MOUNT_ISO9660
- case MOUNT_ISO9660:
- return "iso9660fs";
-#endif
- default:
- return "?";
- }
-#endif /* !INITMOUNTNAMES */
-}
-#endif /* !MFSNAMELEN */
-#endif /* FSTYPE_STATFS */
-
-#ifdef FSTYPE_AIX_STATFS /* AIX. */
-#include
-#include
-
-#define FSTYPE_STATFS /* Otherwise like 4.4BSD. */
-#define f_type f_vfstype
-
-static char *
-fstype_to_string (t)
- short t;
-{
- switch (t)
- {
- case MNT_AIX:
-#if 0 /* NFS filesystems are actually MNT_AIX. */
- return "aix";
-#endif
- case MNT_NFS:
- return "nfs";
- case MNT_JFS:
- return "jfs";
- case MNT_CDROM:
- return "cdrom";
- default:
- return "?";
+ struct mount_entry *pnext = p->me_next;
+
+ free(p->me_devname);
+ free(p->me_mountdir);
+
+ if(p->me_type_malloced)
+ free(p->me_type);
+ p->me_next = NULL;
+ free(p);
+ p = pnext;
}
}
-#endif /* FSTYPE_AIX_STATFS */
+
+
+
#ifdef AFS
#include
@@ -165,8 +130,7 @@ fstype_to_string (t)
#endif
static int
-in_afs (path)
- char *path;
+in_afs (char *path)
{
static char space[2048];
struct ViceIoctl vi;
@@ -191,10 +155,7 @@ static int fstype_known = 0;
Return "unknown" if its filesystem type is unknown. */
char *
-filesystem_type (path, relpath, statp)
- char *path;
- char *relpath;
- struct stat *statp;
+filesystem_type (const struct stat *statp, const char *path)
{
static char *current_fstype = NULL;
static dev_t current_dev;
@@ -206,181 +167,146 @@ filesystem_type (path, relpath, statp)
free (current_fstype);
}
current_dev = statp->st_dev;
- current_fstype = filesystem_type_uncached (path, relpath, statp);
+ current_fstype = filesystem_type_uncached (statp, path);
return current_fstype;
}
+static int
+set_fstype_devno(struct mount_entry *p)
+{
+ struct stat stbuf;
+
+ if (p->me_dev == (dev_t)-1)
+ {
+ if (0 == (options.xstat)(p->me_mountdir, &stbuf))
+ {
+ p->me_dev = stbuf.st_dev;
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ return 0; /* not needed */
+}
+
+static struct mount_entry *
+must_read_fs_list(bool need_fs_type)
+{
+ struct mount_entry *entries = read_file_system_list(need_fs_type);
+ if (NULL == entries)
+ {
+ /* We cannot determine for sure which file we were trying to
+ * use because gnulib has extracted all that stuff away.
+ * Hence we cannot issue a specific error message here.
+ */
+ error(1, 0, "Cannot read mounted filesystem list");
+ }
+ return entries;
+}
+
+
+
/* Return a newly allocated string naming the type of filesystem that the
file PATH, described by STATP, is on.
RELPATH is the file name relative to the current directory.
Return "unknown" if its filesystem type is unknown. */
static char *
-filesystem_type_uncached (path, relpath, statp)
- char *path;
- char *relpath;
- struct stat *statp;
+filesystem_type_uncached (const struct stat *statp, const char *path)
{
- char *type = NULL;
-
-#ifdef FSTYPE_MNTENT /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
- char *table = MOUNTED;
- FILE *mfp;
- struct mntent *mnt;
-
- mfp = setmntent (table, "r");
- if (mfp == NULL)
- error (1, errno, "%s", table);
-
- /* Find the entry with the same device number as STATP, and return
- that entry's fstype. */
- while (type == NULL && (mnt = getmntent (mfp)))
- {
- char *devopt;
- dev_t dev;
- struct stat disk_stats;
-
-#ifdef MNTTYPE_IGNORE
- if (!strcmp (mnt->mnt_type, MNTTYPE_IGNORE))
- continue;
-#endif
-
- /* Newer systems like SunOS 4.1 keep the dev number in the mtab,
- in the options string. For older systems, we need to stat the
- directory that the filesystem is mounted on to get it.
-
- Unfortunately, the HPUX 9.x mnttab entries created by automountq
- contain a dev= option but the option value does not match the
- st_dev value of the file (maybe the lower 16 bits match?). */
-
-#if !defined(hpux) && !defined(__hpux__)
- devopt = strstr (mnt->mnt_opts, "dev=");
- if (devopt)
- {
- if (devopt[4] == '0' && (devopt[5] == 'x' || devopt[5] == 'X'))
- dev = xatoi (devopt + 6);
- else
- dev = xatoi (devopt + 4);
- }
- else
-#endif /* not hpux */
- {
- if (stat (mnt->mnt_dir, &disk_stats) == -1)
- error (1, errno, "error in %s: %s", table, mnt->mnt_dir);
- dev = disk_stats.st_dev;
- }
-
- if (dev == statp->st_dev)
- type = mnt->mnt_type;
- }
-
- if (endmntent (mfp) == 0)
- error (0, errno, "%s", table);
-#endif
-
-#ifdef FSTYPE_GETMNT /* Ultrix. */
- int offset = 0;
- struct fs_data fsd;
-
- while (type == NULL
- && getmnt (&offset, &fsd, sizeof (fsd), NOSTAT_MANY, 0) > 0)
- {
- if (fsd.fd_req.dev == statp->st_dev)
- type = gt_names[fsd.fd_req.fstype];
- }
-#endif
-
-#ifdef FSTYPE_USG_STATFS /* SVR3. */
- struct statfs fss;
- char typebuf[FSTYPSZ];
-
- if (statfs (relpath, &fss, sizeof (struct statfs), 0) == -1)
- {
- /* Don't die if a file was just removed. */
- if (errno != ENOENT)
- error (1, errno, "%s", path);
- }
- else if (!sysfs (GETFSTYP, fss.f_fstyp, typebuf))
- type = typebuf;
-#endif
-
-#ifdef FSTYPE_STATVFS /* SVR4. */
- struct statvfs fss;
-
- if (statvfs (relpath, &fss) == -1)
- {
- /* Don't die if a file was just removed. */
- if (errno != ENOENT)
- error (1, errno, "%s", path);
- }
- else
- type = fss.f_basetype;
-#endif
-
-#ifdef FSTYPE_STATFS /* 4.4BSD. */
- struct statfs fss;
- char *p;
-
- if (S_ISLNK (statp->st_mode))
- p = dirname (relpath);
- else
- p = relpath;
-
- if (statfs (p, &fss) == -1)
- {
- /* Don't die if symlink to nonexisting file, or a file that was
- just removed. */
- if (errno != ENOENT)
- error (1, errno, "%s", path);
- }
- else
- {
-#ifdef MFSNAMELEN /* NetBSD. */
- type = xstrdup (fss.f_fstypename);
-#else
- type = fstype_to_string (fss.f_type);
-#endif
- }
- if (p != relpath)
- free (p);
-#endif
+ struct mount_entry *entries, *entry;
+ char *type;
#ifdef AFS
- if ((!type || !strcmp (type, "xx")) && in_afs (relpath))
- type = "afs";
-#endif
-
- /* An unknown value can be caused by an ENOENT error condition.
- Don't cache those values. */
- fstype_known = (type != NULL);
-
- return xstrdup (type ? type : "unknown");
-}
-
-#ifdef FSTYPE_MNTENT /* 4.3BSD etc. */
-/* Return the value of the hexadecimal number represented by CP.
- No prefix (like '0x') or suffix (like 'h') is expected to be
- part of CP. */
-
-static int
-xatoi (cp)
- char *cp;
-{
- int val;
-
- val = 0;
- while (*cp)
+ if (in_afs(path))
{
- if (*cp >= 'a' && *cp <= 'f')
- val = val * 16 + *cp - 'a' + 10;
- else if (*cp >= 'A' && *cp <= 'F')
- val = val * 16 + *cp - 'A' + 10;
- else if (*cp >= '0' && *cp <= '9')
- val = val * 16 + *cp - '0';
- else
- break;
- cp++;
+ fstype_known = 1;
+ return xstrdup("afs");
}
- return val;
-}
+#endif
+
+ entries = must_read_fs_list(true);
+ for (type=NULL, entry=entries; entry; entry=entry->me_next)
+ {
+#ifdef MNTTYPE_IGNORE
+ if (!strcmp (entry->me_type, MNTTYPE_IGNORE))
+ continue;
#endif
+ set_fstype_devno(entry);
+ if (entry->me_dev == statp->st_dev)
+ {
+ type = xstrdup(entry->me_type);
+ break;
+ }
+ }
+ free_file_system_list(entries);
+
+ /* Don't cache unknown values. */
+ fstype_known = (type != NULL);
+
+ return type ? type : xstrdup(_("unknown"));
+}
+
+
+char *
+get_mounted_filesystems (void)
+{
+ char *result = NULL;
+ size_t alloc_size = 0u;
+ size_t used = 0u;
+ struct mount_entry *entries, *entry;
+
+ entries = must_read_fs_list(false);
+ for (entry=entries; entry; entry=entry->me_next)
+ {
+ size_t len;
+
+#ifdef MNTTYPE_IGNORE
+ if (!strcmp (entry->me_type, MNTTYPE_IGNORE))
+ continue;
+#endif
+ set_fstype_devno(entry);
+
+ len = strlen(entry->me_mountdir) + 1;
+ result = extendbuf(result, used+len, &alloc_size);
+ strcpy(&result[used], entry->me_mountdir);
+ used += len; /* len already includes one for the \0 */
+ }
+
+ free_file_system_list(entries);
+ return result;
+}
+
+
+dev_t *
+get_mounted_devices (size_t *n)
+{
+ size_t alloc_size = 0u;
+ size_t used = 0u;
+ struct mount_entry *entries, *entry;
+ dev_t *result = NULL;
+
+ /* Use read_file_system_list() rather than must_read_fs_list()
+ * because on some system this is always called at startup,
+ * and find should only exit fatally if it needs to use the
+ * result of this operation. If we can't get the fs list
+ * but we never need the information, there is no need to fail.
+ */
+ for (entry = entries = read_file_system_list(false);
+ entry;
+ entry = entry->me_next)
+ {
+ result = extendbuf(result, sizeof(dev_t)*(used+1), &alloc_size);
+ set_fstype_devno(entry);
+ result[used] = entry->me_dev;
+ ++used;
+ }
+ free_file_system_list(entries);
+ *n = used;
+ return result;
+}
+
+
+
diff --git a/src/bin/findutils/find/parser.c b/src/bin/findutils/find/parser.c
index 3bb87c89ce..cb88e88101 100644
--- a/src/bin/findutils/find/parser.c
+++ b/src/bin/findutils/find/parser.c
@@ -1,10 +1,11 @@
/* parser.c -- convert the command line args into an expression tree.
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000, 2001, 2003,
+ 2004, 2005, 2007 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -12,19 +13,51 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see .
+*/
-#include
-#include
-#include
+
+#include "defs.h"
#include
-#include
#include
#include
+#include
#include "modechange.h"
-#include "defs.h"
#include "modetype.h"
+#include "xstrtol.h"
+#include "xalloc.h"
+#include "quote.h"
+#include "quotearg.h"
+#include "buildcmd.h"
+#include "nextelem.h"
+#include "stdio-safer.h"
+#include "regextype.h"
+#include "gnulib-version.h"
+
+#ifdef HAVE_FCNTL_H
+#include
+#else
+#include
+#endif
+
+/* The presence of unistd.h is assumed by gnulib these days, so we
+ * might as well assume it too.
+ */
+/* We need for isatty(). */
+#include
+
+#if ENABLE_NLS
+# include
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
+#endif
#if !defined (isascii) || defined (STDC_HEADERS)
#ifdef isascii
@@ -33,223 +66,336 @@
#define isascii(c) 1
#endif
-#define ISDIGIT(c) (isascii (c) && isdigit (c))
-#define ISUPPER(c) (isascii (c) && isupper (c))
+#define ISDIGIT(c) (isascii ((unsigned char)c) && isdigit ((unsigned char)c))
+#define ISUPPER(c) (isascii ((unsigned char)c) && isupper ((unsigned char)c))
-#ifndef _POSIX_VERSION
-/* POSIX.1 header files should declare these. */
-struct group *getgrnam ();
-struct passwd *getpwnam ();
-#endif
-
-#ifdef CACHE_IDS
-/* These two aren't specified by POSIX.1. */
-struct group *getgrent ();
-struct passwd *getpwent ();
-#endif
-
-#ifndef S_IFLNK
-#define lstat stat
-#endif
-
-char *strstr ();
-int lstat ();
-int stat ();
-#ifndef atol /* for Linux */
-long atol ();
-#endif
-struct tm *localtime ();
-
-#ifdef _POSIX_SOURCE
+#ifndef HAVE_ENDGRENT
#define endgrent()
+#endif
+#ifndef HAVE_ENDPWENT
#define endpwent()
-#else
-void endgrent ();
-void endpwent ();
#endif
-static boolean parse_amin P_((char *argv[], int *arg_ptr));
-static boolean parse_and P_((char *argv[], int *arg_ptr));
-static boolean parse_anewer P_((char *argv[], int *arg_ptr));
-static boolean parse_atime P_((char *argv[], int *arg_ptr));
-boolean parse_close P_((char *argv[], int *arg_ptr));
-static boolean parse_cmin P_((char *argv[], int *arg_ptr));
-static boolean parse_cnewer P_((char *argv[], int *arg_ptr));
-static boolean parse_comma P_((char *argv[], int *arg_ptr));
-static boolean parse_ctime P_((char *argv[], int *arg_ptr));
-static boolean parse_daystart P_((char *argv[], int *arg_ptr));
-static boolean parse_depth P_((char *argv[], int *arg_ptr));
-static boolean parse_empty P_((char *argv[], int *arg_ptr));
-static boolean parse_exec P_((char *argv[], int *arg_ptr));
-static boolean parse_false P_((char *argv[], int *arg_ptr));
-static boolean parse_fls P_((char *argv[], int *arg_ptr));
-static boolean parse_fprintf P_((char *argv[], int *arg_ptr));
-static boolean parse_follow P_((char *argv[], int *arg_ptr));
-static boolean parse_fprint P_((char *argv[], int *arg_ptr));
-static boolean parse_fprint0 P_((char *argv[], int *arg_ptr));
-static boolean parse_fstype P_((char *argv[], int *arg_ptr));
-static boolean parse_gid P_((char *argv[], int *arg_ptr));
-static boolean parse_group P_((char *argv[], int *arg_ptr));
-static boolean parse_help P_((char *argv[], int *arg_ptr));
-static boolean parse_ilname P_((char *argv[], int *arg_ptr));
-static boolean parse_iname P_((char *argv[], int *arg_ptr));
-static boolean parse_inum P_((char *argv[], int *arg_ptr));
-static boolean parse_ipath P_((char *argv[], int *arg_ptr));
-static boolean parse_iregex P_((char *argv[], int *arg_ptr));
-static boolean parse_links P_((char *argv[], int *arg_ptr));
-static boolean parse_lname P_((char *argv[], int *arg_ptr));
-static boolean parse_ls P_((char *argv[], int *arg_ptr));
-static boolean parse_maxdepth P_((char *argv[], int *arg_ptr));
-static boolean parse_mindepth P_((char *argv[], int *arg_ptr));
-static boolean parse_mmin P_((char *argv[], int *arg_ptr));
-static boolean parse_mtime P_((char *argv[], int *arg_ptr));
-static boolean parse_name P_((char *argv[], int *arg_ptr));
-static boolean parse_negate P_((char *argv[], int *arg_ptr));
-static boolean parse_newer P_((char *argv[], int *arg_ptr));
-static boolean parse_noleaf P_((char *argv[], int *arg_ptr));
-static boolean parse_nogroup P_((char *argv[], int *arg_ptr));
-static boolean parse_nouser P_((char *argv[], int *arg_ptr));
-static boolean parse_ok P_((char *argv[], int *arg_ptr));
-boolean parse_open P_((char *argv[], int *arg_ptr));
-static boolean parse_or P_((char *argv[], int *arg_ptr));
-static boolean parse_path P_((char *argv[], int *arg_ptr));
-static boolean parse_perm P_((char *argv[], int *arg_ptr));
-boolean parse_print P_((char *argv[], int *arg_ptr));
-static boolean parse_print0 P_((char *argv[], int *arg_ptr));
-static boolean parse_printf P_((char *argv[], int *arg_ptr));
-static boolean parse_prune P_((char *argv[], int *arg_ptr));
-static boolean parse_regex P_((char *argv[], int *arg_ptr));
-static boolean insert_regex P_((char *argv[], int *arg_ptr, boolean ignore_case));
-static boolean parse_size P_((char *argv[], int *arg_ptr));
-static boolean parse_true P_((char *argv[], int *arg_ptr));
-static boolean parse_type P_((char *argv[], int *arg_ptr));
-static boolean parse_uid P_((char *argv[], int *arg_ptr));
-static boolean parse_used P_((char *argv[], int *arg_ptr));
-static boolean parse_user P_((char *argv[], int *arg_ptr));
-static boolean parse_version P_((char *argv[], int *arg_ptr));
-static boolean parse_xdev P_((char *argv[], int *arg_ptr));
-static boolean parse_xtype P_((char *argv[], int *arg_ptr));
+static boolean parse_amin PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_and PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_anewer PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_atime PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_cmin PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_cnewer PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_comma PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_ctime PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_daystart PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_delete PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_d PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_depth PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_empty PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_exec PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_execdir PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_false PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_fls PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_fprintf PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_follow PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_fprint PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_fprint0 PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_fstype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_gid PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_group PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_help PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_ilname PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_iname PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_inum PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_ipath PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_iregex PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_iwholename PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_links PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_lname PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_ls PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_maxdepth PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_mindepth PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_mmin PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_mtime PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_name PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_negate PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_newer PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_noleaf PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_nogroup PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_nouser PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_nowarn PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_ok PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_okdir PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_or PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_path PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_perm PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_print0 PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_printf PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_prune PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_regex PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_regextype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_samefile PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_size PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_true PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_type PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_uid PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_used PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_user PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_version PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_wholename PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_xdev PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_ignore_race PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_noignore_race PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_warn PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_xtype PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+static boolean parse_quit PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
-static boolean insert_regex P_((char *argv[], int *arg_ptr, boolean ignore_case));
-static boolean insert_type P_((char *argv[], int *arg_ptr, boolean (*which_pred )()));
-static boolean insert_fprintf P_((FILE *fp, boolean (*func )(), char *argv[], int *arg_ptr));
-static struct segment **make_segment P_((struct segment **segment, char *format, int len, int kind));
-static boolean insert_exec_ok P_((boolean (*func )(), char *argv[], int *arg_ptr));
-static boolean get_num_days P_((char *str, unsigned long *num_days, enum comparison_type *comp_type));
-static boolean insert_time P_((char *argv[], int *arg_ptr, PFB pred));
-static boolean get_num P_((char *str, unsigned long *num, enum comparison_type *comp_type));
-static boolean insert_num P_((char *argv[], int *arg_ptr, PFB pred));
-static FILE *open_output_file P_((char *path));
+
+
+boolean parse_print PARAMS((const struct parser_table*, char *argv[], int *arg_ptr));
+
+
+
+static boolean insert_type PARAMS((char **argv, int *arg_ptr, const struct parser_table *entry, PRED_FUNC which_pred));
+static boolean insert_regex PARAMS((char *argv[], int *arg_ptr, const struct parser_table *entry, int regex_options));
+static boolean insert_fprintf PARAMS((FILE *fp, const struct parser_table *entry, PRED_FUNC func, char *argv[], int *arg_ptr));
+
+static struct segment **make_segment PARAMS((struct segment **segment, char *format, int len, int kind));
+static boolean insert_exec_ok PARAMS((const char *action, const struct parser_table *entry, char *argv[], int *arg_ptr));
+static boolean get_num_days PARAMS((char *str, uintmax_t *num_days, enum comparison_type *comp_type));
+static boolean insert_time PARAMS((char **argv, int *arg_ptr, const struct parser_table* entry, PRED_FUNC pred));
+static boolean get_num PARAMS((char *str, uintmax_t *num, enum comparison_type *comp_type));
+static boolean insert_num PARAMS((char *argv[], int *arg_ptr, const struct parser_table *entry));
+static FILE *open_output_file PARAMS((char *path));
+static boolean stream_is_tty(FILE *fp);
#ifdef DEBUG
-char *find_pred_name(PFB pred_func);
+char *find_pred_name PARAMS((PRED_FUNC pred_func));
#endif /* DEBUG */
-struct parser_table
-{
- char *parser_name;
- PFB parser_func;
-};
+
+#define PASTE(x,y) x##y
+#define STRINGIFY(s) #s
+
+#define PARSE_OPTION(what,suffix) \
+ { (ARG_OPTION), (what), PASTE(parse_,suffix), NULL }
+
+#define PARSE_POSOPT(what,suffix) \
+ { (ARG_POSITIONAL_OPTION), (what), PASTE(parse_,suffix), NULL }
+
+#define PARSE_TEST(what,suffix) \
+ { (ARG_TEST), (what), PASTE(parse_,suffix), PASTE(pred_,suffix) }
+
+#define PARSE_TEST_NP(what,suffix) \
+ { (ARG_TEST), (what), PASTE(parse_,suffix), NULL }
+
+#define PARSE_ACTION(what,suffix) \
+ { (ARG_ACTION), (what), PASTE(parse_,suffix), PASTE(pred_,suffix) }
+
+#define PARSE_ACTION_NP(what,suffix) \
+ { (ARG_ACTION), (what), PASTE(parse_,suffix), NULL }
+
+#define PARSE_PUNCTUATION(what,suffix) \
+ { (ARG_PUNCTUATION), (what), PASTE(parse_,suffix), PASTE(pred_,suffix) }
+
/* GNU find predicates that are not mentioned in POSIX.2 are marked `GNU'.
If they are in some Unix versions of find, they are marked `Unix'. */
static struct parser_table const parse_table[] =
{
- {"!", parse_negate},
- {"not", parse_negate}, /* GNU */
- {"(", parse_open},
- {")", parse_close},
- {",", parse_comma}, /* GNU */
- {"a", parse_and},
- {"amin", parse_amin}, /* GNU */
- {"and", parse_and}, /* GNU */
- {"anewer", parse_anewer}, /* GNU */
- {"atime", parse_atime},
- {"cmin", parse_cmin}, /* GNU */
- {"cnewer", parse_cnewer}, /* GNU */
+ PARSE_PUNCTUATION("!", negate),
+ PARSE_PUNCTUATION("not", negate), /* GNU */
+ PARSE_PUNCTUATION("(", openparen),
+ PARSE_PUNCTUATION(")", closeparen),
+ PARSE_PUNCTUATION(",", comma), /* GNU */
+ PARSE_PUNCTUATION("a", and),
+ PARSE_TEST ("amin", amin), /* GNU */
+ PARSE_PUNCTUATION("and", and), /* GNU */
+ PARSE_TEST ("anewer", anewer), /* GNU */
+ PARSE_TEST ("atime", atime),
+ PARSE_TEST ("cmin", cmin), /* GNU */
+ PARSE_TEST ("cnewer", cnewer), /* GNU */
+ PARSE_TEST ("ctime", ctime),
+ PARSE_POSOPT ("daystart", daystart), /* GNU */
+ PARSE_ACTION ("delete", delete), /* GNU, Mac OS, FreeBSD */
+ PARSE_OPTION ("d", d), /* Mac OS X, FreeBSD, NetBSD, OpenBSD, but deprecated in favour of -depth */
+ PARSE_OPTION ("depth", depth),
+ PARSE_TEST ("empty", empty), /* GNU */
+ {ARG_ACTION, "exec", parse_exec, pred_exec}, /* POSIX */
+ PARSE_ACTION ("execdir", execdir), /* *BSD, GNU */
+ PARSE_ACTION ("fls", fls), /* GNU */
+ PARSE_POSOPT ("follow", follow), /* GNU, Unix */
+ PARSE_ACTION ("fprint", fprint), /* GNU */
+ PARSE_ACTION ("fprint0", fprint0), /* GNU */
+ {ARG_ACTION, "fprintf", parse_fprintf, pred_fprintf}, /* GNU */
+ PARSE_TEST ("fstype", fstype), /* GNU, Unix */
+ PARSE_TEST ("gid", gid), /* GNU */
+ PARSE_TEST ("group", group),
+ PARSE_OPTION ("ignore_readdir_race", ignore_race), /* GNU */
+ PARSE_TEST ("ilname", ilname), /* GNU */
+ PARSE_TEST ("iname", iname), /* GNU */
+ PARSE_TEST ("inum", inum), /* GNU, Unix */
+ PARSE_TEST ("ipath", ipath), /* GNU, deprecated in favour of iwholename */
+ PARSE_TEST_NP ("iregex", iregex), /* GNU */
+ PARSE_TEST_NP ("iwholename", iwholename), /* GNU */
+ PARSE_TEST ("links", links),
+ PARSE_TEST ("lname", lname), /* GNU */
+ PARSE_ACTION ("ls", ls), /* GNU, Unix */
+ PARSE_OPTION ("maxdepth", maxdepth), /* GNU */
+ PARSE_OPTION ("mindepth", mindepth), /* GNU */
+ PARSE_TEST ("mmin", mmin), /* GNU */
+ PARSE_OPTION ("mount", xdev), /* Unix */
+ PARSE_TEST ("mtime", mtime),
+ PARSE_TEST ("name", name),
+#ifdef UNIMPLEMENTED_UNIX
+ PARSE(ARG_UNIMPLEMENTED, "ncpio", ncpio), /* Unix */
+#endif
+ PARSE_TEST ("newer", newer),
+ PARSE_OPTION ("noleaf", noleaf), /* GNU */
+ PARSE_TEST ("nogroup", nogroup),
+ PARSE_TEST ("nouser", nouser),
+ PARSE_OPTION ("noignore_readdir_race", noignore_race), /* GNU */
+ PARSE_OPTION ("nowarn", nowarn), /* GNU */
+ PARSE_PUNCTUATION("o", or),
+ PARSE_PUNCTUATION("or", or), /* GNU */
+ PARSE_ACTION ("ok", ok),
+ PARSE_ACTION ("okdir", okdir), /* GNU (-execdir is BSD) */
+ PARSE_TEST ("path", path), /* GNU, HP-UX, GNU prefers wholename */
+ PARSE_TEST ("perm", perm),
+ PARSE_ACTION ("print", print),
+ PARSE_ACTION ("print0", print0), /* GNU */
+ {ARG_ACTION, "printf", parse_printf, NULL}, /* GNU */
+ PARSE_ACTION ("prune", prune),
+ PARSE_ACTION ("quit", quit), /* GNU */
+ PARSE_TEST ("regex", regex), /* GNU */
+ PARSE_OPTION ("regextype", regextype), /* GNU */
+ PARSE_TEST ("samefile", samefile), /* GNU */
+ PARSE_TEST ("size", size),
+ PARSE_TEST ("type", type),
+ PARSE_TEST ("uid", uid), /* GNU */
+ PARSE_TEST ("used", used), /* GNU */
+ PARSE_TEST ("user", user),
+ PARSE_OPTION ("warn", warn), /* GNU */
+ PARSE_TEST_NP ("wholename", wholename), /* GNU, replaces -path */
+ PARSE_OPTION ("xdev", xdev),
+ PARSE_TEST ("xtype", xtype), /* GNU */
#ifdef UNIMPLEMENTED_UNIX
/* It's pretty ugly for find to know about archive formats.
Plus what it could do with cpio archives is very limited.
Better to leave it out. */
- {"cpio", parse_cpio}, /* Unix */
+ PARSE(ARG_UNIMPLEMENTED, "cpio", cpio), /* Unix */
#endif
- {"ctime", parse_ctime},
- {"daystart", parse_daystart}, /* GNU */
- {"depth", parse_depth},
- {"empty", parse_empty}, /* GNU */
- {"exec", parse_exec},
- {"false", parse_false}, /* GNU */
- {"fls", parse_fls}, /* GNU */
- {"follow", parse_follow}, /* GNU, Unix */
- {"fprint", parse_fprint}, /* GNU */
- {"fprint0", parse_fprint0}, /* GNU */
- {"fprintf", parse_fprintf}, /* GNU */
- {"fstype", parse_fstype}, /* GNU, Unix */
- {"gid", parse_gid}, /* GNU */
- {"group", parse_group},
- {"help", parse_help}, /* GNU */
- {"-help", parse_help}, /* GNU */
- {"ilname", parse_ilname}, /* GNU */
- {"iname", parse_iname}, /* GNU */
- {"inum", parse_inum}, /* GNU, Unix */
- {"ipath", parse_ipath}, /* GNU */
- {"iregex", parse_iregex}, /* GNU */
- {"links", parse_links},
- {"lname", parse_lname}, /* GNU */
- {"ls", parse_ls}, /* GNU, Unix */
- {"maxdepth", parse_maxdepth}, /* GNU */
- {"mindepth", parse_mindepth}, /* GNU */
- {"mmin", parse_mmin}, /* GNU */
- {"mount", parse_xdev}, /* Unix */
- {"mtime", parse_mtime},
- {"name", parse_name},
-#ifdef UNIMPLEMENTED_UNIX
- {"ncpio", parse_ncpio}, /* Unix */
-#endif
- {"newer", parse_newer},
- {"noleaf", parse_noleaf}, /* GNU */
- {"nogroup", parse_nogroup},
- {"nouser", parse_nouser},
- {"o", parse_or},
- {"or", parse_or}, /* GNU */
- {"ok", parse_ok},
- {"path", parse_path}, /* GNU, HP-UX */
- {"perm", parse_perm},
- {"print", parse_print},
- {"print0", parse_print0}, /* GNU */
- {"printf", parse_printf}, /* GNU */
- {"prune", parse_prune},
- {"regex", parse_regex}, /* GNU */
- {"size", parse_size},
- {"true", parse_true}, /* GNU */
- {"type", parse_type},
- {"uid", parse_uid}, /* GNU */
- {"used", parse_used}, /* GNU */
- {"user", parse_user},
- {"version", parse_version}, /* GNU */
- {"-version", parse_version}, /* GNU */
- {"xdev", parse_xdev},
- {"xtype", parse_xtype}, /* GNU */
- {0, 0}
+ /* gnulib's stdbool.h might have made true and false into macros,
+ * so we can't leave named 'true' and 'false' tokens, so we have
+ * to expeant the relevant entries longhand.
+ */
+ {ARG_TEST, "false", parse_false, pred_false}, /* GNU */
+ {ARG_TEST, "true", parse_true, pred_true }, /* GNU */
+
+ /* Various other cases that don't fit neatly into our macro scheme. */
+ {ARG_TEST, "help", parse_help, NULL}, /* GNU */
+ {ARG_TEST, "-help", parse_help, NULL}, /* GNU */
+ {ARG_TEST, "version", parse_version, NULL}, /* GNU */
+ {ARG_TEST, "-version", parse_version, NULL}, /* GNU */
+ {0, 0, 0, 0}
};
+
+static const char *first_nonoption_arg = NULL;
+
+
+
+void
+parse_begin_user_args (char **args, int argno, const struct predicate *last, const struct predicate *predicates)
+{
+ (void) args;
+ (void) argno;
+ (void) last;
+ (void) predicates;
+ first_nonoption_arg = NULL;
+}
+
+void
+parse_end_user_args (char **args, int argno, const struct predicate *last, const struct predicate *predicates)
+{
+ /* does nothing */
+ (void) args;
+ (void) argno;
+ (void) last;
+ (void) predicates;
+}
+
+
+
+
/* Return a pointer to the parser function to invoke for predicate
SEARCH_NAME.
Return NULL if SEARCH_NAME is not a valid predicate name. */
-PFB
-find_parser (search_name)
- char *search_name;
+const struct parser_table*
+find_parser (char *search_name)
{
int i;
-
+ const char *original_arg = search_name;
+
if (*search_name == '-')
search_name++;
for (i = 0; parse_table[i].parser_name != 0; i++)
- if (strcmp (parse_table[i].parser_name, search_name) == 0)
- return (parse_table[i].parser_func);
- return (NULL);
+ {
+ if (strcmp (parse_table[i].parser_name, search_name) == 0)
+ {
+ /* If this is an option, but we have already had a
+ * non-option argument, the user may be under the
+ * impression that the behaviour of the option
+ * argument is conditional on some preceding
+ * tests. This might typically be the case with,
+ * for example, -maxdepth.
+ *
+ * The options -daystart and -follow are exempt
+ * from this treatment, since their positioning
+ * in the command line does have an effect on
+ * subsequent tests but not previous ones. That
+ * might be intentional on the part of the user.
+ */
+ if (parse_table[i].type != ARG_POSITIONAL_OPTION)
+ {
+ /* Something other than -follow/-daystart.
+ * If this is an option, check if it followed
+ * a non-option and if so, issue a warning.
+ */
+ if (parse_table[i].type == ARG_OPTION)
+ {
+ if ((first_nonoption_arg != NULL)
+ && options.warnings )
+ {
+ /* option which follows a non-option */
+ error (0, 0,
+ _("warning: you have specified the %s "
+ "option after a non-option argument %s, "
+ "but options are not positional (%s affects "
+ "tests specified before it as well as those "
+ "specified after it). Please specify options "
+ "before other arguments.\n"),
+ original_arg,
+ first_nonoption_arg,
+ original_arg);
+ }
+ }
+ else
+ {
+ /* Not an option or a positional option,
+ * so remember we've seen it in order to
+ * use it in a possible future warning message.
+ */
+ if (first_nonoption_arg == NULL)
+ {
+ first_nonoption_arg = original_arg;
+ }
+ }
+ }
+
+ return &parse_table[i];
+ }
+ }
+ return NULL;
}
/* The parsers are responsible to continue scanning ARGV for
@@ -263,315 +409,342 @@ find_parser (search_name)
The predicate structure is updated with the new information. */
static boolean
-parse_amin (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_amin (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- unsigned long num;
+ uintmax_t num;
enum comparison_type c_type;
+ time_t t;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (!get_num_days (argv[*arg_ptr], &num, &c_type))
- return (false);
- our_pred = insert_primary (pred_amin);
+ return false;
+ t = options.cur_day_start + DAYSECS - num * 60;
+ our_pred = insert_primary (entry);
our_pred->args.info.kind = c_type;
- our_pred->args.info.l_val = cur_day_start + DAYSECS - num * 60;
+ our_pred->args.info.negative = t < 0;
+ our_pred->args.info.l_val = t;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_and (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_and (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = get_new_pred ();
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = get_new_pred (entry);
our_pred->pred_func = pred_and;
#ifdef DEBUG
our_pred->p_name = find_pred_name (pred_and);
#endif /* DEBUG */
our_pred->p_type = BI_OP;
our_pred->p_prec = AND_PREC;
- our_pred->need_stat = false;
- return (true);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_anewer (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_anewer (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
struct stat stat_newer;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- if ((*xstat) (argv[*arg_ptr], &stat_newer))
+ return false;
+ if ((*options.xstat) (argv[*arg_ptr], &stat_newer))
error (1, errno, "%s", argv[*arg_ptr]);
- our_pred = insert_primary (pred_anewer);
+ our_pred = insert_primary (entry);
our_pred->args.time = stat_newer.st_mtime;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_atime (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_atime (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_time (argv, arg_ptr, pred_atime));
+ return insert_time (argv, arg_ptr, entry, pred_atime);
}
boolean
-parse_close (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_closeparen (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = get_new_pred ();
- our_pred->pred_func = pred_close;
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = get_new_pred (entry);
+ our_pred->pred_func = pred_closeparen;
#ifdef DEBUG
- our_pred->p_name = find_pred_name (pred_close);
+ our_pred->p_name = find_pred_name (pred_closeparen);
#endif /* DEBUG */
our_pred->p_type = CLOSE_PAREN;
our_pred->p_prec = NO_PREC;
- our_pred->need_stat = false;
- return (true);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_cmin (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_cmin (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- unsigned long num;
+ uintmax_t num;
enum comparison_type c_type;
+ time_t t;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (!get_num_days (argv[*arg_ptr], &num, &c_type))
- return (false);
- our_pred = insert_primary (pred_cmin);
+ return false;
+ t = options.cur_day_start + DAYSECS - num * 60;
+ our_pred = insert_primary (entry);
our_pred->args.info.kind = c_type;
- our_pred->args.info.l_val = cur_day_start + DAYSECS - num * 60;
+ our_pred->args.info.negative = t < 0;
+ our_pred->args.info.l_val = t;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_cnewer (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_cnewer (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
struct stat stat_newer;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- if ((*xstat) (argv[*arg_ptr], &stat_newer))
+ return false;
+ if ((*options.xstat) (argv[*arg_ptr], &stat_newer))
error (1, errno, "%s", argv[*arg_ptr]);
- our_pred = insert_primary (pred_cnewer);
+ our_pred = insert_primary (entry);
our_pred->args.time = stat_newer.st_mtime;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_comma (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_comma (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = get_new_pred ();
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = get_new_pred (entry);
our_pred->pred_func = pred_comma;
#ifdef DEBUG
our_pred->p_name = find_pred_name (pred_comma);
#endif /* DEBUG */
our_pred->p_type = BI_OP;
our_pred->p_prec = COMMA_PREC;
- our_pred->need_stat = false;
- return (true);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_ctime (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_ctime (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_time (argv, arg_ptr, pred_ctime));
+ return insert_time (argv, arg_ptr, entry, pred_ctime);
}
static boolean
-parse_daystart (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_daystart (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct tm *local;
- if (full_days == false)
+ (void) entry;
+ (void) argv;
+ (void) arg_ptr;
+
+ if (options.full_days == false)
{
- cur_day_start += DAYSECS;
- local = localtime (&cur_day_start);
- cur_day_start -= local->tm_sec + local->tm_min * 60
- + local->tm_hour * 3600;
- full_days = true;
+ options.cur_day_start += DAYSECS;
+ local = localtime (&options.cur_day_start);
+ options.cur_day_start -= (local
+ ? (local->tm_sec + local->tm_min * 60
+ + local->tm_hour * 3600)
+ : options.cur_day_start % DAYSECS);
+ options.full_days = true;
}
- return (true);
+ return true;
}
static boolean
-parse_depth (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_delete (const struct parser_table* entry, char *argv[], int *arg_ptr)
{
- do_dir_first = false;
- return (true);
+ struct predicate *our_pred;
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = insert_primary (entry);
+ our_pred->side_effects = our_pred->no_default_print = true;
+ /* -delete implies -depth */
+ options.do_dir_first = false;
+ return true;
+}
+
+static boolean
+parse_depth (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) entry;
+ (void) argv;
+ (void) arg_ptr;
+
+ options.do_dir_first = false;
+ return true;
}
static boolean
-parse_empty (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_d (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- insert_primary (pred_empty);
- return (true);
+ (void) argv;
+ (void) arg_ptr;
+
+ if (options.warnings)
+ {
+ error (0, 0,
+ _("warning: the -d option is deprecated; please use -depth instead, because the latter is a POSIX-compliant feature."));
+ }
+ return parse_depth(entry, argv, arg_ptr);
+}
+
+static boolean
+parse_empty (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+
+ insert_primary (entry);
+ return true;
}
static boolean
-parse_exec (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_exec (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_exec_ok (pred_exec, argv, arg_ptr));
+ return insert_exec_ok ("-exec", entry, argv, arg_ptr);
}
static boolean
-parse_false (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_execdir (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ return insert_exec_ok ("-execdir", entry, argv, arg_ptr);
+}
+
+static boolean
+parse_false (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
+
+ (void) argv;
+ (void) arg_ptr;
- our_pred = insert_primary (pred_false);
- our_pred->need_stat = false;
- return (true);
+ our_pred = insert_primary (entry);
+ our_pred->need_stat = our_pred->need_type = false;
+ our_pred->side_effects = our_pred->no_default_print = false;
+ return true;
}
static boolean
-parse_fls (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_fls (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_fls);
+ return false;
+ our_pred = insert_primary (entry);
our_pred->args.stream = open_output_file (argv[*arg_ptr]);
- our_pred->side_effects = true;
+ our_pred->side_effects = our_pred->no_default_print = true;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_fprintf (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_fprintf (const struct parser_table* entry, char **argv, int *arg_ptr)
{
FILE *fp;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (argv[*arg_ptr + 1] == NULL)
{
/* Ensure we get "missing arg" message, not "invalid arg". */
(*arg_ptr)++;
- return (false);
+ return false;
}
fp = open_output_file (argv[*arg_ptr]);
(*arg_ptr)++;
- return (insert_fprintf (fp, pred_fprintf, argv, arg_ptr));
+ return insert_fprintf (fp, entry, pred_fprintf, argv, arg_ptr);
}
static boolean
-parse_follow (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_follow (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- dereference = true;
- xstat = stat;
- no_leaf_check = true;
- return (true);
+ (void) entry;
+ (void) argv;
+ (void) arg_ptr;
+
+ set_follow_state(SYMLINK_ALWAYS_DEREF);
+ return true;
}
static boolean
-parse_fprint (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_fprint (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_fprint);
- our_pred->args.stream = open_output_file (argv[*arg_ptr]);
- our_pred->side_effects = true;
- our_pred->need_stat = false;
+ return false;
+ our_pred = insert_primary (entry);
+ our_pred->args.printf_vec.segment = NULL;
+ our_pred->args.printf_vec.stream = open_output_file (argv[*arg_ptr]);
+ our_pred->args.printf_vec.dest_is_tty = stream_is_tty(our_pred->args.printf_vec.stream);
+ our_pred->args.printf_vec.quote_opts = clone_quoting_options (NULL);
+ our_pred->side_effects = our_pred->no_default_print = true;
+ our_pred->need_stat = our_pred->need_type = false;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_fprint0 (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_fprint0 (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_fprint0);
+ return false;
+ our_pred = insert_primary (entry);
our_pred->args.stream = open_output_file (argv[*arg_ptr]);
- our_pred->side_effects = true;
- our_pred->need_stat = false;
+ our_pred->side_effects = our_pred->no_default_print = true;
+ our_pred->need_stat = our_pred->need_type = false;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_fstype (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_fstype (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_fstype);
+ return false;
+ our_pred = insert_primary (entry);
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_gid (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_gid (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_num (argv, arg_ptr, pred_gid));
+ return insert_num (argv, arg_ptr, entry);
}
static boolean
-parse_group (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_group (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct group *cur_gr;
struct predicate *our_pred;
@@ -579,7 +752,7 @@ parse_group (argv, arg_ptr)
int gid_len;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
cur_gr = getgrnam (argv[*arg_ptr]);
endgrent ();
if (cur_gr != NULL)
@@ -588,268 +761,335 @@ parse_group (argv, arg_ptr)
{
gid_len = strspn (argv[*arg_ptr], "0123456789");
if ((gid_len == 0) || (argv[*arg_ptr][gid_len] != '\0'))
- return (false);
+ return false;
gid = atoi (argv[*arg_ptr]);
}
- our_pred = insert_primary (pred_group);
+ our_pred = insert_primary (entry);
our_pred->args.gid = gid;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_help (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_help (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- printf ("\
-Usage: %s [path...] [expression]\n", program_name);
- printf ("\
+ (void) entry;
+ (void) argv;
+ (void) arg_ptr;
+
+ printf (_("\
+Usage: %s [path...] [expression]\n"), program_name);
+ puts (_("\n\
default path is the current directory; default expression is -print\n\
-expression may consist of:\n\
+expression may consist of: operators, options, tests, and actions:\n"));
+ puts (_("\
operators (decreasing precedence; -and is implicit where no others are given):\n\
- ( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2\n");
- printf ("\
- EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2\n\
-options (always true): -daystart -depth -follow --help\n\
- -maxdepth LEVELS -mindepth LEVELS -mount -noleaf --version -xdev\n\
-tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N\n");
- printf ("\
+ ( EXPR ) ! EXPR -not EXPR EXPR1 -a EXPR2 EXPR1 -and EXPR2\n\
+ EXPR1 -o EXPR2 EXPR1 -or EXPR2 EXPR1 , EXPR2\n"));
+ puts (_("\
+positional options (always true): -daystart -follow -regextype\n\n\
+normal options (always true, specified before other expressions):\n\
+ -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf\n\
+ --version -xdev -ignore_readdir_race -noignore_readdir_race\n"));
+ puts (_("\
+tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N\n\
-cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME\n\
- -ilname PATTERN -iname PATTERN -inum N -ipath PATTERN -iregex PATTERN\n\
- -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE\n");
- printf ("\
+ -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN\n\
+ -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE"));
+ puts (_("\
-nouser -nogroup -path PATTERN -perm [+-]MODE -regex PATTERN\n\
- -size N[bckw] -true -type [bcdpfls] -uid N -used N -user NAME\n\
- -xtype [bcdpfls]\n");
- printf ("\
-actions: -exec COMMAND ; -fprint FILE -fprint0 FILE -fprintf FILE FORMAT\n\
- -ok COMMAND ; -print -print0 -printf FORMAT -prune -ls\n");
+ -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N\n\
+ -used N -user NAME -xtype [bcdpfls]\n"));
+ puts (_("\
+actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print \n\
+ -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit\n\
+ -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;\n\
+ -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;\n\
+"));
+ puts (_("Report (and track progress on fixing) bugs via the findutils bug-reporting\n\
+page at http://savannah.gnu.org/ or, if you have no web access, by sending\n\
+email to ."));
exit (0);
}
static boolean
-parse_ilname (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_ilname (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_ilname);
+ return false;
+ our_pred = insert_primary (entry);
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
+
+/* sanity check the fnmatch() function to make sure
+ * it really is the GNU version.
+ */
+static boolean
+fnmatch_sanitycheck(void)
+{
+ /* fprintf(stderr, "Performing find sanity check..."); */
+ if (0 != fnmatch("foo", "foo", 0)
+ || 0 == fnmatch("Foo", "foo", 0)
+ || 0 != fnmatch("Foo", "foo", FNM_CASEFOLD))
+ {
+ error (1, 0, _("sanity check of the fnmatch() library function failed."));
+ /* fprintf(stderr, "FAILED\n"); */
+ return false;
+ }
+
+ /* fprintf(stderr, "OK\n"); */
+ return true;
+}
+
+
static boolean
-parse_iname (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+check_name_arg(const char *pred, const char *arg)
+{
+ if (options.warnings && strchr(arg, '/'))
+ {
+ error(0, 0,_("warning: Unix filenames usually don't contain slashes (though pathnames do). That means that '%s %s' will probably evaluate to false all the time on this system. You might find the '-wholename' test more useful, or perhaps '-samefile'. Alternatively, if you are using GNU grep, you could use 'find ... -print0 | grep -FzZ %s'."),
+ pred, arg, arg);
+ }
+ return true; /* allow it anyway */
+}
+
+
+
+static boolean
+parse_iname (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_iname);
- our_pred->need_stat = false;
+ return false;
+ if (!check_name_arg("-iname", argv[*arg_ptr]))
+ return false;
+
+ fnmatch_sanitycheck();
+
+ our_pred = insert_primary (entry);
+ our_pred->need_stat = our_pred->need_type = false;
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_inum (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_inum (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_num (argv, arg_ptr, pred_inum));
+ return insert_num (argv, arg_ptr, entry);
+}
+
+/* -ipath is deprecated (at RMS's request) in favour of
+ * -iwholename. See the node "GNU Manuals" in standards.texi
+ * for the rationale for this (basically, GNU prefers the use
+ * of the phrase "file name" to "path name"
+ */
+static boolean
+parse_ipath (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ error (0, 0,
+ _("warning: the predicate -ipath is deprecated; please use -iwholename instead."));
+
+ return parse_iwholename(entry, argv, arg_ptr);
}
static boolean
-parse_ipath (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_iwholename (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_ipath);
- our_pred->need_stat = false;
+ return false;
+
+ fnmatch_sanitycheck();
+
+ our_pred = insert_primary_withpred (entry, pred_ipath);
+ our_pred->need_stat = our_pred->need_type = false;
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_iregex (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_iregex (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return insert_regex (argv, arg_ptr, true);
+ return insert_regex (argv, arg_ptr, entry, RE_ICASE|options.regex_options);
}
static boolean
-parse_links (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_links (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_num (argv, arg_ptr, pred_links));
+ return insert_num (argv, arg_ptr, entry);
}
static boolean
-parse_lname (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_lname (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
+ (void) argv;
+ (void) arg_ptr;
+
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_lname);
+ return false;
+
+ fnmatch_sanitycheck();
+
+ our_pred = insert_primary (entry);
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_ls (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_ls (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = insert_primary (pred_ls);
- our_pred->side_effects = true;
- return (true);
+ (void) &argv;
+ (void) &arg_ptr;
+
+ our_pred = insert_primary (entry);
+ our_pred->side_effects = our_pred->no_default_print = true;
+ return true;
}
static boolean
-parse_maxdepth (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_maxdepth (const struct parser_table* entry, char **argv, int *arg_ptr)
{
int depth_len;
+ (void) entry;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
depth_len = strspn (argv[*arg_ptr], "0123456789");
if ((depth_len == 0) || (argv[*arg_ptr][depth_len] != '\0'))
- return (false);
- maxdepth = atoi (argv[*arg_ptr]);
- if (maxdepth < 0)
- return (false);
+ return false;
+ options.maxdepth = atoi (argv[*arg_ptr]);
+ if (options.maxdepth < 0)
+ return false;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_mindepth (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_mindepth (const struct parser_table* entry, char **argv, int *arg_ptr)
{
int depth_len;
+ (void) entry;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
depth_len = strspn (argv[*arg_ptr], "0123456789");
if ((depth_len == 0) || (argv[*arg_ptr][depth_len] != '\0'))
- return (false);
- mindepth = atoi (argv[*arg_ptr]);
- if (mindepth < 0)
- return (false);
+ return false;
+ options.mindepth = atoi (argv[*arg_ptr]);
+ if (options.mindepth < 0)
+ return false;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_mmin (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_mmin (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- unsigned long num;
+ uintmax_t num;
enum comparison_type c_type;
+ time_t t;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (!get_num_days (argv[*arg_ptr], &num, &c_type))
- return (false);
- our_pred = insert_primary (pred_mmin);
+ return false;
+ t = options.cur_day_start + DAYSECS - num * 60;
+ our_pred = insert_primary (entry);
our_pred->args.info.kind = c_type;
- our_pred->args.info.l_val = cur_day_start + DAYSECS - num * 60;
+ our_pred->args.info.negative = t < 0;
+ our_pred->args.info.l_val = t;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_mtime (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_mtime (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_time (argv, arg_ptr, pred_mtime));
+ return insert_time (argv, arg_ptr, entry, pred_mtime);
}
static boolean
-parse_name (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_name (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
+ (void) argv;
+ (void) arg_ptr;
+
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_name);
- our_pred->need_stat = false;
+ return false;
+ if (!check_name_arg("-name", argv[*arg_ptr]))
+ return false;
+ fnmatch_sanitycheck();
+
+ our_pred = insert_primary (entry);
+ our_pred->need_stat = our_pred->need_type = false;
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_negate (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_negate (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = get_new_pred_chk_op ();
+ (void) &argv;
+ (void) &arg_ptr;
+
+ our_pred = get_new_pred_chk_op (entry);
our_pred->pred_func = pred_negate;
#ifdef DEBUG
our_pred->p_name = find_pred_name (pred_negate);
#endif /* DEBUG */
our_pred->p_type = UNI_OP;
our_pred->p_prec = NEGATE_PREC;
- our_pred->need_stat = false;
- return (true);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_newer (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_newer (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
struct stat stat_newer;
+ (void) argv;
+ (void) arg_ptr;
+
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- if ((*xstat) (argv[*arg_ptr], &stat_newer))
+ return false;
+ if ((*options.xstat) (argv[*arg_ptr], &stat_newer))
error (1, errno, "%s", argv[*arg_ptr]);
- our_pred = insert_primary (pred_newer);
+ our_pred = insert_primary (entry);
our_pred->args.time = stat_newer.st_mtime;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_noleaf (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_noleaf (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- no_leaf_check = true;
+ (void) &argv;
+ (void) &arg_ptr;
+ (void) entry;
+
+ options.no_leaf_check = true;
return true;
}
@@ -870,13 +1110,14 @@ unsigned gid_allocated;
#endif
static boolean
-parse_nogroup (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_nogroup (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = insert_primary (pred_nogroup);
+ (void) &argv;
+ (void) &arg_ptr;
+
+ our_pred = insert_primary (entry);
#ifdef CACHE_IDS
if (gid_unused == NULL)
{
@@ -901,17 +1142,18 @@ parse_nogroup (argv, arg_ptr)
endgrent ();
}
#endif
- return (true);
+ return true;
}
static boolean
-parse_nouser (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_nouser (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
+ (void) argv;
+ (void) arg_ptr;
+
- our_pred = insert_primary (pred_nouser);
+ our_pred = insert_primary (entry);
#ifdef CACHE_IDS
if (uid_unused == NULL)
{
@@ -936,198 +1178,319 @@ parse_nouser (argv, arg_ptr)
endpwent ();
}
#endif
- return (true);
+ return true;
}
static boolean
-parse_ok (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_nowarn (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_exec_ok (pred_ok, argv, arg_ptr));
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+
+ options.warnings = false;
+ return true;;
+}
+
+static boolean
+parse_ok (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ return insert_exec_ok ("-ok", entry, argv, arg_ptr);
+}
+
+static boolean
+parse_okdir (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ return insert_exec_ok ("-okdir", entry, argv, arg_ptr);
}
boolean
-parse_open (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_openparen (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = get_new_pred_chk_op ();
- our_pred->pred_func = pred_open;
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = get_new_pred_chk_op (entry);
+ our_pred->pred_func = pred_openparen;
#ifdef DEBUG
- our_pred->p_name = find_pred_name (pred_open);
+ our_pred->p_name = find_pred_name (pred_openparen);
#endif /* DEBUG */
our_pred->p_type = OPEN_PAREN;
our_pred->p_prec = NO_PREC;
- our_pred->need_stat = false;
- return (true);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_or (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_or (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = get_new_pred ();
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = get_new_pred (entry);
our_pred->pred_func = pred_or;
#ifdef DEBUG
our_pred->p_name = find_pred_name (pred_or);
#endif /* DEBUG */
our_pred->p_type = BI_OP;
our_pred->p_prec = OR_PREC;
- our_pred->need_stat = false;
- return (true);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
+}
+
+/* -path is deprecated (at RMS's request) in favour of
+ * -iwholename. See the node "GNU Manuals" in standards.texi
+ * for the rationale for this (basically, GNU prefers the use
+ * of the phrase "file name" to "path name".
+ *
+ * We do not issue a warning that this usage is deprecated
+ * since HPUX find supports this predicate also.
+ */
+static boolean
+parse_path (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ return parse_wholename(entry, argv, arg_ptr);
}
static boolean
-parse_path (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_wholename (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_path);
- our_pred->need_stat = false;
+ return false;
+ our_pred = insert_primary_withpred (entry, pred_path);
+ our_pred->need_stat = our_pred->need_type = false;
our_pred->args.str = argv[*arg_ptr];
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_perm (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_perm (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- unsigned long perm_val;
+ mode_t perm_val[2];
int mode_start = 0;
- struct mode_change *change;
+ boolean havekind = false;
+ enum permissions_type kind = PERM_EXACT;
+ struct mode_change *change = NULL;
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
switch (argv[*arg_ptr][0])
{
case '-':
- case '+':
mode_start = 1;
+ kind = PERM_AT_LEAST;
+ havekind = true;
break;
+
+ case '+':
+ change = mode_compile (argv[*arg_ptr]);
+ if (NULL == change)
+ {
+ /* Most likely the caller is an old script that is still
+ * using the obsolete GNU syntax '-perm +MODE'. This old
+ * syntax was withdrawn in favor of '-perm /MODE' because
+ * it is incompatible with POSIX in some cases, but we
+ * still support uses of it that are not incompatible with
+ * POSIX.
+ */
+ mode_start = 1;
+ kind = PERM_ANY;
+ }
+ else
+ {
+ /* This is a POSIX-compatible usage */
+ mode_start = 0;
+ kind = PERM_EXACT;
+ }
+ havekind = true;
+ break;
+
+ case '/': /* GNU extension */
+ mode_start = 1;
+ kind = PERM_ANY;
+ havekind = true;
+ break;
+
default:
- /* empty */
+ /* For example, '-perm 0644', which is valid and matches
+ * only files whose mode is exactly 0644.
+ *
+ * We do nothing here, because mode_start and kind are already
+ * correctly set.
+ */
break;
}
- change = mode_compile (argv[*arg_ptr] + mode_start, MODE_MASK_PLUS);
- if (change == MODE_INVALID)
- error (1, 0, "invalid mode `%s'", argv[*arg_ptr]);
- else if (change == MODE_MEMORY_EXHAUSTED)
- error (1, 0, "virtual memory exhausted");
- perm_val = mode_adjust (0, change);
- mode_free (change);
-
- our_pred = insert_primary (pred_perm);
-
- switch (argv[*arg_ptr][0])
+ if (NULL == change)
{
- case '-':
- /* Set magic flag to indicate true if at least the given bits are set. */
- our_pred->args.perm = (perm_val & 07777) | 010000;
- break;
- case '+':
- /* Set magic flag to indicate true if any of the given bits are set. */
- our_pred->args.perm = (perm_val & 07777) | 020000;
- break;
- default:
- /* True if exactly the given bits are set. */
- our_pred->args.perm = (perm_val & 07777);
- break;
+ change = mode_compile (argv[*arg_ptr] + mode_start);
+ if (NULL == change)
+ error (1, 0, _("invalid mode `%s'"), argv[*arg_ptr]);
}
+ perm_val[0] = mode_adjust (0, false, 0, change, NULL);
+ perm_val[1] = mode_adjust (0, true, 0, change, NULL);
+ free (change);
+
+ our_pred = insert_primary (entry);
+
+ if (havekind)
+ {
+ our_pred->args.perm.kind = kind;
+ }
+ else
+ {
+
+ switch (argv[*arg_ptr][0])
+ {
+ case '-':
+ our_pred->args.perm.kind = PERM_AT_LEAST;
+ break;
+ case '+':
+ our_pred->args.perm.kind = PERM_ANY;
+ break;
+ default:
+ our_pred->args.perm.kind = PERM_EXACT;
+ break;
+ }
+ }
+
+ if (('/' == argv[*arg_ptr][0]) && (0 == perm_val[0]) && (0 == perm_val[1]))
+ {
+ /* The meaning of -perm /000 will change in the future.
+ * It currently matches no files, but like -perm -000 it
+ * should match all files.
+ */
+ error (0, 0,
+ _("warning: you have specified a mode pattern %s which is "
+ "equivalent to 000. The meaning of -perm /000 will soon be "
+ "changed to be consistent with -perm -000; that is, at the "
+ "moment it matches no files but it will soon be changed to "
+ "match all files."),
+ argv[*arg_ptr]);
+ }
+
+ memcpy (our_pred->args.perm.val, perm_val, sizeof perm_val);
(*arg_ptr)++;
- return (true);
+ return true;
}
boolean
-parse_print (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_print (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = insert_primary (pred_print);
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = insert_primary (entry);
/* -print has the side effect of printing. This prevents us
from doing undesired multiple printing when the user has
already specified -print. */
- our_pred->side_effects = true;
- our_pred->need_stat = false;
- return (true);
+ our_pred->side_effects = our_pred->no_default_print = true;
+ our_pred->need_stat = our_pred->need_type = false;
+ our_pred->args.printf_vec.segment = NULL;
+ our_pred->args.printf_vec.stream = stdout;
+ our_pred->args.printf_vec.dest_is_tty = stream_is_tty(stdout);
+ our_pred->args.printf_vec.quote_opts = clone_quoting_options (NULL);
+
+ return true;
}
static boolean
-parse_print0 (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_print0 (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = insert_primary (pred_print0);
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = insert_primary (entry);
/* -print0 has the side effect of printing. This prevents us
from doing undesired multiple printing when the user has
already specified -print0. */
- our_pred->side_effects = true;
- our_pred->need_stat = false;
- return (true);
+ our_pred->side_effects = our_pred->no_default_print = true;
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_printf (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_printf (const struct parser_table* entry, char **argv, int *arg_ptr)
{
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- return (insert_fprintf (stdout, pred_fprintf, argv, arg_ptr));
+ return false;
+ return insert_fprintf (stdout, entry, pred_fprintf, argv, arg_ptr);
}
static boolean
-parse_prune (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_prune (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = insert_primary (pred_prune);
- our_pred->need_stat = false;
- return (true);
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = insert_primary (entry);
+ our_pred->need_stat = our_pred->need_type = false;
+ /* -prune has a side effect that it does not descend into
+ the current directory. */
+ our_pred->side_effects = true;
+ our_pred->no_default_print = false;
+ return true;
}
-static boolean
-parse_regex (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+static boolean
+parse_quit (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return insert_regex (argv, arg_ptr, false);
+ struct predicate *our_pred = insert_primary (entry);
+ (void) argv;
+ (void) arg_ptr;
+ our_pred->need_stat = our_pred->need_type = false;
+ our_pred->side_effects = true; /* Exiting is a side effect... */
+ our_pred->no_default_print = false; /* Don't inhibit the default print, though. */
+ return true;
+}
+
+
+static boolean
+parse_regextype (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ if ((argv == NULL) || (argv[*arg_ptr] == NULL))
+ return false;
+
+ /* collect the regex type name */
+ options.regex_options = get_regex_type(argv[*arg_ptr]);
+ (*arg_ptr)++;
+
+ return true;
+}
+
+
+static boolean
+parse_regex (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ return insert_regex (argv, arg_ptr, entry, options.regex_options);
}
static boolean
-insert_regex (argv, arg_ptr, ignore_case)
- char *argv[];
- int *arg_ptr;
- boolean ignore_case;
+insert_regex (char **argv, int *arg_ptr, const struct parser_table *entry, int regex_options)
{
struct predicate *our_pred;
struct re_pattern_buffer *re;
const char *error_message;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
- our_pred = insert_primary (pred_regex);
- our_pred->need_stat = false;
+ return false;
+ our_pred = insert_primary_withpred (entry, pred_regex);
+ our_pred->need_stat = our_pred->need_type = false;
re = (struct re_pattern_buffer *)
xmalloc (sizeof (struct re_pattern_buffer));
our_pred->args.regex = re;
@@ -1135,42 +1498,32 @@ insert_regex (argv, arg_ptr, ignore_case)
re->buffer = (unsigned char *) xmalloc (re->allocated);
re->fastmap = NULL;
- if (ignore_case)
- {
- unsigned i;
-
- re->translate = xmalloc (256);
- /* Map uppercase characters to corresponding lowercase ones. */
- for (i = 0; i < 256; i++)
- re->translate[i] = ISUPPER (i) ? tolower (i) : i;
- }
- else
- re->translate = NULL;
-
+ re_set_syntax(regex_options);
+ re->syntax = regex_options;
+ re->translate = NULL;
+
error_message = re_compile_pattern (argv[*arg_ptr], strlen (argv[*arg_ptr]),
re);
if (error_message)
error (1, 0, "%s", error_message);
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_size (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_size (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- unsigned long num;
+ uintmax_t num;
enum comparison_type c_type;
int blksize = 512;
int len;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
len = strlen (argv[*arg_ptr]);
if (len == 0)
- error (1, 0, "invalid null argument to -size");
+ error (1, 0, _("invalid null argument to -size"));
switch (argv[*arg_ptr][len - 1])
{
case 'b':
@@ -1188,6 +1541,16 @@ parse_size (argv, arg_ptr)
argv[*arg_ptr][len - 1] = '\0';
break;
+ case 'M': /* Megabytes */
+ blksize = 1024*1024;
+ argv[*arg_ptr][len - 1] = '\0';
+ break;
+
+ case 'G': /* Gigabytes */
+ blksize = 1024*1024*1024;
+ argv[*arg_ptr][len - 1] = '\0';
+ break;
+
case 'w':
blksize = 2;
argv[*arg_ptr][len - 1] = '\0';
@@ -1206,71 +1569,88 @@ parse_size (argv, arg_ptr)
break;
default:
- error (1, 0, "invalid -size type `%c'", argv[*arg_ptr][len - 1]);
+ error (1, 0, _("invalid -size type `%c'"), argv[*arg_ptr][len - 1]);
}
if (!get_num (argv[*arg_ptr], &num, &c_type))
- return (false);
- our_pred = insert_primary (pred_size);
+ return false;
+ our_pred = insert_primary (entry);
our_pred->args.size.kind = c_type;
our_pred->args.size.blocksize = blksize;
our_pred->args.size.size = num;
(*arg_ptr)++;
- return (true);
+ return true;
}
+
static boolean
-parse_true (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_samefile (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ struct predicate *our_pred;
+ struct stat st;
+
+ if ((argv == NULL) || (argv[*arg_ptr] == NULL))
+ return false;
+ if ((*options.xstat) (argv[*arg_ptr], &st))
+ error (1, errno, "%s", argv[*arg_ptr]);
+
+ our_pred = insert_primary (entry);
+ our_pred->args.fileid.ino = st.st_ino;
+ our_pred->args.fileid.dev = st.st_dev;
+ our_pred->need_type = false;
+ our_pred->need_stat = true;
+ (*arg_ptr)++;
+ return true;
+}
+
+
+static boolean
+parse_true (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- our_pred = insert_primary (pred_true);
- our_pred->need_stat = false;
- return (true);
+ (void) argv;
+ (void) arg_ptr;
+
+ our_pred = insert_primary (entry);
+ our_pred->need_stat = our_pred->need_type = false;
+ return true;
}
static boolean
-parse_type (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_type (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return insert_type (argv, arg_ptr, pred_type);
+ return insert_type (argv, arg_ptr, entry, pred_type);
}
static boolean
-parse_uid (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_uid (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return (insert_num (argv, arg_ptr, pred_uid));
+ return insert_num (argv, arg_ptr, entry);
}
static boolean
-parse_used (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
-
+parse_used (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct predicate *our_pred;
- unsigned long num_days;
+ uintmax_t num_days;
enum comparison_type c_type;
+ time_t t;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (!get_num (argv[*arg_ptr], &num_days, &c_type))
- return (false);
- our_pred = insert_primary (pred_used);
+ return false;
+ t = num_days * DAYSECS;
+ our_pred = insert_primary (entry);
our_pred->args.info.kind = c_type;
- our_pred->args.info.l_val = num_days * DAYSECS;
+ our_pred->args.info.negative = t < 0;
+ our_pred->args.info.l_val = t;
(*arg_ptr)++;
- return (true);
+ return true;
}
static boolean
-parse_user (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_user (const struct parser_table* entry, char **argv, int *arg_ptr)
{
struct passwd *cur_pwd;
struct predicate *our_pred;
@@ -1278,7 +1658,7 @@ parse_user (argv, arg_ptr)
int uid_len;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
cur_pwd = getpwnam (argv[*arg_ptr]);
endpwent ();
if (cur_pwd != NULL)
@@ -1287,56 +1667,123 @@ parse_user (argv, arg_ptr)
{
uid_len = strspn (argv[*arg_ptr], "0123456789");
if ((uid_len == 0) || (argv[*arg_ptr][uid_len] != '\0'))
- return (false);
+ return false;
uid = atoi (argv[*arg_ptr]);
}
- our_pred = insert_primary (pred_user);
+ our_pred = insert_primary (entry);
our_pred->args.uid = uid;
(*arg_ptr)++;
- return (true);
-}
-
-static boolean
-parse_version (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
-{
- extern char *version_string;
-
- fflush (stderr);
- printf ("GNU find version %s\n", version_string);
- exit (0);
-}
-
-static boolean
-parse_xdev (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
-{
- stay_on_filesystem = true;
return true;
}
static boolean
-parse_xtype (argv, arg_ptr)
- char *argv[];
- int *arg_ptr;
+parse_version (const struct parser_table* entry, char **argv, int *arg_ptr)
{
- return insert_type (argv, arg_ptr, pred_xtype);
+ extern char *version_string;
+ int features = 0;
+
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+
+ fflush (stderr);
+ printf (_("GNU find version %s\n"), version_string);
+ printf (_("Built using GNU gnulib version %s\n"), gnulib_version);
+ printf (_("Features enabled: "));
+
+#if CACHE_IDS
+ printf("CACHE_IDS ");
+ ++features;
+#endif
+#if DEBUG
+ printf("DEBUG ");
+ ++features;
+#endif
+#if DEBUG_STAT
+ printf("DEBUG_STAT ");
+ ++features;
+#endif
+#if defined(USE_STRUCT_DIRENT_D_TYPE) && defined(HAVE_STRUCT_DIRENT_D_TYPE)
+ printf("D_TYPE ");
+ ++features;
+#endif
+#if defined(O_NOFOLLOW)
+ printf("O_NOFOLLOW(%s) ",
+ (options.open_nofollow_available ? "enabled" : "disabled"));
+ ++features;
+#endif
+#if defined(LEAF_OPTIMISATION)
+ printf("LEAF_OPTIMISATION ");
+ ++features;
+#endif
+ if (0 == features)
+ {
+ /* For the moment, leave this as English in case someone wants
+ to parse these strings. */
+ printf("none");
+ }
+ printf("\n");
+
+ exit (0);
+}
+
+static boolean
+parse_xdev (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+ options.stay_on_filesystem = true;
+ return true;
+}
+
+static boolean
+parse_ignore_race (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+ options.ignore_readdir_race = true;
+ return true;
+}
+
+static boolean
+parse_noignore_race (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+ options.ignore_readdir_race = false;
+ return true;
+}
+
+static boolean
+parse_warn (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+ (void) entry;
+ options.warnings = true;
+ return true;
+}
+
+static boolean
+parse_xtype (const struct parser_table* entry, char **argv, int *arg_ptr)
+{
+ (void) argv;
+ (void) arg_ptr;
+ return insert_type (argv, arg_ptr, entry, pred_xtype);
}
static boolean
-insert_type (argv, arg_ptr, which_pred)
- char *argv[];
- int *arg_ptr;
- boolean (*which_pred) ();
+insert_type (char **argv, int *arg_ptr, const struct parser_table *entry, PRED_FUNC which_pred)
{
- unsigned long type_cell;
+ mode_t type_cell;
struct predicate *our_pred;
if ((argv == NULL) || (argv[*arg_ptr] == NULL)
|| (strlen (argv[*arg_ptr]) != 1))
- return (false);
+ return false;
switch (argv[*arg_ptr][0])
{
case 'b': /* block special */
@@ -1365,26 +1812,63 @@ insert_type (argv, arg_ptr, which_pred)
case 's': /* socket */
type_cell = S_IFSOCK;
break;
+#endif
+#ifdef S_IFDOOR
+ case 'D': /* Solaris door */
+ type_cell = S_IFDOOR;
+ break;
#endif
default: /* None of the above ... nuke 'em. */
- return (false);
+ return false;
+ }
+ our_pred = insert_primary_withpred (entry, which_pred);
+
+ /* Figure out if we will need to stat the file, because if we don't
+ * need to follow symlinks, we can avoid a stat call by using
+ * struct dirent.d_type.
+ */
+ if (which_pred == pred_xtype)
+ {
+ our_pred->need_stat = true;
+ our_pred->need_type = false;
+ }
+ else
+ {
+ our_pred->need_stat = false; /* struct dirent is enough */
+ our_pred->need_type = true;
}
- our_pred = insert_primary (which_pred);
our_pred->args.type = type_cell;
(*arg_ptr)++; /* Move on to next argument. */
- return (true);
+ return true;
}
+
+/* Return true if the file accessed via FP is a terminal.
+ */
+static boolean
+stream_is_tty(FILE *fp)
+{
+ int fd = fileno(fp);
+ if (-1 == fd)
+ {
+ return false; /* not a valid stream */
+ }
+ else
+ {
+ return isatty(fd) ? true : false;
+ }
+
+}
+
+
+
/* If true, we've determined that the current fprintf predicate
uses stat information. */
static boolean fprintf_stat_needed;
+/* XXX: do we need to pass FUNC to this function? */
static boolean
-insert_fprintf (fp, func, argv, arg_ptr)
- FILE *fp;
- boolean (*func) ();
- char *argv[];
- int *arg_ptr;
+insert_fprintf (FILE *fp, const struct parser_table *entry, PRED_FUNC func, char **argv, int *arg_ptr)
{
char *format; /* Beginning of unprocessed format string. */
register char *scan; /* Current address in scanning `format'. */
@@ -1395,9 +1879,11 @@ insert_fprintf (fp, func, argv, arg_ptr)
format = argv[(*arg_ptr)++];
fprintf_stat_needed = false; /* Might be overridden later. */
- our_pred = insert_primary (func);
- our_pred->side_effects = true;
+ our_pred = insert_primary_withpred (entry, func);
+ our_pred->side_effects = our_pred->no_default_print = true;
our_pred->args.printf_vec.stream = fp;
+ our_pred->args.printf_vec.dest_is_tty = stream_is_tty(fp);
+ our_pred->args.printf_vec.quote_opts = clone_quoting_options (NULL);
segmentp = &our_pred->args.printf_vec.segment;
*segmentp = NULL;
@@ -1429,7 +1915,7 @@ insert_fprintf (fp, func, argv, arg_ptr)
case 'c':
make_segment (segmentp, format, scan - format, KIND_STOP);
our_pred->need_stat = fprintf_stat_needed;
- return (true);
+ return true;
case 'f':
*scan = '\f';
break;
@@ -1449,7 +1935,8 @@ insert_fprintf (fp, func, argv, arg_ptr)
/* *scan = '\\'; * it already is */
break;
default:
- error (0, 0, "warning: unrecognized escape `\\%c'", *scan2);
+ error (0, 0,
+ _("warning: unrecognized escape `\\%c'"), *scan2);
scan++;
continue;
}
@@ -1461,7 +1948,12 @@ insert_fprintf (fp, func, argv, arg_ptr)
}
else if (*scan == '%')
{
- if (scan[1] == '%')
+ if (scan[1] == 0)
+ {
+ /* Trailing %. We don't like those. */
+ error (1, 0, _("error: %s at end of format string"), scan);
+ }
+ else if (scan[1] == '%')
{
segmentp = make_segment (segmentp, format, scan - format + 1,
KIND_PLAIN);
@@ -1477,7 +1969,7 @@ insert_fprintf (fp, func, argv, arg_ptr)
if (*scan2 == '.')
for (scan2++; ISDIGIT (*scan2); scan2++)
/* Do nothing. */ ;
- if (strchr ("abcdfFgGhHiklmnpPstuU", *scan2))
+ if (strchr ("abcdDfFgGhHiklmMnpPstuUyY", *scan2))
{
segmentp = make_segment (segmentp, format, scan2 - format,
(int) *scan2);
@@ -1495,7 +1987,7 @@ insert_fprintf (fp, func, argv, arg_ptr)
else
{
/* An unrecognized % escape. Print the char after the %. */
- error (0, 0, "warning: unrecognized format directive `%%%c'",
+ error (0, 0, _("warning: unrecognized format directive `%%%c'"),
*scan2);
segmentp = make_segment (segmentp, format, scan - format,
KIND_PLAIN);
@@ -1507,8 +1999,9 @@ insert_fprintf (fp, func, argv, arg_ptr)
if (scan > format)
make_segment (segmentp, format, scan - format, KIND_PLAIN);
+ our_pred->need_type = false;
our_pred->need_stat = fprintf_stat_needed;
- return (true);
+ return true;
}
/* Create a new fprintf segment in *SEGMENT, with type KIND,
@@ -1516,10 +2009,7 @@ insert_fprintf (fp, func, argv, arg_ptr)
Return the address of the `next' pointer of the new segment. */
static struct segment **
-make_segment (segment, format, len, kind)
- struct segment **segment;
- char *format;
- int len, kind;
+make_segment (struct segment **segment, char *format, int len, int kind)
{
char *fmt;
@@ -1529,7 +2019,7 @@ make_segment (segment, format, len, kind)
(*segment)->next = NULL;
(*segment)->text_len = len;
- fmt = (*segment)->text = xmalloc (len + 3); /* room for "ld\0" */
+ fmt = (*segment)->text = xmalloc (len + sizeof "d");
strncpy (fmt, format, len);
fmt += len;
@@ -1540,15 +2030,20 @@ make_segment (segment, format, len, kind)
break;
case 'a': /* atime in `ctime' format */
+ case 'A': /* atime in user-specified strftime format */
case 'c': /* ctime in `ctime' format */
+ case 'C': /* ctime in user-specified strftime format */
case 'F': /* filesystem type */
case 'g': /* group name */
+ case 'i': /* inode number */
case 'l': /* object of symlink */
+ case 'M': /* mode in `ls -l' format (eg., "drwxr-xr-x") */
+ case 's': /* size in bytes */
case 't': /* mtime in `ctime' format */
- case 'u': /* user name */
- case 'A': /* atime in user-specified strftime format */
- case 'C': /* ctime in user-specified strftime format */
case 'T': /* mtime in user-specified strftime format */
+ case 'u': /* user name */
+ case 'y': /* file type */
+ case 'Y': /* symlink pointed file type */
fprintf_stat_needed = true;
/* FALLTHROUGH */
case 'f': /* basename of path */
@@ -1559,25 +2054,23 @@ make_segment (segment, format, len, kind)
*fmt++ = 's';
break;
- case 'b': /* size in 512-byte blocks */
- case 'k': /* size in 1K blocks */
- case 's': /* size in bytes */
- *fmt++ = 'l';
- /*FALLTHROUGH*/
- case 'n': /* number of links */
- fprintf_stat_needed = true;
- /* FALLTHROUGH */
- case 'd': /* depth in search tree (0 = ARGV element) */
- *fmt++ = 'd';
- break;
-
- case 'i': /* inode number */
- *fmt++ = 'l';
- /*FALLTHROUGH*/
+ /* Numeric items that one might expect to honour
+ * #, 0, + flags but which do not.
+ */
case 'G': /* GID number */
case 'U': /* UID number */
- *fmt++ = 'u';
+ case 'b': /* size in 512-byte blocks */
+ case 'D': /* Filesystem device on which the file exits */
+ case 'k': /* size in 1K blocks */
+ case 'n': /* number of links */
fprintf_stat_needed = true;
+ *fmt++ = 's';
+ break;
+
+ /* Numeric items that DO honour #, 0, + flags.
+ */
+ case 'd': /* depth in search tree (0 = ARGV element) */
+ *fmt++ = 'd';
break;
case 'm': /* mode as octal number (perms only) */
@@ -1587,14 +2080,225 @@ make_segment (segment, format, len, kind)
}
*fmt = '\0';
- return (&(*segment)->next);
+ return &(*segment)->next;
+}
+
+static void
+check_path_safety(const char *action)
+{
+ const char *path = getenv("PATH");
+ char *s;
+ s = next_element(path, 1);
+ while ((s = next_element ((char *) NULL, 1)) != NULL)
+ {
+ if (0 == strcmp(s, "."))
+ {
+ error(1, 0, _("The current directory is included in the PATH environment variable, which is insecure in combination with the %s action of find. Please remove the current directory from your $PATH (that is, remove \".\" or leading or trailing colons)"),
+ action);
+ }
+ }
}
+
+/* handles both exec and ok predicate */
+#if defined(NEW_EXEC)
+/* handles both exec and ok predicate */
static boolean
-insert_exec_ok (func, argv, arg_ptr)
- boolean (*func) ();
- char *argv[];
- int *arg_ptr;
+new_insert_exec_ok (const char *action,
+ const struct parser_table *entry,
+ char **argv,
+ int *arg_ptr)
+{
+ int start, end; /* Indexes in ARGV of start & end of cmd. */
+ int i; /* Index into cmd args */
+ int saw_braces; /* True if previous arg was '{}'. */
+ boolean allow_plus; /* True if + is a valid terminator */
+ int brace_count; /* Number of instances of {}. */
+ PRED_FUNC func = entry->pred_func;
+ enum BC_INIT_STATUS bcstatus;
+
+ struct predicate *our_pred;
+ struct exec_val *execp; /* Pointer for efficiency. */
+
+ if ((argv == NULL) || (argv[*arg_ptr] == NULL))
+ return false;
+
+ our_pred = insert_primary_withpred (entry, func);
+ our_pred->side_effects = our_pred->no_default_print = true;
+ execp = &our_pred->args.exec_vec;
+
+ if ((func != pred_okdir) && (func != pred_ok))
+ {
+ allow_plus = true;
+ execp->close_stdin = false;
+ }
+ else
+ {
+ allow_plus = false;
+ /* If find reads stdin (i.e. for -ok and similar), close stdin
+ * in the child to prevent some script from consiming the output
+ * intended for find.
+ */
+ execp->close_stdin = true;
+ }
+
+
+ if ((func == pred_execdir) || (func == pred_okdir))
+ {
+ options.ignore_readdir_race = false;
+ check_path_safety(action);
+ execp->use_current_dir = true;
+ }
+ else
+ {
+ execp->use_current_dir = false;
+ }
+
+ our_pred->args.exec_vec.multiple = 0;
+
+ /* Count the number of args with path replacements, up until the ';'.
+ * Also figure out if the command is terminated by ";" or by "+".
+ */
+ start = *arg_ptr;
+ for (end = start, saw_braces=0, brace_count=0;
+ (argv[end] != NULL)
+ && ((argv[end][0] != ';') || (argv[end][1] != '\0'));
+ end++)
+ {
+ /* For -exec and -execdir, "{} +" can terminate the command. */
+ if ( allow_plus
+ && argv[end][0] == '+' && argv[end][1] == 0
+ && saw_braces)
+ {
+ our_pred->args.exec_vec.multiple = 1;
+ break;
+ }
+
+ saw_braces = 0;
+ if (strstr (argv[end], "{}"))
+ {
+ saw_braces = 1;
+ ++brace_count;
+
+ if (0 == end && (func == pred_execdir || func == pred_okdir))
+ {
+ /* The POSIX standard says that {} replacement should
+ * occur even in the utility name. This is insecure
+ * since it means we will be executing a command whose
+ * name is chosen according to whatever find finds in
+ * the filesystem. That can be influenced by an
+ * attacker. Hence for -execdir and -okdir this is not
+ * allowed. We can specify this as those options are
+ * not defined by POSIX.
+ */
+ error(1, 0, _("You may not use {} within the utility name for -execdir and -okdir, because this is a potential security problem."));
+ }
+ }
+ }
+
+ /* Fail if no command given or no semicolon found. */
+ if ((end == start) || (argv[end] == NULL))
+ {
+ *arg_ptr = end;
+ free(our_pred);
+ return false;
+ }
+
+ if (our_pred->args.exec_vec.multiple && brace_count > 1)
+ {
+
+ const char *suffix;
+ if (func == pred_execdir)
+ suffix = "dir";
+ else
+ suffix = "";
+
+ error(1, 0,
+ _("Only one instance of {} is supported with -exec%s ... +"),
+ suffix);
+ }
+
+ /* We use a switch statement here so that
+ * the compiler warns us when we forget to handle a
+ * newly invented enum value.
+ */
+ bcstatus = bc_init_controlinfo(&execp->ctl);
+ switch (bcstatus)
+ {
+ case BC_INIT_ENV_TOO_BIG:
+ error(1, 0,
+ _("The environment is too large for exec()."));
+ break;
+ case BC_INIT_OK:
+ /* Good news. Carry on. */
+ break;
+ }
+ bc_use_sensible_arg_max(&execp->ctl);
+
+
+ execp->ctl.exec_callback = launch;
+
+ if (our_pred->args.exec_vec.multiple)
+ {
+ /* "+" terminator, so we can just append our arguments after the
+ * command and initial arguments.
+ */
+ execp->replace_vec = NULL;
+ execp->ctl.replace_pat = NULL;
+ execp->ctl.rplen = 0;
+ execp->ctl.lines_per_exec = 0; /* no limit */
+ execp->ctl.args_per_exec = 0; /* no limit */
+
+ /* remember how many arguments there are */
+ execp->ctl.initial_argc = (end-start) - 1;
+
+ /* execp->state = xmalloc(sizeof struct buildcmd_state); */
+ bc_init_state(&execp->ctl, &execp->state, execp);
+
+ /* Gather the initial arguments. Skip the {}. */
+ for (i=start; ictl, &execp->state,
+ argv[i], strlen(argv[i])+1,
+ NULL, 0,
+ 1);
+ }
+ }
+ else
+ {
+ /* Semicolon terminator - more than one {} is supported, so we
+ * have to do brace-replacement.
+ */
+ execp->num_args = end - start;
+
+ execp->ctl.replace_pat = "{}";
+ execp->ctl.rplen = strlen(execp->ctl.replace_pat);
+ execp->ctl.lines_per_exec = 0; /* no limit */
+ execp->ctl.args_per_exec = 0; /* no limit */
+ execp->replace_vec = xmalloc(sizeof(char*)*execp->num_args);
+
+
+ /* execp->state = xmalloc(sizeof(*(execp->state))); */
+ bc_init_state(&execp->ctl, &execp->state, execp);
+
+ /* Remember the (pre-replacement) arguments for later. */
+ for (i=0; inum_args; ++i)
+ {
+ execp->replace_vec[i] = argv[i+start];
+ }
+ }
+
+ if (argv[end] == NULL)
+ *arg_ptr = end;
+ else
+ *arg_ptr = end + 1;
+
+ return true;
+}
+#else
+/* handles both exec and ok predicate */
+static boolean
+old_insert_exec_ok (boolean (*func) (/* ??? */), char **argv, int *arg_ptr)
{
int start, end; /* Indexes in ARGV of start & end of cmd. */
int num_paths; /* Number of args with path replacements. */
@@ -1604,7 +2308,7 @@ insert_exec_ok (func, argv, arg_ptr)
struct exec_val *execp; /* Pointer for efficiency. */
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
/* Count the number of args with path replacements, up until the ';'. */
start = *arg_ptr;
@@ -1618,12 +2322,14 @@ insert_exec_ok (func, argv, arg_ptr)
if ((end == start) || (argv[end] == NULL))
{
*arg_ptr = end;
- return (false);
+ return false;
}
our_pred = insert_primary (func);
- our_pred->side_effects = true;
+ our_pred->side_effects = our_pred->no_default_print = true;
execp = &our_pred->args.exec_vec;
+ execp->usercontext = our_pred;
+ execp->use_current_dir = false;
execp->paths =
(struct path_arg *) xmalloc (sizeof (struct path_arg) * (num_paths + 1));
execp->vec = (char **) xmalloc (sizeof (char *) * (end - start + 1));
@@ -1657,8 +2363,23 @@ insert_exec_ok (func, argv, arg_ptr)
*arg_ptr = end;
else
*arg_ptr = end + 1;
- return (true);
+ return true;
}
+#endif
+
+
+
+static boolean
+insert_exec_ok (const char *action, const struct parser_table *entry, char **argv, int *arg_ptr)
+{
+#if defined(NEW_EXEC)
+ return new_insert_exec_ok(action, entry, argv, arg_ptr);
+#else
+ return old_insert_exec_ok(func, argv, arg_ptr);
+#endif
+}
+
+
/* Get a number of days and comparison type.
STR is the ASCII representation.
@@ -1673,48 +2394,17 @@ insert_exec_ok (func, argv, arg_ptr)
get the appropriate information for a time predicate processor. */
static boolean
-get_num_days (str, num_days, comp_type)
- char *str;
- unsigned long *num_days;
- enum comparison_type *comp_type;
+get_num_days (char *str, uintmax_t *num_days, enum comparison_type *comp_type)
{
- int len_days; /* length of field */
-
- if (str == NULL)
- return (false);
- switch (str[0])
- {
- case '+':
- *comp_type = COMP_LT;
- str++;
- break;
- case '-':
- *comp_type = COMP_GT;
- str++;
- break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
- *comp_type = COMP_EQ;
- break;
- default:
- return (false);
- }
-
- /* We know the first char has been reasonable. Find the
- number of days to play with. */
- len_days = strspn (str, "0123456789");
- if ((len_days == 0) || (str[len_days] != '\0'))
- return (false);
- *num_days = (unsigned long) atol (str);
- return (true);
+ boolean r = get_num (str, num_days, comp_type);
+ if (r)
+ switch (*comp_type)
+ {
+ case COMP_LT: *comp_type = COMP_GT; break;
+ case COMP_GT: *comp_type = COMP_LT; break;
+ default: break;
+ }
+ return r;
}
/* Insert a time predicate PRED.
@@ -1730,66 +2420,79 @@ get_num_days (str, num_days, comp_type)
Used by -atime, -ctime, and -mtime parsers. */
static boolean
-insert_time (argv, arg_ptr, pred)
- char *argv[];
- int *arg_ptr;
- PFB pred;
+insert_time (char **argv, int *arg_ptr, const struct parser_table* entry, PRED_FUNC pred)
{
struct predicate *our_pred;
- unsigned long num_days;
+ uintmax_t num_days;
enum comparison_type c_type;
+ time_t t;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (!get_num_days (argv[*arg_ptr], &num_days, &c_type))
- return (false);
- our_pred = insert_primary (pred);
+ return false;
+
+ /* Figure out the timestamp value we are looking for. */
+ t = ( options.cur_day_start - num_days * DAYSECS
+ + ((c_type == COMP_GT) ? DAYSECS - 1 : 0));
+
+ if (1)
+ {
+ /* We introduce a scope in which 'val' can be declared, for the
+ * benefit of compilers that are really C89 compilers
+ * which support intmax_t because config.h #defines it
+ */
+ intmax_t val = ( (intmax_t)options.cur_day_start - num_days * DAYSECS
+ + ((c_type == COMP_GT) ? DAYSECS - 1 : 0));
+ t = val;
+
+ /* Check for possibility of an overflow */
+ if ( (intmax_t)t != val )
+ {
+ error (1, 0, "arithmetic overflow while converting %s days to a number of seconds", argv[*arg_ptr]);
+ }
+ }
+
+ our_pred = insert_primary_withpred (entry, pred);
our_pred->args.info.kind = c_type;
- our_pred->args.info.l_val = cur_day_start - num_days * DAYSECS
- + ((c_type == COMP_GT) ? DAYSECS - 1 : 0);
+ our_pred->args.info.negative = t < 0;
+ our_pred->args.info.l_val = t;
(*arg_ptr)++;
#ifdef DEBUG
- printf ("inserting %s\n", our_pred->p_name);
- printf (" type: %s %s ",
+ fprintf (stderr, "inserting %s\n", our_pred->p_name);
+ fprintf (stderr, " type: %s %s ",
(c_type == COMP_GT) ? "gt" :
((c_type == COMP_LT) ? "lt" : ((c_type == COMP_EQ) ? "eq" : "?")),
(c_type == COMP_GT) ? " >" :
((c_type == COMP_LT) ? " <" : ((c_type == COMP_EQ) ? ">=" : " ?")));
- printf ("%ld %s", our_pred->args.info.l_val,
- ctime (&our_pred->args.info.l_val));
+ t = our_pred->args.info.l_val;
+ fprintf (stderr, "%ju %s", (uintmax_t) our_pred->args.info.l_val, ctime (&t));
if (c_type == COMP_EQ)
{
- our_pred->args.info.l_val += DAYSECS;
- printf (" < %ld %s", our_pred->args.info.l_val,
- ctime (&our_pred->args.info.l_val));
+ t = our_pred->args.info.l_val += DAYSECS;
+ fprintf (stderr, " < %ju %s",
+ (uintmax_t) our_pred->args.info.l_val, ctime (&t));
our_pred->args.info.l_val -= DAYSECS;
}
#endif /* DEBUG */
- return (true);
+ return true;
}
-/* Get a number with comparision information.
- The sense of the comparision information is 'normal'; that is,
- '+' looks for inums or links > than the number and '-' less than.
+/* Get a number with comparison information.
+ The sense of the comparison information is 'normal'; that is,
+ '+' looks for a count > than the number and '-' less than.
STR is the ASCII representation of the number.
Set *NUM to the number.
Set *COMP_TYPE to the kind of comparison that is requested.
- Return true if all okay, false if input error.
-
- Used by the -inum and -links predicate parsers. */
+ Return true if all okay, false if input error. */
static boolean
-get_num (str, num, comp_type)
- char *str;
- unsigned long *num;
- enum comparison_type *comp_type;
+get_num (char *str, uintmax_t *num, enum comparison_type *comp_type)
{
- int len_num; /* Length of field. */
-
if (str == NULL)
- return (false);
+ return false;
switch (str[0])
{
case '+':
@@ -1800,29 +2503,12 @@ get_num (str, num, comp_type)
*comp_type = COMP_LT;
str++;
break;
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9':
+ default:
*comp_type = COMP_EQ;
break;
- default:
- return (false);
}
- /* We know the first char has been reasonable. Find the number of
- days to play with. */
- len_num = strspn (str, "0123456789");
- if ((len_num == 0) || (str[len_num] != '\0'))
- return (false);
- *num = (unsigned long) atol (str);
- return (true);
+ return xstrtoumax (str, NULL, 10, num, "") == LONGINT_OK;
}
/* Insert a number predicate.
@@ -1838,47 +2524,43 @@ get_num (str, num, comp_type)
Used by -inum and -links parsers. */
static boolean
-insert_num (argv, arg_ptr, pred)
- char *argv[];
- int *arg_ptr;
- PFB pred;
+insert_num (char **argv, int *arg_ptr, const struct parser_table *entry)
{
struct predicate *our_pred;
- unsigned long num;
+ uintmax_t num;
enum comparison_type c_type;
if ((argv == NULL) || (argv[*arg_ptr] == NULL))
- return (false);
+ return false;
if (!get_num (argv[*arg_ptr], &num, &c_type))
- return (false);
- our_pred = insert_primary (pred);
+ return false;
+ our_pred = insert_primary (entry);
our_pred->args.info.kind = c_type;
our_pred->args.info.l_val = num;
(*arg_ptr)++;
#ifdef DEBUG
- printf ("inserting %s\n", our_pred->p_name);
- printf (" type: %s %s ",
+ fprintf (stderr, "inserting %s\n", our_pred->p_name);
+ fprintf (stderr, " type: %s %s ",
(c_type == COMP_GT) ? "gt" :
((c_type == COMP_LT) ? "lt" : ((c_type == COMP_EQ) ? "eq" : "?")),
(c_type == COMP_GT) ? " >" :
((c_type == COMP_LT) ? " <" : ((c_type == COMP_EQ) ? " =" : " ?")));
- printf ("%ld\n", our_pred->args.info.l_val);
+ fprintf (stderr, "%ju\n", our_pred->args.info.l_val);
#endif /* DEBUG */
- return (true);
+ return true;
}
static FILE *
-open_output_file (path)
- char *path;
+open_output_file (char *path)
{
FILE *f;
if (!strcmp (path, "/dev/stderr"))
- return (stderr);
+ return stderr;
else if (!strcmp (path, "/dev/stdout"))
- return (stdout);
- f = fopen (path, "w");
+ return stdout;
+ f = fopen_safer (path, "w");
if (f == NULL)
error (1, errno, "%s", path);
- return (f);
+ return f;
}
diff --git a/src/bin/findutils/find/pred.c b/src/bin/findutils/find/pred.c
index 9c8c682852..b8a3ff9b29 100644
--- a/src/bin/findutils/find/pred.c
+++ b/src/bin/findutils/find/pred.c
@@ -1,40 +1,59 @@
/* pred.c -- execute the expression tree.
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 1991, 1992, 1993, 1994, 2000, 2003,
+ 2004, 2005, 2007 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see .
+*/
+
+#include "defs.h"
-#include
-#include
-#include
-#include
#include
#include
#include
#include
-#include "defs.h"
+#include
+#include
+#include
+#include
+#include "xalloc.h"
+#include "dirname.h"
+#include "human.h"
#include "modetype.h"
+#include "filemode.h"
#include "wait.h"
+#include "printquoted.h"
+#include "buildcmd.h"
+#include "yesno.h"
+
+#if ENABLE_NLS
+# include
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
+#endif
#if !defined(SIGCHLD) && defined(SIGCLD)
#define SIGCHLD SIGCLD
#endif
-#ifndef _POSIX_VERSION
-struct passwd *getpwuid ();
-struct group *getgrgid ();
-#endif
+
#if HAVE_DIRENT_H
# include
@@ -60,37 +79,82 @@ struct group *getgrgid ();
#define CLOSEDIR(d) closedir (d)
#endif
-#ifndef S_IFLNK
-#define lstat stat
-#endif
+
+
+
+/* Get or fake the disk device blocksize.
+ Usually defined by sys/param.h (if at all). */
+#ifndef DEV_BSIZE
+# ifdef BSIZE
+# define DEV_BSIZE BSIZE
+# else /* !BSIZE */
+# define DEV_BSIZE 4096
+# endif /* !BSIZE */
+#endif /* !DEV_BSIZE */
/* Extract or fake data from a `struct stat'.
- ST_NBLOCKS: Number of 512-byte blocks in the file
- (including indirect blocks).
- HP-UX, perhaps uniquely, counts st_blocks in 1024-byte units.
- This workaround loses when mixing HP-UX and 4BSD filesystems, though. */
-#ifdef _POSIX_SOURCE
-# define ST_NBLOCKS(statp) (((statp)->st_size + 512 - 1) / 512)
-#else
-# ifndef HAVE_ST_BLOCKS
-# define ST_NBLOCKS(statp) (st_blocks ((statp)->st_size))
-# else
-# if defined(hpux) || defined(__hpux__)
-# define ST_NBLOCKS(statp) ((statp)->st_blocks * 2)
-# else
-# define ST_NBLOCKS(statp) ((statp)->st_blocks)
-# endif
-# endif
+ ST_BLKSIZE: Preferred I/O blocksize for the file, in bytes.
+ ST_NBLOCKS: Number of blocks in the file, including indirect blocks.
+ ST_NBLOCKSIZE: Size of blocks used when calculating ST_NBLOCKS. */
+#ifndef HAVE_STRUCT_STAT_ST_BLOCKS
+# define ST_BLKSIZE(statbuf) DEV_BSIZE
+# if defined(_POSIX_SOURCE) || !defined(BSIZE) /* fileblocks.c uses BSIZE. */
+# define ST_NBLOCKS(statbuf) \
+ (S_ISREG ((statbuf).st_mode) \
+ || S_ISDIR ((statbuf).st_mode) \
+ ? (statbuf).st_size / ST_NBLOCKSIZE + ((statbuf).st_size % ST_NBLOCKSIZE != 0) : 0)
+# else /* !_POSIX_SOURCE && BSIZE */
+# define ST_NBLOCKS(statbuf) \
+ (S_ISREG ((statbuf).st_mode) \
+ || S_ISDIR ((statbuf).st_mode) \
+ ? st_blocks ((statbuf).st_size) : 0)
+# endif /* !_POSIX_SOURCE && BSIZE */
+#else /* HAVE_STRUCT_STAT_ST_BLOCKS */
+/* Some systems, like Sequents, return st_blksize of 0 on pipes. */
+# define ST_BLKSIZE(statbuf) ((statbuf).st_blksize > 0 \
+ ? (statbuf).st_blksize : DEV_BSIZE)
+# if defined(hpux) || defined(__hpux__) || defined(__hpux)
+/* HP-UX counts st_blocks in 1024-byte units.
+ This loses when mixing HP-UX and BSD filesystems with NFS. */
+# define ST_NBLOCKSIZE 1024
+# else /* !hpux */
+# if defined(_AIX) && defined(_I386)
+/* AIX PS/2 counts st_blocks in 4K units. */
+# define ST_NBLOCKSIZE (4 * 1024)
+# else /* not AIX PS/2 */
+# if defined(_CRAY)
+# define ST_NBLOCKS(statbuf) \
+ (S_ISREG ((statbuf).st_mode) \
+ || S_ISDIR ((statbuf).st_mode) \
+ ? (statbuf).st_blocks * ST_BLKSIZE(statbuf)/ST_NBLOCKSIZE : 0)
+# endif /* _CRAY */
+# endif /* not AIX PS/2 */
+# endif /* !hpux */
+#endif /* HAVE_STRUCT_STAT_ST_BLOCKS */
+
+#ifndef ST_NBLOCKS
+# define ST_NBLOCKS(statbuf) \
+ (S_ISREG ((statbuf).st_mode) \
+ || S_ISDIR ((statbuf).st_mode) \
+ ? (statbuf).st_blocks : 0)
#endif
-int lstat ();
-int stat ();
+#ifndef ST_NBLOCKSIZE
+# define ST_NBLOCKSIZE 512
+#endif
-static boolean insert_lname P_((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr, boolean ignore_case));
-static boolean launch P_((struct predicate *pred_ptr));
-static char *format_date P_((time_t when, int kind));
+
+#undef MAX
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+static boolean insert_lname PARAMS((char *pathname, struct stat *stat_buf, struct predicate *pred_ptr, boolean ignore_case));
+
+static char *format_date PARAMS((time_t when, int kind));
+static char *ctime_format PARAMS((time_t when));
#ifdef DEBUG
+typedef boolean (*PFB) (char *, struct stat *, struct predicate *);
+
struct pred_assoc
{
PFB pred_func;
@@ -103,13 +167,15 @@ struct pred_assoc pred_table[] =
{pred_and, "and "},
{pred_anewer, "anewer "},
{pred_atime, "atime "},
- {pred_close, ") "},
+ {pred_closeparen, ") "},
{pred_amin, "cmin "},
{pred_cnewer, "cnewer "},
{pred_comma, ", "},
{pred_ctime, "ctime "},
+ {pred_delete, "delete "},
{pred_empty, "empty "},
{pred_exec, "exec "},
+ {pred_execdir, "execdir "},
{pred_false, "false "},
{pred_fprint, "fprint "},
{pred_fprint0, "fprint0 "},
@@ -132,7 +198,8 @@ struct pred_assoc pred_table[] =
{pred_nogroup, "nogroup "},
{pred_nouser, "nouser "},
{pred_ok, "ok "},
- {pred_open, "( "},
+ {pred_okdir, "okdir "},
+ {pred_openparen, "( "},
{pred_or, "or "},
{pred_path, "path "},
{pred_perm, "perm "},
@@ -140,6 +207,7 @@ struct pred_assoc pred_table[] =
{pred_print0, "print0 "},
{pred_prune, "prune "},
{pred_regex, "regex "},
+ {pred_samefile,"samefile "},
{pred_size, "size "},
{pred_true, "true "},
{pred_type, "type "},
@@ -193,53 +261,55 @@ struct prec_assoc prec_table[] =
Return true if the file passes this predicate, false if not. */
-boolean
-pred_amin (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+
+/* pred_timewindow
+ *
+ * Returns true if THE_TIME is
+ * COMP_GT: after the specified time
+ * COMP_LT: before the specified time
+ * COMP_EQ: less than WINDOW seconds after the specified time.
+ */
+static boolean
+pred_timewindow(time_t the_time, struct predicate const *pred_ptr, int window)
{
switch (pred_ptr->args.info.kind)
{
case COMP_GT:
- if (stat_buf->st_atime > (time_t) pred_ptr->args.info.l_val)
- return (true);
+ if (the_time > (time_t) pred_ptr->args.info.l_val)
+ return true;
break;
case COMP_LT:
- if (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val)
- return (true);
+ if (the_time < (time_t) pred_ptr->args.info.l_val)
+ return true;
break;
case COMP_EQ:
- if ((stat_buf->st_atime >= (time_t) pred_ptr->args.info.l_val)
- && (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val + 60))
- return (true);
+ if ((the_time >= (time_t) pred_ptr->args.info.l_val)
+ && (the_time < (time_t) pred_ptr->args.info.l_val + window))
+ return true;
break;
}
- return (false);
+ return false;
+}
+
+
+boolean
+pred_amin (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ (void) &pathname;
+ return pred_timewindow(stat_buf->st_atime, pred_ptr, 60);
}
boolean
-pred_and (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_and (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
if (pred_ptr->pred_left == NULL
|| (*pred_ptr->pred_left->pred_func) (pathname, stat_buf,
pred_ptr->pred_left))
{
/* Check whether we need a stat here. */
- if (pred_ptr->need_stat)
- {
- if (!have_stat && (*xstat) (rel_pathname, stat_buf) != 0)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
- }
- have_stat = true;
- }
- return ((*pred_ptr->pred_right->pred_func) (pathname, stat_buf,
+ if (get_info(pathname, state.rel_pathname, stat_buf, pred_ptr) != 0)
+ return false;
+ return ((*pred_ptr->pred_right->pred_func) (pathname, stat_buf,
pred_ptr->pred_right));
}
else
@@ -247,143 +317,99 @@ pred_and (pathname, stat_buf, pred_ptr)
}
boolean
-pred_anewer (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_anewer (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) &pathname;
+
if (stat_buf->st_atime > pred_ptr->args.time)
return (true);
return (false);
}
boolean
-pred_atime (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_atime (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- switch (pred_ptr->args.info.kind)
- {
- case COMP_GT:
- if (stat_buf->st_atime > (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_LT:
- if (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_EQ:
- if ((stat_buf->st_atime >= (time_t) pred_ptr->args.info.l_val)
- && (stat_buf->st_atime < (time_t) pred_ptr->args.info.l_val
- + DAYSECS))
- return (true);
- break;
- }
- return (false);
+ (void) &pathname;
+ return pred_timewindow(stat_buf->st_atime, pred_ptr, DAYSECS);
}
boolean
-pred_close (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_closeparen (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- return (true);
+ (void) &pathname;
+ (void) &stat_buf;
+ (void) &pred_ptr;
+
+ return true;
}
boolean
-pred_cmin (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_cmin (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- switch (pred_ptr->args.info.kind)
- {
- case COMP_GT:
- if (stat_buf->st_ctime > (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_LT:
- if (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_EQ:
- if ((stat_buf->st_ctime >= (time_t) pred_ptr->args.info.l_val)
- && (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val + 60))
- return (true);
- break;
- }
- return (false);
+ (void) pathname;
+ return pred_timewindow(stat_buf->st_ctime, pred_ptr, 60);
}
boolean
-pred_cnewer (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_cnewer (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+
if (stat_buf->st_ctime > pred_ptr->args.time)
- return (true);
- return (false);
+ return true;
+ else
+ return false;
}
boolean
-pred_comma (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_comma (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
if (pred_ptr->pred_left != NULL)
(*pred_ptr->pred_left->pred_func) (pathname, stat_buf,
pred_ptr->pred_left);
/* Check whether we need a stat here. */
- if (pred_ptr->need_stat)
- {
- if (!have_stat && (*xstat) (rel_pathname, stat_buf) != 0)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
- }
- have_stat = true;
- }
+ /* TODO: what about need_type? */
+ if (get_info(pathname, state.rel_pathname, stat_buf, pred_ptr) != 0)
+ return false;
return ((*pred_ptr->pred_right->pred_func) (pathname, stat_buf,
pred_ptr->pred_right));
}
boolean
-pred_ctime (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_ctime (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- switch (pred_ptr->args.info.kind)
- {
- case COMP_GT:
- if (stat_buf->st_ctime > (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_LT:
- if (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_EQ:
- if ((stat_buf->st_ctime >= (time_t) pred_ptr->args.info.l_val)
- && (stat_buf->st_ctime < (time_t) pred_ptr->args.info.l_val
- + DAYSECS))
- return (true);
- break;
- }
- return (false);
+ (void) &pathname;
+ return pred_timewindow(stat_buf->st_ctime, pred_ptr, DAYSECS);
}
boolean
-pred_empty (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_delete (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pred_ptr;
+ (void) stat_buf;
+ if (strcmp (state.rel_pathname, "."))
+ {
+ if (0 != remove (state.rel_pathname))
+ {
+ error (0, errno, "cannot delete %s", pathname);
+ return false;
+ }
+ else
+ {
+ return true;
+ }
+ }
+
+ /* nothing to do. */
+ return true;
+}
+
+boolean
+pred_empty (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ (void) pathname;
+ (void) pred_ptr;
+
if (S_ISDIR (stat_buf->st_mode))
{
DIR *d;
@@ -391,12 +417,12 @@ pred_empty (pathname, stat_buf, pred_ptr)
boolean empty = true;
errno = 0;
- d = opendir (rel_pathname);
+ d = opendir (state.rel_pathname);
if (d == NULL)
{
error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
+ state.exit_status = 1;
+ return false;
}
for (dp = readdir (d); dp; dp = readdir (d))
{
@@ -411,8 +437,8 @@ pred_empty (pathname, stat_buf, pred_ptr)
if (CLOSEDIR (d))
{
error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
+ state.exit_status = 1;
+ return false;
}
return (empty);
}
@@ -422,97 +448,142 @@ pred_empty (pathname, stat_buf, pred_ptr)
return (false);
}
-boolean
-pred_exec (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+static boolean
+new_impl_pred_exec (const char *pathname, struct stat *stat_buf,
+ struct predicate *pred_ptr,
+ const char *prefix, size_t pfxlen)
{
- int i;
- int path_pos;
- struct exec_val *execp; /* Pointer for efficiency. */
+ struct exec_val *execp = &pred_ptr->args.exec_vec;
+ size_t len = strlen(pathname);
- execp = &pred_ptr->args.exec_vec;
-
- /* Replace "{}" with the real path in each affected arg. */
- for (path_pos = 0; execp->paths[path_pos].offset >= 0; path_pos++)
+ (void) stat_buf;
+
+ if (execp->multiple)
{
- register char *from, *to;
-
- i = execp->paths[path_pos].offset;
- execp->vec[i] =
- xmalloc (strlen (execp->paths[path_pos].origarg) + 1
- + (strlen (pathname) - 2) * execp->paths[path_pos].count);
- for (from = execp->paths[path_pos].origarg, to = execp->vec[i]; *from; )
- if (from[0] == '{' && from[1] == '}')
- {
- to = stpcpy (to, pathname);
- from += 2;
- }
- else
- *to++ = *from++;
- *to = *from; /* Copy null. */
+ /* Push the argument onto the current list.
+ * The command may or may not be run at this point,
+ * depending on the command line length limits.
+ */
+ bc_push_arg(&execp->ctl,
+ &execp->state,
+ pathname, len+1,
+ prefix, pfxlen,
+ 0);
+
+ /* POSIX: If the primary expression is punctuated by a plus
+ * sign, the primary shall always evaluate as true
+ */
+ return true;
}
+ else
+ {
+ int i;
- i = launch (pred_ptr);
+ for (i=0; inum_args; ++i)
+ {
+ bc_do_insert(&execp->ctl,
+ &execp->state,
+ execp->replace_vec[i],
+ strlen(execp->replace_vec[i]),
+ prefix, pfxlen,
+ pathname, len,
+ 0);
+ }
- /* Free the temporary args. */
- for (path_pos = 0; execp->paths[path_pos].offset >= 0; path_pos++)
- free (execp->vec[execp->paths[path_pos].offset]);
+ /* Actually invoke the command. */
+ return execp->ctl.exec_callback(&execp->ctl,
+ &execp->state);
+ }
+}
- return (i);
+
+boolean
+pred_exec (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ return new_impl_pred_exec(pathname, stat_buf, pred_ptr, NULL, 0);
}
boolean
-pred_false (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_execdir (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ const char *prefix = (state.rel_pathname[0] == '/') ? NULL : "./";
+ (void) &pathname;
+ return new_impl_pred_exec (state.rel_pathname, stat_buf, pred_ptr,
+ prefix, (prefix ? 2 : 0));
+}
+
+boolean
+pred_false (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ (void) &pathname;
+ (void) &stat_buf;
+ (void) &pred_ptr;
+
+
return (false);
}
boolean
-pred_fls (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_fls (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- list_file (pathname, rel_pathname, stat_buf, pred_ptr->args.stream);
+ list_file (pathname, state.rel_pathname, stat_buf, options.start_time,
+ options.output_block_size, pred_ptr->args.stream);
return (true);
}
boolean
-pred_fprint (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_fprint (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- fputs (pathname, pred_ptr->args.stream);
- putc ('\n', pred_ptr->args.stream);
- return (true);
+ (void) &pathname;
+ (void) &stat_buf;
+
+ print_quoted(pred_ptr->args.printf_vec.stream,
+ pred_ptr->args.printf_vec.quote_opts,
+ pred_ptr->args.printf_vec.dest_is_tty,
+ "%s\n",
+ pathname);
+ return true;
}
boolean
-pred_fprint0 (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_fprint0 (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) &pathname;
+ (void) &stat_buf;
+
fputs (pathname, pred_ptr->args.stream);
putc (0, pred_ptr->args.stream);
return (true);
}
+
+
+static char*
+mode_to_filetype(mode_t m)
+{
+ return
+ m == S_IFSOCK ? "s" :
+ m == S_IFLNK ? "l" :
+ m == S_IFREG ? "f" :
+ m == S_IFBLK ? "b" :
+ m == S_IFDIR ? "d" :
+ m == S_IFCHR ? "c" :
+#ifdef S_IFDOOR
+ m == S_IFDOOR ? "D" :
+#endif
+ m == S_IFIFO ? "p" : "U";
+}
+
+
boolean
-pred_fprintf (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_fprintf (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
FILE *fp = pred_ptr->args.printf_vec.stream;
+ const struct quoting_options *qopts = pred_ptr->args.printf_vec.quote_opts;
+ boolean ttyflag = pred_ptr->args.printf_vec.dest_is_tty;
struct segment *segment;
char *cp;
+ char hbuf[LONGEST_HUMAN_READABLE + 1];
for (segment = pred_ptr->args.printf_vec.segment; segment;
segment = segment->next)
@@ -535,6 +606,11 @@ pred_fprintf (pathname, stat_buf, pred_ptr)
default:
abort ();
}
+ /* We trust the output of format_date not to contain
+ * nasty characters, though the value of the date
+ * is itself untrusted data.
+ */
+ /* trusted */
fprintf (fp, segment->text,
format_date (t, (segment->kind >> 8) & 0xff));
continue;
@@ -543,41 +619,56 @@ pred_fprintf (pathname, stat_buf, pred_ptr)
switch (segment->kind)
{
case KIND_PLAIN: /* Plain text string (no % conversion). */
+ /* trusted */
fwrite (segment->text, 1, segment->text_len, fp);
break;
case KIND_STOP: /* Terminate argument and flush output. */
+ /* trusted */
fwrite (segment->text, 1, segment->text_len, fp);
fflush (fp);
return (true);
case 'a': /* atime in `ctime' format. */
- cp = ctime (&stat_buf->st_atime);
- cp[24] = '\0';
- fprintf (fp, segment->text, cp);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text, ctime_format (stat_buf->st_atime));
break;
case 'b': /* size in 512-byte blocks */
- fprintf (fp, segment->text, ST_NBLOCKS (stat_buf));
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) ST_NBLOCKS (*stat_buf),
+ hbuf, human_ceiling,
+ ST_NBLOCKSIZE, 512));
break;
case 'c': /* ctime in `ctime' format */
- cp = ctime (&stat_buf->st_ctime);
- cp[24] = '\0';
- fprintf (fp, segment->text, cp);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text, ctime_format (stat_buf->st_ctime));
break;
case 'd': /* depth in search tree */
- fprintf (fp, segment->text, curdepth);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text, state.curdepth);
break;
- case 'f': /* basename of path */
- cp = strrchr (pathname, '/');
- if (cp)
- cp++;
- else
- cp = pathname;
- fprintf (fp, segment->text, cp);
+ case 'D': /* Device on which file exists (stat.st_dev) */
+ /* trusted */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) stat_buf->st_dev, hbuf,
+ human_ceiling, 1, 1));
+ break;
+ case 'f': /* base name of path */
+ /* sanitised */
+ {
+ char *base = base_name (pathname);
+ print_quoted (fp, qopts, ttyflag, segment->text, base);
+ free (base);
+ }
break;
case 'F': /* filesystem type */
- fprintf (fp, segment->text,
- filesystem_type (pathname, rel_pathname, stat_buf));
+ /* trusted */
+ print_quoted (fp, qopts, ttyflag, segment->text, filesystem_type (stat_buf, pathname));
break;
case 'g': /* group name */
+ /* trusted */
+ /* (well, the actual group is selected by the user but
+ * its name was selected by the system administrator)
+ */
{
struct group *g;
@@ -591,71 +682,139 @@ pred_fprintf (pathname, stat_buf, pred_ptr)
/* else fallthru */
}
case 'G': /* GID number */
- segment->text[segment->text_len] = 'u';
- fprintf (fp, segment->text, stat_buf->st_gid);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) stat_buf->st_gid, hbuf,
+ human_ceiling, 1, 1));
break;
case 'h': /* leading directories part of path */
+ /* sanitised */
{
char cc;
-
+
cp = strrchr (pathname, '/');
if (cp == NULL) /* No leading directories. */
- break;
- cc = *cp;
- *cp = '\0';
- fprintf (fp, segment->text, pathname);
- *cp = cc;
+ {
+ /* If there is no slash in the pathname, we still
+ * print the string because it contains characters
+ * other than just '%s'. The %h expands to ".".
+ */
+ print_quoted (fp, qopts, ttyflag, segment->text, ".");
+ }
+ else
+ {
+ cc = *cp;
+ *cp = '\0';
+ print_quoted (fp, qopts, ttyflag, segment->text, pathname);
+ *cp = cc;
+ }
break;
}
case 'H': /* ARGV element file was found under */
+ /* trusted */
{
- char cc = pathname[path_length];
+ char cc = pathname[state.path_length];
- pathname[path_length] = '\0';
+ pathname[state.path_length] = '\0';
fprintf (fp, segment->text, pathname);
- pathname[path_length] = cc;
+ pathname[state.path_length] = cc;
break;
}
case 'i': /* inode number */
- fprintf (fp, segment->text, stat_buf->st_ino);
+ /* UNTRUSTED, but not exploitable I think */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) stat_buf->st_ino, hbuf,
+ human_ceiling,
+ 1, 1));
break;
case 'k': /* size in 1K blocks */
- fprintf (fp, segment->text, (ST_NBLOCKS (stat_buf) + 1) / 2);
+ /* UNTRUSTED, but not exploitable I think */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) ST_NBLOCKS (*stat_buf),
+ hbuf, human_ceiling,
+ ST_NBLOCKSIZE, 1024));
break;
case 'l': /* object of symlink */
+ /* sanitised */
#ifdef S_ISLNK
{
char *linkname = 0;
if (S_ISLNK (stat_buf->st_mode))
{
- linkname = get_link_name (pathname, rel_pathname);
+ linkname = get_link_name (pathname, state.rel_pathname);
if (linkname == 0)
- exit_status = 1;
+ state.exit_status = 1;
}
if (linkname)
{
- fprintf (fp, segment->text, linkname);
+ print_quoted (fp, qopts, ttyflag, segment->text, linkname);
free (linkname);
}
else
- fprintf (fp, segment->text, "");
+ print_quoted (fp, qopts, ttyflag, segment->text, "");
}
#endif /* S_ISLNK */
break;
- case 'm': /* mode as octal number (perms only) */
- fprintf (fp, segment->text, stat_buf->st_mode & 07777);
+
+ case 'M': /* mode as 10 chars (eg., "-rwxr-x--x" */
+ /* UNTRUSTED, probably unexploitable */
+ {
+ char modestring[16] ;
+ filemodestring (stat_buf, modestring);
+ modestring[10] = '\0';
+ fprintf (fp, segment->text, modestring);
+ }
break;
+
+ case 'm': /* mode as octal number (perms only) */
+ /* UNTRUSTED, probably unexploitable */
+ {
+ /* Output the mode portably using the traditional numbers,
+ even if the host unwisely uses some other numbering
+ scheme. But help the compiler in the common case where
+ the host uses the traditional numbering scheme. */
+ mode_t m = stat_buf->st_mode;
+ boolean traditional_numbering_scheme =
+ (S_ISUID == 04000 && S_ISGID == 02000 && S_ISVTX == 01000
+ && S_IRUSR == 00400 && S_IWUSR == 00200 && S_IXUSR == 00100
+ && S_IRGRP == 00040 && S_IWGRP == 00020 && S_IXGRP == 00010
+ && S_IROTH == 00004 && S_IWOTH == 00002 && S_IXOTH == 00001);
+ fprintf (fp, segment->text,
+ (traditional_numbering_scheme
+ ? m & MODE_ALL
+ : ((m & S_ISUID ? 04000 : 0)
+ | (m & S_ISGID ? 02000 : 0)
+ | (m & S_ISVTX ? 01000 : 0)
+ | (m & S_IRUSR ? 00400 : 0)
+ | (m & S_IWUSR ? 00200 : 0)
+ | (m & S_IXUSR ? 00100 : 0)
+ | (m & S_IRGRP ? 00040 : 0)
+ | (m & S_IWGRP ? 00020 : 0)
+ | (m & S_IXGRP ? 00010 : 0)
+ | (m & S_IROTH ? 00004 : 0)
+ | (m & S_IWOTH ? 00002 : 0)
+ | (m & S_IXOTH ? 00001 : 0))));
+ }
+ break;
+
case 'n': /* number of links */
- fprintf (fp, segment->text, stat_buf->st_nlink);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) stat_buf->st_nlink,
+ hbuf,
+ human_ceiling,
+ 1, 1));
break;
case 'p': /* pathname */
- fprintf (fp, segment->text, pathname);
+ /* sanitised */
+ print_quoted (fp, qopts, ttyflag, segment->text, pathname);
break;
case 'P': /* pathname with ARGV element stripped */
- if (curdepth)
+ /* sanitised */
+ if (state.curdepth > 0)
{
- cp = pathname + path_length;
+ cp = pathname + state.path_length;
if (*cp == '/')
/* Move past the slash between the ARGV element
and the rest of the pathname. But if the ARGV element
@@ -665,17 +824,24 @@ pred_fprintf (pathname, stat_buf, pred_ptr)
}
else
cp = "";
- fprintf (fp, segment->text, cp);
+ print_quoted (fp, qopts, ttyflag, segment->text, cp);
break;
case 's': /* size in bytes */
- fprintf (fp, segment->text, stat_buf->st_size);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) stat_buf->st_size,
+ hbuf, human_ceiling, 1, 1));
break;
case 't': /* mtime in `ctime' format */
- cp = ctime (&stat_buf->st_mtime);
- cp[24] = '\0';
- fprintf (fp, segment->text, cp);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text, ctime_format (stat_buf->st_mtime));
break;
case 'u': /* user name */
+ /* trusted */
+ /* (well, the actual user is selected by the user on systems
+ * where chown is not restricted, but the user name was
+ * selected by the system administrator)
+ */
{
struct passwd *p;
@@ -688,33 +854,80 @@ pred_fprintf (pathname, stat_buf, pred_ptr)
}
/* else fallthru */
}
+
case 'U': /* UID number */
- segment->text[segment->text_len] = 'u';
- fprintf (fp, segment->text, stat_buf->st_uid);
+ /* UNTRUSTED, probably unexploitable */
+ fprintf (fp, segment->text,
+ human_readable ((uintmax_t) stat_buf->st_uid, hbuf,
+ human_ceiling, 1, 1));
+ break;
+
+ /* type of filesystem entry like `ls -l`: (d,-,l,s,p,b,c,n) n=nonexistent(symlink) */
+ case 'Y': /* in case of symlink */
+ /* trusted */
+ {
+#ifdef S_ISLNK
+ if (S_ISLNK (stat_buf->st_mode))
+ {
+ struct stat sbuf;
+ /* If we would normally follow links, do not do so.
+ * If we would normally not follow links, do so.
+ */
+ if ((following_links() ? lstat : stat)
+ (state.rel_pathname, &sbuf) != 0)
+ {
+ if ( errno == ENOENT ) {
+ fprintf (fp, segment->text, "N");
+ break;
+ };
+ if ( errno == ELOOP ) {
+ fprintf (fp, segment->text, "L");
+ break;
+ };
+ error (0, errno, "%s", pathname);
+ /* exit_status = 1;
+ return (false); */
+ }
+ fprintf (fp, segment->text,
+ mode_to_filetype(sbuf.st_mode & S_IFMT));
+ }
+#endif /* S_ISLNK */
+ else
+ {
+ fprintf (fp, segment->text,
+ mode_to_filetype(stat_buf->st_mode & S_IFMT));
+ }
+ }
+ break;
+
+ case 'y':
+ /* trusted */
+ {
+ fprintf (fp, segment->text,
+ mode_to_filetype(stat_buf->st_mode & S_IFMT));
+ }
break;
}
}
- return (true);
+ return true;
}
boolean
-pred_fstype (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_fstype (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- if (strcmp (filesystem_type (pathname, rel_pathname, stat_buf),
- pred_ptr->args.str) == 0)
- return (true);
- return (false);
+ (void) pathname;
+
+ if (strcmp (filesystem_type (stat_buf, pathname), pred_ptr->args.str) == 0)
+ return true;
+ else
+ return false;
}
boolean
-pred_gid (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_gid (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+
switch (pred_ptr->args.info.kind)
{
case COMP_GT:
@@ -734,11 +947,10 @@ pred_gid (pathname, stat_buf, pred_ptr)
}
boolean
-pred_group (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_group (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+
if (pred_ptr->args.gid == stat_buf->st_gid)
return (true);
else
@@ -746,34 +958,51 @@ pred_group (pathname, stat_buf, pred_ptr)
}
boolean
-pred_ilname (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_ilname (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
return insert_lname (pathname, stat_buf, pred_ptr, true);
}
-boolean
-pred_iname (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+/* Common code between -name, -iname. PATHNAME is being visited, STR
+ is name to compare basename against, and FLAGS are passed to
+ fnmatch. Recall that 'find / -name /' is one of the few times where a '/'
+ in the -name must actually find something. */
+static boolean
+pred_name_common (const char *pathname, const char *str, int flags)
{
- char *base;
+ char *p;
+ boolean b;
+ /* We used to use last_component() here, but that would not allow us
+ * to modify the input string, which is const. We could optimise by
+ * duplicating the string only if we need to modify it, and I'll do
+ * that if there is a measurable performance difference on a machine
+ * built after 1990...
+ */
+ char *base = base_name (pathname);
+ /* remove trailing slashes, but leave "/" or "//foo" unchanged. */
+ strip_trailing_slashes(base);
- base = basename (pathname);
- if (fnmatch (pred_ptr->args.str, base, FNM_PERIOD | FNM_CASEFOLD) == 0)
- return (true);
- return (false);
+ /* FNM_PERIOD is not used here because POSIX requires that it not be.
+ * See http://standards.ieee.org/reading/ieee/interp/1003-2-92_int/pasc-1003.2-126.html
+ */
+ b = fnmatch (str, base, flags) == 0;
+ free (base);
+ return b;
+}
+
+
+boolean
+pred_iname (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ (void) stat_buf;
+ return pred_name_common (pathname, pred_ptr->args.str, FNM_CASEFOLD);
}
boolean
-pred_inum (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_inum (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+
switch (pred_ptr->args.info.kind)
{
case COMP_GT:
@@ -793,22 +1022,20 @@ pred_inum (pathname, stat_buf, pred_ptr)
}
boolean
-pred_ipath (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_ipath (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) stat_buf;
+
if (fnmatch (pred_ptr->args.str, pathname, FNM_CASEFOLD) == 0)
return (true);
return (false);
}
boolean
-pred_links (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_links (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+
switch (pred_ptr->args.info.kind)
{
case COMP_GT:
@@ -828,26 +1055,19 @@ pred_links (pathname, stat_buf, pred_ptr)
}
boolean
-pred_lname (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_lname (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
return insert_lname (pathname, stat_buf, pred_ptr, false);
}
static boolean
-insert_lname (pathname, stat_buf, pred_ptr, ignore_case)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
- boolean ignore_case;
+insert_lname (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr, boolean ignore_case)
{
boolean ret = false;
#ifdef S_ISLNK
if (S_ISLNK (stat_buf->st_mode))
{
- char *linkname = get_link_name (pathname, rel_pathname);
+ char *linkname = get_link_name (pathname, state.rel_pathname);
if (linkname)
{
if (fnmatch (pred_ptr->args.str, linkname,
@@ -861,118 +1081,63 @@ insert_lname (pathname, stat_buf, pred_ptr, ignore_case)
}
boolean
-pred_ls (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_ls (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- list_file (pathname, rel_pathname, stat_buf, stdout);
+ (void) pred_ptr;
+
+ list_file (pathname, state.rel_pathname, stat_buf, options.start_time,
+ options.output_block_size, stdout);
return (true);
}
boolean
-pred_mmin (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_mmin (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- switch (pred_ptr->args.info.kind)
- {
- case COMP_GT:
- if (stat_buf->st_mtime > (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_LT:
- if (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_EQ:
- if ((stat_buf->st_mtime >= (time_t) pred_ptr->args.info.l_val)
- && (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val + 60))
- return (true);
- break;
- }
- return (false);
+ (void) &pathname;
+ return pred_timewindow(stat_buf->st_mtime, pred_ptr, 60);
}
boolean
-pred_mtime (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_mtime (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- switch (pred_ptr->args.info.kind)
- {
- case COMP_GT:
- if (stat_buf->st_mtime > (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_LT:
- if (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_EQ:
- if ((stat_buf->st_mtime >= (time_t) pred_ptr->args.info.l_val)
- && (stat_buf->st_mtime < (time_t) pred_ptr->args.info.l_val
- + DAYSECS))
- return (true);
- break;
- }
- return (false);
+ (void) pathname;
+ return pred_timewindow(stat_buf->st_mtime, pred_ptr, DAYSECS);
}
boolean
-pred_name (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_name (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- char *base;
-
- base = basename (pathname);
- if (fnmatch (pred_ptr->args.str, base, FNM_PERIOD) == 0)
- return (true);
- return (false);
+ (void) stat_buf;
+ return pred_name_common (pathname, pred_ptr->args.str, 0);
}
boolean
-pred_negate (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_negate (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
/* Check whether we need a stat here. */
- if (pred_ptr->need_stat)
- {
- if (!have_stat && (*xstat) (rel_pathname, stat_buf) != 0)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
- }
- have_stat = true;
- }
+ /* TODO: what about need_type? */
+ if (get_info(pathname, state.rel_pathname, stat_buf, pred_ptr) != 0)
+ return false;
return (!(*pred_ptr->pred_right->pred_func) (pathname, stat_buf,
pred_ptr->pred_right));
}
boolean
-pred_newer (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_newer (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+
if (stat_buf->st_mtime > pred_ptr->args.time)
return (true);
return (false);
}
boolean
-pred_nogroup (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_nogroup (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
+ (void) pred_ptr;
+
#ifdef CACHE_IDS
extern char *gid_unused;
@@ -983,157 +1148,187 @@ pred_nogroup (pathname, stat_buf, pred_ptr)
}
boolean
-pred_nouser (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_nouser (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
#ifdef CACHE_IDS
extern char *uid_unused;
-
+#endif
+
+ (void) pathname;
+ (void) pred_ptr;
+
+#ifdef CACHE_IDS
return uid_unused[(unsigned) stat_buf->st_uid];
#else
return getpwuid (stat_buf->st_uid) == NULL;
#endif
}
-boolean
-pred_ok (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+
+static boolean
+is_ok(const char *program, const char *arg)
{
- int i, yes;
-
fflush (stdout);
- fprintf (stderr, "< %s ... %s > ? ",
- pred_ptr->args.exec_vec.vec[0], pathname);
+ /* The draft open standard requires that, in the POSIX locale,
+ the last non-blank character of this prompt be '?'.
+ The exact format is not specified.
+ This standard does not have requirements for locales other than POSIX
+ */
+ /* XXX: printing UNTRUSTED data here. */
+ fprintf (stderr, _("< %s ... %s > ? "), program, arg);
fflush (stderr);
- i = getchar ();
- yes = (i == 'y' || i == 'Y');
- while (i != EOF && i != '\n')
- i = getchar ();
- if (!yes)
- return (false);
- return pred_exec (pathname, stat_buf, pred_ptr);
+ return yesno();
}
boolean
-pred_open (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_ok (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- return (true);
+ if (is_ok(pred_ptr->args.exec_vec.replace_vec[0], pathname))
+ return new_impl_pred_exec (pathname, stat_buf, pred_ptr, NULL, 0);
+ else
+ return false;
}
boolean
-pred_or (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_okdir (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ const char *prefix = (state.rel_pathname[0] == '/') ? NULL : "./";
+ if (is_ok(pred_ptr->args.exec_vec.replace_vec[0], pathname))
+ return new_impl_pred_exec (state.rel_pathname, stat_buf, pred_ptr,
+ prefix, (prefix ? 2 : 0));
+ else
+ return false;
+}
+
+boolean
+pred_openparen (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ (void) pathname;
+ (void) stat_buf;
+ (void) pred_ptr;
+ return true;
+}
+
+boolean
+pred_or (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
if (pred_ptr->pred_left == NULL
|| !(*pred_ptr->pred_left->pred_func) (pathname, stat_buf,
pred_ptr->pred_left))
{
- /* Check whether we need a stat here. */
- if (pred_ptr->need_stat)
- {
- if (!have_stat && (*xstat) (rel_pathname, stat_buf) != 0)
- {
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
- }
- have_stat = true;
- }
+ if (get_info(pathname, state.rel_pathname, stat_buf, pred_ptr) != 0)
+ return false;
return ((*pred_ptr->pred_right->pred_func) (pathname, stat_buf,
pred_ptr->pred_right));
}
else
- return (true);
+ return true;
}
boolean
-pred_path (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_path (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) stat_buf;
if (fnmatch (pred_ptr->args.str, pathname, 0) == 0)
return (true);
return (false);
}
boolean
-pred_perm (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_perm (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- if (pred_ptr->args.perm & 010000)
+ mode_t mode = stat_buf->st_mode;
+ mode_t perm_val = pred_ptr->args.perm.val[S_ISDIR (mode) != 0];
+ (void) pathname;
+ switch (pred_ptr->args.perm.kind)
{
- /* Magic flag set in parse_perm:
- true if at least the given bits are set. */
- if ((stat_buf->st_mode & 07777 & pred_ptr->args.perm)
- == (pred_ptr->args.perm & 07777))
- return (true);
+ case PERM_AT_LEAST:
+ return (mode & perm_val) == perm_val;
+ break;
+
+ case PERM_ANY:
+ /* True if any of the bits set in the mask are also set in the file's mode.
+ *
+ *
+ * Otherwise, if onum is prefixed by a hyphen, the primary shall
+ * evaluate as true if at least all of the bits specified in
+ * onum that are also set in the octal mask 07777 are set.
+ *
+ * Eric Blake's interpretation is that the mode argument is zero,
+
+ */
+ if (0 == perm_val)
+ return true; /* Savannah bug 14748; we used to return false */
+ else
+ return (mode & perm_val) != 0;
+ break;
+
+ case PERM_EXACT:
+ return (mode & MODE_ALL) == perm_val;
+ break;
+
+ default:
+ abort ();
+ break;
}
- else if (pred_ptr->args.perm & 020000)
- {
- /* Magic flag set in parse_perm:
- true if any of the given bits are set. */
- if ((stat_buf->st_mode & 07777) & pred_ptr->args.perm)
- return (true);
- }
- else
- {
- /* True if exactly the given bits are set. */
- if ((stat_buf->st_mode & 07777) == pred_ptr->args.perm)
- return (true);
- }
- return (false);
}
boolean
-pred_print (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_print (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- puts (pathname);
- return (true);
+ (void) stat_buf;
+ (void) pred_ptr;
+ /* puts (pathname); */
+ print_quoted(pred_ptr->args.printf_vec.stream,
+ pred_ptr->args.printf_vec.quote_opts,
+ pred_ptr->args.printf_vec.dest_is_tty,
+ "%s\n", pathname);
+ return true;
}
boolean
-pred_print0 (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_print0 (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) stat_buf;
+ (void) pred_ptr;
fputs (pathname, stdout);
putc (0, stdout);
return (true);
}
boolean
-pred_prune (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_prune (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- stop_at_current_level = true;
- return (do_dir_first); /* This is what SunOS find seems to do. */
+ (void) pathname;
+ (void) stat_buf;
+ (void) pred_ptr;
+ state.stop_at_current_level = true;
+ return (options.do_dir_first); /* This is what SunOS find seems to do. */
}
boolean
-pred_regex (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_quit (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ (void) pathname;
+ (void) stat_buf;
+ (void) pred_ptr;
+
+ /* Run any cleanups. This includes executing any command lines
+ * we have partly built but not executed.
+ */
+ cleanup();
+
+ /* Since -exec and friends don't leave child processes running in the
+ * background, there is no need to wait for them here.
+ */
+ exit(state.exit_status); /* 0 for success, etc. */
+}
+
+boolean
+pred_regex (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
int len = strlen (pathname);
+(void) stat_buf;
if (re_match (pred_ptr->args.regex, pathname, len, 0,
(struct re_registers *) NULL) == len)
return (true);
@@ -1141,15 +1336,13 @@ pred_regex (pathname, stat_buf, pred_ptr)
}
boolean
-pred_size (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_size (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- unsigned long f_val;
+ uintmax_t f_val;
- f_val = (stat_buf->st_size + pred_ptr->args.size.blocksize - 1)
- / pred_ptr->args.size.blocksize;
+ (void) pathname;
+ f_val = ((stat_buf->st_size / pred_ptr->args.size.blocksize)
+ + (stat_buf->st_size % pred_ptr->args.size.blocksize != 0));
switch (pred_ptr->args.size.kind)
{
case COMP_GT:
@@ -1169,22 +1362,46 @@ pred_size (pathname, stat_buf, pred_ptr)
}
boolean
-pred_true (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_samefile (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- return (true);
+ /* Potential optimisation: because of the loop protection, we always
+ * know the device of the current directory, hence the device number
+ * of the file we're currently considering. If -L is not in effect,
+ * and the device number of the file we're looking for is not the
+ * same as the device number of the current directory, this
+ * predicate cannot return true. Hence there would be no need to
+ * stat the file we're lookingn at.
+ */
+ (void) pathname;
+
+ return stat_buf->st_ino == pred_ptr->args.fileid.ino
+ && stat_buf->st_dev == pred_ptr->args.fileid.dev;
}
boolean
-pred_type (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_true (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- unsigned long mode = stat_buf->st_mode;
- unsigned long type = pred_ptr->args.type;
+ (void) pathname;
+ (void) stat_buf;
+ (void) pred_ptr;
+ return true;
+}
+
+boolean
+pred_type (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
+{
+ mode_t mode;
+ mode_t type = pred_ptr->args.type;
+
+ assert(state.have_type);
+ assert(state.type != 0);
+
+ (void) pathname;
+
+ if (state.have_stat)
+ mode = stat_buf->st_mode;
+ else
+ mode = state.type;
#ifndef S_IFMT
/* POSIX system; check `mode' the slow way. */
@@ -1200,6 +1417,9 @@ pred_type (pathname, stat_buf, pred_ptr)
#endif
#ifdef S_IFSOCK
|| (S_ISSOCK (mode) && type == S_IFSOCK)
+#endif
+#ifdef S_IFDOOR
+ || (S_ISDOOR (mode) && type == S_IFDOOR)
#endif
)
#else /* S_IFMT */
@@ -1212,11 +1432,9 @@ pred_type (pathname, stat_buf, pred_ptr)
}
boolean
-pred_uid (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_uid (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
switch (pred_ptr->args.info.kind)
{
case COMP_GT:
@@ -1236,39 +1454,19 @@ pred_uid (pathname, stat_buf, pred_ptr)
}
boolean
-pred_used (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_used (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
time_t delta;
+ (void) pathname;
delta = stat_buf->st_atime - stat_buf->st_ctime; /* Use difftime? */
- switch (pred_ptr->args.info.kind)
- {
- case COMP_GT:
- if (delta > (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_LT:
- if (delta < (time_t) pred_ptr->args.info.l_val)
- return (true);
- break;
- case COMP_EQ:
- if ((delta >= (time_t) pred_ptr->args.info.l_val)
- && (delta < (time_t) pred_ptr->args.info.l_val + DAYSECS))
- return (true);
- break;
- }
- return (false);
+ return pred_timewindow(delta, pred_ptr, DAYSECS);
}
boolean
-pred_user (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_user (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
+ (void) pathname;
if (pred_ptr->args.uid == stat_buf->st_uid)
return (true);
else
@@ -1276,24 +1474,39 @@ pred_user (pathname, stat_buf, pred_ptr)
}
boolean
-pred_xtype (pathname, stat_buf, pred_ptr)
- char *pathname;
- struct stat *stat_buf;
- struct predicate *pred_ptr;
+pred_xtype (char *pathname, struct stat *stat_buf, struct predicate *pred_ptr)
{
- struct stat sbuf;
- int (*ystat) ();
+ struct stat sbuf; /* local copy, not stat_buf because we're using a different stat method */
+ int (*ystat) (const char*, struct stat *p);
- ystat = xstat == lstat ? stat : lstat;
- if ((*ystat) (rel_pathname, &sbuf) != 0)
+ /* If we would normally stat the link itself, stat the target instead.
+ * If we would normally follow the link, stat the link itself instead.
+ */
+ if (following_links())
+ ystat = optionp_stat;
+ else
+ ystat = optionl_stat;
+
+ if ((*ystat) (state.rel_pathname, &sbuf) != 0)
{
- if (ystat == stat && errno == ENOENT)
- /* Mimic behavior of ls -lL. */
- return (pred_type (pathname, stat_buf, pred_ptr));
- error (0, errno, "%s", pathname);
- exit_status = 1;
- return (false);
+ if (following_links() && errno == ENOENT)
+ {
+ /* If we failed to follow the symlink,
+ * fall back on looking at the symlink itself.
+ */
+ /* Mimic behavior of ls -lL. */
+ return (pred_type (pathname, stat_buf, pred_ptr));
+ }
+ else
+ {
+ error (0, errno, "%s", pathname);
+ state.exit_status = 1;
+ }
+ return false;
}
+ /* Now that we have our stat() information, query it in the same
+ * way that -type does.
+ */
return (pred_type (pathname, &sbuf, pred_ptr));
}
@@ -1315,21 +1528,46 @@ pred_xtype (pathname, stat_buf, pred_ptr)
zero, and the exit arg (status high) is 0.
Otherwise return false, possibly printing an error message. */
-static boolean
-launch (pred_ptr)
- struct predicate *pred_ptr;
+
+static void
+prep_child_for_exec (boolean close_stdin)
{
- int status;
- pid_t wait_ret, child_pid;
- struct exec_val *execp; /* Pointer for efficiency. */
+ if (close_stdin)
+ {
+ const char inputfile[] = "/dev/null";
+ /* fprintf(stderr, "attaching stdin to /dev/null\n"); */
+
+ close(0);
+ if (open(inputfile, O_RDONLY) < 0)
+ {
+ /* This is not entirely fatal, since
+ * executing the child with a closed
+ * stdin is almost as good as executing it
+ * with its stdin attached to /dev/null.
+ */
+ error (0, errno, "%s", inputfile);
+ }
+ }
+}
+
+
+
+int
+launch (const struct buildcmd_control *ctl,
+ struct buildcmd_state *buildstate)
+{
+ int wait_status;
+ pid_t child_pid;
static int first_time = 1;
-
- execp = &pred_ptr->args.exec_vec;
-
+ const struct exec_val *execp = buildstate->usercontext;
+
+ /* Null terminate the arg list. */
+ bc_push_arg (ctl, buildstate, (char *) NULL, 0, NULL, 0, false);
+
/* Make sure output of command doesn't get mixed with find output. */
fflush (stdout);
fflush (stderr);
-
+
/* Make sure to listen for the kids. */
if (first_time)
{
@@ -1339,83 +1577,137 @@ launch (pred_ptr)
child_pid = fork ();
if (child_pid == -1)
- error (1, errno, "cannot fork");
+ error (1, errno, _("cannot fork"));
if (child_pid == 0)
{
/* We be the child. */
-#ifndef HAVE_FCHDIR
- if (chdir (starting_dir) < 0)
+ prep_child_for_exec(execp->close_stdin);
+
+ /* For -exec and -ok, change directory back to the starting directory.
+ * for -execdir and -okdir, stay in the directory we are searching
+ * (the latter is more secure).
+ */
+ if (!execp->use_current_dir)
{
- error (0, errno, "%s", starting_dir);
- _exit (1);
+ /* Even if DEBUG_STAT is set, don't announce our change of
+ * directory, since we're not going to emit a subsequent
+ * announcement of a call to stat() anyway, as we're about
+ * to exec something.
+ */
+ if (starting_desc < 0
+ ? chdir (starting_dir) != 0
+ : fchdir (starting_desc) != 0)
+ {
+ error (0, errno, "%s", starting_dir);
+ _exit (1);
+ }
}
-#else
- if (fchdir (starting_desc) < 0)
- {
- error (0, errno, "cannot return to starting directory");
- _exit (1);
- }
-#endif
- execvp (execp->vec[0], execp->vec);
- error (0, errno, "%s", execp->vec[0]);
+
+ execvp (buildstate->cmd_argv[0], buildstate->cmd_argv);
+ error (0, errno, "%s", buildstate->cmd_argv[0]);
_exit (1);
}
- wait_ret = wait (&status);
- if (wait_ret == -1)
+
+ /* In parent; set up for next time. */
+ bc_clear_args(ctl, buildstate);
+
+
+ while (waitpid (child_pid, &wait_status, 0) == (pid_t) -1)
{
- error (0, errno, "error waiting for %s", execp->vec[0]);
- exit_status = 1;
- return (false);
+ if (errno != EINTR)
+ {
+ error (0, errno, _("error waiting for %s"), buildstate->cmd_argv[0]);
+ state.exit_status = 1;
+ return 0; /* FAIL */
+ }
}
- if (wait_ret != child_pid)
+
+ if (WIFSIGNALED (wait_status))
{
- error (0, 0, "wait got pid %d, expected pid %d", wait_ret, child_pid);
- exit_status = 1;
- return (false);
+ error (0, 0, _("%s terminated by signal %d"),
+ buildstate->cmd_argv[0], WTERMSIG (wait_status));
+
+ if (execp->multiple)
+ {
+ /* -exec \; just returns false if the invoked command fails.
+ * -exec {} + returns true if the invoked command fails, but
+ * sets the program exit status.
+ */
+ state.exit_status = 1;
+ }
+
+ return 1; /* OK */
}
- if (WIFSTOPPED (status))
+
+ if (0 == WEXITSTATUS (wait_status))
{
- error (0, 0, "%s stopped by signal %d",
- execp->vec[0], WSTOPSIG (status));
- exit_status = 1;
- return (false);
+ return 1; /* OK */
}
- if (WIFSIGNALED (status))
+ else
{
- error (0, 0, "%s terminated by signal %d",
- execp->vec[0], WTERMSIG (status));
- exit_status = 1;
- return (false);
+ if (execp->multiple)
+ {
+ /* -exec \; just returns false if the invoked command fails.
+ * -exec {} + returns true if the invoked command fails, but
+ * sets the program exit status.
+ */
+ state.exit_status = 1;
+ }
+ return 0; /* FAIL */
}
- return (!WEXITSTATUS (status));
+
}
+
/* Return a static string formatting the time WHEN according to the
strftime format character KIND. */
static char *
-format_date (when, kind)
- time_t when;
- int kind;
+format_date (time_t when, int kind)
{
- static char fmt[3];
- static char buf[64]; /* More than enough space. */
+ static char buf[MAX (LONGEST_HUMAN_READABLE + 2, 64)];
+ struct tm *tm;
+ char fmt[6];
- if (kind == '@')
+ fmt[0] = '%';
+ fmt[1] = kind;
+ fmt[2] = '\0';
+ if (kind == '+')
+ strcpy (fmt, "%F+%T");
+
+ if (kind != '@'
+ && (tm = localtime (&when))
+ && strftime (buf, sizeof buf, fmt, tm))
+ return buf;
+ else
{
- sprintf (buf, "%ld", when);
- return (buf);
+ uintmax_t w = when;
+ char *p = human_readable (when < 0 ? -w : w, buf + 1,
+ human_ceiling, 1, 1);
+ if (when < 0)
+ *--p = '-';
+ return p;
+ }
+}
+
+static char *
+ctime_format (time_t when)
+{
+ char *r = ctime (&when);
+ if (!r)
+ {
+ /* The time cannot be represented as a struct tm.
+ Output it as an integer. */
+ return format_date (when, '@');
}
else
{
- fmt[0] = '%';
- fmt[1] = kind;
- fmt[2] = '\0';
- if (strftime (buf, sizeof (buf), fmt, localtime (&when)))
- return (buf);
+ /* Remove the trailing newline from the ctime output,
+ being careful not to assume that the output is fixed-width. */
+ *strchr (r, '\n') = '\0';
+ return r;
}
- return "";
}
#ifdef DEBUG
@@ -1462,27 +1754,45 @@ prec_name (prec)
INDENT is the number of levels to indent the left margin. */
void
-print_tree (node, indent)
- struct predicate *node;
- int indent;
+print_tree (FILE *fp, struct predicate *node, int indent)
{
int i;
if (node == NULL)
return;
for (i = 0; i < indent; i++)
- printf (" ");
- printf ("pred = %s type = %s prec = %s addr = %x\n",
+ fprintf (fp, " ");
+ fprintf (fp, "pred = %s type = %s prec = %s addr = %p\n",
find_pred_name (node->pred_func),
type_name (node->p_type), prec_name (node->p_prec), node);
+ if (node->need_stat || node->need_type)
+ {
+ int comma = 0;
+
+ for (i = 0; i < indent; i++)
+ fprintf (fp, " ");
+
+ fprintf (fp, "Needs ");
+ if (node->need_stat)
+ {
+ fprintf (fp, "stat");
+ comma = 1;
+ }
+ if (node->need_type)
+ {
+ fprintf (fp, "%stype", comma ? "," : "");
+ }
+ fprintf (fp, "\n");
+ }
+
for (i = 0; i < indent; i++)
- printf (" ");
- printf ("left:\n");
- print_tree (node->pred_left, indent + 1);
+ fprintf (fp, " ");
+ fprintf (fp, "left:\n");
+ print_tree (fp, node->pred_left, indent + 1);
for (i = 0; i < indent; i++)
- printf (" ");
- printf ("right:\n");
- print_tree (node->pred_right, indent + 1);
+ fprintf (fp, " ");
+ fprintf (fp, "right:\n");
+ print_tree (fp, node->pred_right, indent + 1);
}
/* Copy STR into BUF and trim blanks from the end of BUF.
@@ -1508,8 +1818,7 @@ blank_rtrim (str, buf)
/* Print out the predicate list starting at NODE. */
void
-print_list (node)
- struct predicate *node;
+print_list (FILE *fp, struct predicate *node)
{
struct predicate *cur;
char name[256];
@@ -1517,9 +1826,126 @@ print_list (node)
cur = node;
while (cur != NULL)
{
- printf ("%s ", blank_rtrim (find_pred_name (cur->pred_func), name));
+ fprintf (fp, "%s ", blank_rtrim (find_pred_name (cur->pred_func), name));
cur = cur->pred_next;
}
- printf ("\n");
+ fprintf (fp, "\n");
}
+
+
+/* Print out the predicate list starting at NODE. */
+
+
+static void
+print_parenthesised(FILE *fp, struct predicate *node)
+{
+ int parens = 0;
+
+ if (node)
+ {
+ if ( ( (node->pred_func == pred_or)
+ || (node->pred_func == pred_and) )
+ && node->pred_left == NULL)
+ {
+ /* We print " or X" as just "X"
+ * We print " and X" as just "X"
+ */
+ print_parenthesised(fp, node->pred_right);
+ }
+ else
+ {
+ if (node->pred_left || node->pred_right)
+ parens = 1;
+
+ if (parens)
+ fprintf(fp, "%s", " ( ");
+ print_optlist(fp, node);
+ if (parens)
+ fprintf(fp, "%s", " ) ");
+ }
+ }
+}
+
+void
+print_optlist (FILE *fp, struct predicate *p)
+{
+ char name[256];
+
+ if (p)
+ {
+ print_parenthesised(fp, p->pred_left);
+ fprintf (fp,
+ "%s%s%s ",
+ p->need_stat ? "[stat called here] " : "",
+ p->need_type ? "[type needed here] " : "",
+ blank_rtrim (find_pred_name (p->pred_func), name));
+ print_parenthesised(fp, p->pred_right);
+ }
+}
+
#endif /* DEBUG */
+
+
+void
+pred_sanity_check(const struct predicate *predicates)
+{
+ const struct predicate *p;
+
+ for (p=predicates; p != NULL; p=p->pred_next)
+ {
+ /* All predicates must do something. */
+ assert(p->pred_func != NULL);
+
+ /* All predicates must have a parser table entry. */
+ assert(p->parser_entry != NULL);
+
+ /* If the parser table tells us that just one predicate function is
+ * possible, verify that that is still the one that is in effect.
+ * If the parser has NULL for the predicate function, that means that
+ * the parse_xxx function fills it in, so we can't check it.
+ */
+ if (p->parser_entry->pred_func)
+ {
+ assert(p->parser_entry->pred_func == p->pred_func);
+ }
+
+ switch (p->parser_entry->type)
+ {
+ /* Options all take effect during parsing, so there should
+ * be no predicate entries corresponding to them. Hence we
+ * should not see any ARG_OPTION or ARG_POSITIONAL_OPTION
+ * items.
+ *
+ * This is a silly way of coding this test, but it prevents
+ * a compiler warning (i.e. otherwise it would think that
+ * there would be case statements missing).
+ */
+ case ARG_OPTION:
+ case ARG_POSITIONAL_OPTION:
+ assert(p->parser_entry->type != ARG_OPTION);
+ assert(p->parser_entry->type != ARG_POSITIONAL_OPTION);
+ break;
+
+ case ARG_ACTION:
+ assert(p->side_effects); /* actions have side effects. */
+ if (p->pred_func != pred_prune && p->pred_func != pred_quit)
+ {
+ /* actions other than -prune and -quit should
+ * inhibit the default -print
+ */
+ assert(p->no_default_print);
+ }
+ break;
+
+ case ARG_PUNCTUATION:
+ case ARG_TEST:
+ /* Punctuation and tests should have no side
+ * effects and not inhibit default print.
+ */
+ assert(!p->no_default_print);
+ assert(!p->side_effects);
+ break;
+
+ }
+ }
+}
diff --git a/src/bin/findutils/find/tree.c b/src/bin/findutils/find/tree.c
index 220924278c..1acd142695 100644
--- a/src/bin/findutils/find/tree.c
+++ b/src/bin/findutils/find/tree.c
@@ -1,29 +1,41 @@
/* tree.c -- helper functions to build and evaluate the expression tree.
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 91, 92, 93, 94, 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see .
+*/
-#include
-#include
-#include
-#include
#include "defs.h"
+#include "../gnulib/lib/xalloc.h"
-static struct predicate *scan_rest P_((struct predicate **input, struct predicate *head, int prev_prec));
-static void merge_pred P_((struct predicate *beg_list, struct predicate *end_list, struct predicate **last_p));
-static struct predicate *set_new_parent P_((struct predicate *curr, enum predicate_precedence high_prec, struct predicate **prevp));
+#if ENABLE_NLS
+# include
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
+#endif
+
+static struct predicate *scan_rest PARAMS((struct predicate **input,
+ struct predicate *head,
+ short int prev_prec));
+static void merge_pred PARAMS((struct predicate *beg_list, struct predicate *end_list, struct predicate **last_p));
+static struct predicate *set_new_parent PARAMS((struct predicate *curr, enum predicate_precedence high_prec, struct predicate **prevp));
/* Return a pointer to a tree that represents the
expression prior to non-unary operator *INPUT.
@@ -45,20 +57,25 @@ static struct predicate *set_new_parent P_((struct predicate *curr, enum predica
our caller, so get_expr recurses. */
struct predicate *
-get_expr (input, prev_prec)
- struct predicate **input;
- short prev_prec;
+get_expr (struct predicate **input, short int prev_prec)
{
- struct predicate *next;
+ struct predicate *next = NULL;
if (*input == NULL)
- error (1, 0, "invalid expression");
+ error (1, 0, _("invalid expression"));
+
switch ((*input)->p_type)
{
case NO_TYPE:
+ error (1, 0, _("invalid expression"));
+ break;
+
case BI_OP:
+ error (1, 0, _("invalid expression; you have used a binary operator with nothing before it."));
+ break;
+
case CLOSE_PAREN:
- error (1, 0, "invalid expression");
+ error (1, 0, _("invalid expression; you have too many ')'"));
break;
case PRIMARY_TYPE:
@@ -77,12 +94,12 @@ get_expr (input, prev_prec)
next = get_expr (input, NO_PREC);
if ((*input == NULL)
|| ((*input)->p_type != CLOSE_PAREN))
- error (1, 0, "invalid expression");
+ error (1, 0, _("invalid expression; I was expecting to find a ')' somewhere but did not see one."));
*input = (*input)->pred_next; /* move over close */
break;
default:
- error (1, 0, "oops -- invalid expression type!");
+ error (1, 0, _("oops -- invalid expression type!"));
break;
}
@@ -97,7 +114,7 @@ get_expr (input, prev_prec)
{
next = scan_rest (input, next, prev_prec);
if (next == NULL)
- error (1, 0, "invalid expression");
+ error (1, 0, _("invalid expression"));
}
return (next);
}
@@ -116,10 +133,9 @@ get_expr (input, prev_prec)
PREV_PREC is the precedence of the previous predicate element. */
static struct predicate *
-scan_rest (input, head, prev_prec)
- struct predicate **input;
- struct predicate *head;
- short prev_prec;
+scan_rest (struct predicate **input,
+ struct predicate *head,
+ short int prev_prec)
{
struct predicate *tree; /* The new tree we are building. */
@@ -134,7 +150,10 @@ scan_rest (input, head, prev_prec)
case PRIMARY_TYPE:
case UNI_OP:
case OPEN_PAREN:
- error (1, 0, "invalid expression");
+ /* I'm not sure how we get here, so it is not obvious what
+ * sort of mistakes might give rise to this condition.
+ */
+ error (1, 0, _("invalid expression"));
break;
case BI_OP:
@@ -145,14 +164,16 @@ scan_rest (input, head, prev_prec)
break;
case CLOSE_PAREN:
- return (tree);
+ return tree;
default:
- error (1, 0, "oops -- invalid expression type!");
+ error (1, 0,
+ _("oops -- invalid expression type (%d)!"),
+ (int)(*input)->p_type);
break;
}
}
- return (tree);
+ return tree;
}
/* Optimize the ordering of the predicates in the tree. Rearrange
@@ -162,9 +183,12 @@ scan_rest (input, head, prev_prec)
predicates (if any) which have "side effects", such as printing.
The grouping implements the partial ordering on predicates which
those with side effects impose.
- * Place -name, -path, and -regex at the front of a group, with
- -name and -path ahead of -regex. Predicates that are moved to the
- front of a group by definition do not have side effects.
+
+ * Place -name, -iname, -path, -ipath, -regex and -iregex at the front
+ of a group, with -name, -iname, -path and -ipath ahead of
+ -regex and -iregex. Predicates which are moved to the front
+ of a group by definition do not have side effects. Both
+ -regex and -iregex both use pred_regex.
This routine "normalizes" the predicate tree by ensuring that
all expression predicates have AND (or OR or COMMA) parent nodes
@@ -176,8 +200,7 @@ scan_rest (input, head, prev_prec)
Return true if the tree contains side effects, false if not. */
boolean
-opt_expr (eval_treep)
- struct predicate **eval_treep;
+opt_expr (struct predicate **eval_treep)
{
/* List of -name and -path predicates to move. */
struct predicate *name_list = NULL;
@@ -188,7 +211,7 @@ opt_expr (eval_treep)
struct predicate *curr;
struct predicate **prevp; /* Address of `curr' node. */
struct predicate **last_sidep; /* Last predicate with side effects. */
- PFB pred_func;
+ PRED_FUNC pred_func;
enum predicate_type p_type;
boolean has_side_effects = false; /* Return value. */
enum predicate_precedence prev_prec, /* precedence of last BI_OP in branch */
@@ -217,12 +240,13 @@ opt_expr (eval_treep)
#ifdef DEBUG
/* Normalized tree. */
- printf ("Normalized Eval Tree:\n");
- print_tree (*eval_treep, 0);
+ fprintf (stderr, "Normalized Eval Tree:\n");
+ print_tree (stderr, *eval_treep, 0);
#endif
/* Rearrange the predicates. */
prevp = eval_treep;
+ biop_prec = NO_PREC; /* not COMMA_PREC */
if ((*prevp) && (*prevp)->p_type == BI_OP)
biop_prec = (*prevp)->p_prec;
while ((curr = *prevp) != NULL)
@@ -237,8 +261,6 @@ opt_expr (eval_treep)
{
if (curr->p_prec != biop_prec)
curr = set_new_parent(curr, biop_prec, prevp);
- else
- biop_prec = curr->p_prec;
}
/* See which predicate type we have. */
@@ -249,9 +271,15 @@ opt_expr (eval_treep)
{
case NO_TYPE:
case PRIMARY_TYPE:
+ /* Don't rearrange the arguments of the comma operator, it is
+ not commutative. */
+ if (biop_prec == COMMA_PREC)
+ break;
+
/* If it's one of our special primaries, move it to the
front of the list for that primary. */
- if (pred_func == pred_name || pred_func == pred_path)
+ if (pred_func == pred_name || pred_func == pred_path ||
+ pred_func == pred_iname || pred_func == pred_ipath)
{
*prevp = curr->pred_left;
curr->pred_left = name_list;
@@ -293,7 +321,7 @@ opt_expr (eval_treep)
all of the user's parentheses. */
default:
- error (1, 0, "oops -- invalid expression type!");
+ error (1, 0, _("oops -- invalid expression type!"));
break;
}
@@ -334,10 +362,7 @@ opt_expr (eval_treep)
HIGH_PREC. */
static struct predicate *
-set_new_parent (curr, high_prec, prevp)
- struct predicate *curr;
- enum predicate_precedence high_prec;
- struct predicate **prevp;
+set_new_parent (struct predicate *curr, enum predicate_precedence high_prec, struct predicate **prevp)
{
struct predicate *new_parent;
@@ -345,6 +370,7 @@ set_new_parent (curr, high_prec, prevp)
new_parent->p_type = BI_OP;
new_parent->p_prec = high_prec;
new_parent->need_stat = false;
+ new_parent->need_type = false;
switch (high_prec)
{
@@ -362,6 +388,7 @@ set_new_parent (curr, high_prec, prevp)
}
new_parent->side_effects = false;
+ new_parent->no_default_print = false;
new_parent->args.str = NULL;
new_parent->pred_next = NULL;
@@ -382,8 +409,7 @@ set_new_parent (curr, high_prec, prevp)
into the tree at LAST_P. */
static void
-merge_pred (beg_list, end_list, last_p)
- struct predicate *beg_list, *end_list, **last_p;
+merge_pred (struct predicate *beg_list, struct predicate *end_list, struct predicate **last_p)
{
end_list->pred_left = *last_p;
*last_p = beg_list;
@@ -400,8 +426,7 @@ merge_pred (beg_list, end_list, last_p)
in TREE requires a stat, false if not. */
boolean
-mark_stat (tree)
- struct predicate *tree;
+mark_stat (struct predicate *tree)
{
/* The tree is executed in-order, so walk this way (apologies to Aerosmith)
to find the first predicate for which the stat is needed. */
@@ -427,7 +452,44 @@ mark_stat (tree)
return (false);
default:
- error (1, 0, "oops -- invalid expression type!");
+ error (1, 0, _("oops -- invalid expression type in mark_stat!"));
return (false);
}
}
+
+/* Find the first node in expression tree TREE that we will
+ need to know the file type, if any. Operates in the same
+ was as mark_stat().
+*/
+boolean
+mark_type (struct predicate *tree)
+{
+ /* The tree is executed in-order, so walk this way (apologies to Aerosmith)
+ to find the first predicate for which the type information is needed. */
+ switch (tree->p_type)
+ {
+ case NO_TYPE:
+ case PRIMARY_TYPE:
+ return tree->need_type;
+
+ case UNI_OP:
+ if (mark_type (tree->pred_right))
+ tree->need_type = true;
+ return false;
+
+ case BI_OP:
+ /* ANDs and ORs are linked along ->left ending in NULL. */
+ if (tree->pred_left != NULL)
+ mark_type (tree->pred_left);
+
+ if (mark_type (tree->pred_right))
+ tree->need_type = true;
+
+ return false;
+
+ default:
+ error (1, 0, _("oops -- invalid expression type in mark_type!"));
+ return (false);
+ }
+}
+
diff --git a/src/bin/findutils/find/util.c b/src/bin/findutils/find/util.c
index 95ce57e08e..45188f23d1 100644
--- a/src/bin/findutils/find/util.c
+++ b/src/bin/findutils/find/util.c
@@ -1,43 +1,38 @@
/* util.c -- functions for initializing new tree elements, and other things.
- Copyright (C) 1990, 91, 92, 93, 94 Free Software Foundation, Inc.
+ Copyright (C) 1990, 91, 92, 93, 94, 2000, 2001, 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
- This program is free software; you can redistribute it and/or modify
+ This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2, or (at your option)
- any later version.
-
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
-
+
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+ along with this program. If not, see .
+*/
-#include
-#include
-#include
-#include
#include "defs.h"
-
-/* Return the last component of pathname FNAME, with leading slashes
- compressed into one slash. */
+#include "xalloc.h"
-char *
-basename (fname)
- char *fname;
-{
- char *p;
+#if ENABLE_NLS
+# include
+# define _(Text) gettext (Text)
+#else
+# define _(Text) Text
+#endif
+#ifdef gettext_noop
+# define N_(String) gettext_noop (String)
+#else
+/* See locate.c for explanation as to why not use (String) */
+# define N_(String) String
+#endif
+
+#include
- /* For "/", "//", etc., return "/". */
- for (p = fname; *p == '/'; ++p)
- /* Do nothing. */ ;
- if (*p == '\0')
- return p - 1;
- p = strrchr (fname, '/');
- return (p == NULL ? fname : p + 1);
-}
/* Return a pointer to a new predicate structure, which has been
linked in as the last one in the predicates list.
@@ -48,10 +43,15 @@ basename (fname)
Set all cells in the new structure to the default values. */
struct predicate *
-get_new_pred ()
+get_new_pred (const struct parser_table *entry)
{
register struct predicate *new_pred;
+ (void) entry;
+ /* Options should not be turned into predicates. */
+ assert(entry->type != ARG_OPTION);
+ assert(entry->type != ARG_POSITIONAL_OPTION);
+
if (predicates == NULL)
{
predicates = (struct predicate *)
@@ -64,6 +64,7 @@ get_new_pred ()
last_pred->pred_next = new_pred;
last_pred = new_pred;
}
+ last_pred->parser_entry = entry;
last_pred->pred_func = NULL;
#ifdef DEBUG
last_pred->p_name = NULL;
@@ -71,7 +72,9 @@ get_new_pred ()
last_pred->p_type = NO_TYPE;
last_pred->p_prec = NO_PREC;
last_pred->side_effects = false;
+ last_pred->no_default_print = false;
last_pred->need_stat = true;
+ last_pred->need_type = true;
last_pred->args.str = NULL;
last_pred->pred_next = NULL;
last_pred->pred_left = NULL;
@@ -84,20 +87,29 @@ get_new_pred ()
predicate is an operator. If it isn't, the AND operator is inserted. */
struct predicate *
-get_new_pred_chk_op ()
+get_new_pred_chk_op (const struct parser_table *entry)
{
struct predicate *new_pred;
+ static const struct parser_table *entry_and = NULL;
+
+ /* Locate the entry in the parser table for the "and" operator */
+ if (NULL == entry_and)
+ entry_and = find_parser("and");
+
+ /* Check that it's actually there. If not, that is a bug.*/
+ assert(entry_and != NULL);
if (last_pred)
switch (last_pred->p_type)
{
case NO_TYPE:
- error (1, 0, "oops -- invalid default insertion of and!");
+ error (1, 0, _("oops -- invalid default insertion of and!"));
break;
case PRIMARY_TYPE:
case CLOSE_PAREN:
- new_pred = get_new_pred ();
+ /* We need to interpose the and operator. */
+ new_pred = get_new_pred (entry_and);
new_pred->pred_func = pred_and;
#ifdef DEBUG
new_pred->p_name = find_pred_name (pred_and);
@@ -105,15 +117,22 @@ get_new_pred_chk_op ()
new_pred->p_type = BI_OP;
new_pred->p_prec = AND_PREC;
new_pred->need_stat = false;
+ new_pred->need_type = false;
new_pred->args.str = NULL;
+ new_pred->side_effects = false;
+ new_pred->no_default_print = false;
+ break;
default:
break;
}
- return (get_new_pred ());
+
+ new_pred = get_new_pred (entry);
+ new_pred->parser_entry = entry;
+ return new_pred;
}
-/* Add a primary of predicate type PRED_FUNC to the predicate input list.
+/* Add a primary of predicate type PRED_FUNC (described by ENTRY) to the predicate input list.
Return a pointer to the predicate node just inserted.
@@ -130,29 +149,51 @@ get_new_pred_chk_op ()
operator. */
struct predicate *
-insert_primary (pred_func)
- boolean (*pred_func) ();
+insert_primary_withpred (const struct parser_table *entry, PRED_FUNC pred_func)
{
struct predicate *new_pred;
- new_pred = get_new_pred_chk_op ();
+ new_pred = get_new_pred_chk_op (entry);
new_pred->pred_func = pred_func;
#ifdef DEBUG
- new_pred->p_name = find_pred_name (pred_func);
+ new_pred->p_name = entry->parser_name;
#endif /* DEBUG */
new_pred->args.str = NULL;
new_pred->p_type = PRIMARY_TYPE;
new_pred->p_prec = NO_PREC;
- return (new_pred);
+ return new_pred;
}
+
+/* Add a primary described by ENTRY to the predicate input list.
+
+ Return a pointer to the predicate node just inserted.
+
+ Fills in the following cells of the new predicate node:
+
+ pred_func PRED_FUNC
+ args(.str) NULL
+ p_type PRIMARY_TYPE
+ p_prec NO_PREC
+
+ Other cells that need to be filled in are defaulted by
+ get_new_pred_chk_op, which is used to insure that the prior node is
+ either not there at all (we are the very first node) or is an
+ operator. */
+struct predicate *
+insert_primary (const struct parser_table *entry)
+{
+ assert(entry->pred_func != NULL);
+ return insert_primary_withpred(entry, entry->pred_func);
+}
+
+
void
-usage (msg)
- char *msg;
+usage (char *msg)
{
if (msg)
fprintf (stderr, "%s: %s\n", program_name, msg);
- fprintf (stderr, "\
-Usage: %s [path...] [expression]\n", program_name);
+ fprintf (stderr, _("\
+Usage: %s [-H] [-L] [-P] [path...] [expression]\n"), program_name);
exit (1);
}
diff --git a/src/bin/findutils/find/version.c b/src/bin/findutils/find/version.c
index 460883ff22..c833c5bf5a 100644
--- a/src/bin/findutils/find/version.c
+++ b/src/bin/findutils/find/version.c
@@ -1 +1,3 @@
-char *version_string = "4.1";
+#include
+char *version_string = VERSION;
+
diff --git a/src/bin/findutils/findutils.rdef b/src/bin/findutils/findutils.rdef
index 613d1262eb..db94cdabc6 100644
--- a/src/bin/findutils/findutils.rdef
+++ b/src/bin/findutils/findutils.rdef
@@ -1,11 +1,11 @@
resource app_version
{
major = 4,
- middle = 1,
- minor = 0,
+ middle = 2,
+ minor = 33,
variety = 5,
internal = 0,
- short_info = "4.1",
- long_info = "4.1 ©1994 The Free Software Foundation"
+ short_info = "4.2.33",
+ long_info = "4.2.33 ©2008 The Free Software Foundation"
};
diff --git a/src/bin/findutils/gnulib/Jamfile b/src/bin/findutils/gnulib/Jamfile
new file mode 100644
index 0000000000..2a96672c77
--- /dev/null
+++ b/src/bin/findutils/gnulib/Jamfile
@@ -0,0 +1,3 @@
+SubDir HAIKU_TOP src bin findutils gnulib ;
+
+SubInclude HAIKU_TOP src bin findutils gnulib lib ;
diff --git a/src/bin/findutils/gnulib/lib/Jamfile b/src/bin/findutils/gnulib/lib/Jamfile
new file mode 100644
index 0000000000..57b6a7c673
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/Jamfile
@@ -0,0 +1,58 @@
+SubDir HAIKU_TOP src bin findutils gnulib lib ;
+
+SubDirSysHdrs [ FDirName $(SUBDIR) ] ;
+SubDirSysHdrs [ FDirName $(SUBDIR) $(DOTDOT) $(DOTDOT) ] ;
+
+# filter warnings we don't want here
+TARGET_WARNING_CCFLAGS = [ FFilter $(TARGET_WARNING_CCFLAGS)
+ : -Wall -Wmissing-prototypes -Wsign-compare ] ;
+
+# set some additional defines
+{
+ SubDirCcFlags -DHAVE_CONFIG_H ;
+}
+
+
+StaticLibrary gnulibfindutils.a :
+ areadlink-with-size.c
+ argmatch.c
+ basename.c
+ canonicalize.c
+ closein.c
+ closeout.c
+ close-stream.c
+ dirname.c
+ dup-safer.c
+ error.c
+ exitfail.c
+ filemode.c
+ file-set.c
+ fnmatch.c
+ fopen-safer.c
+ fpending.c
+ freadahead.c
+ getcwd.c
+ hash.c
+ hash-pjw.c
+ hash-triple.c
+ human.c
+ idcache.c
+ localcharset.c
+ modechange.c
+ mountlist.c
+ quote.c
+ quotearg.c
+ regex.c
+ same.c
+ stripslash.c
+ strndup.c
+ xalloc-die.c
+ xgetcwd.c
+ xmalloc.c
+ xstrndup.c
+ xstrtol-error.c
+ xstrtoumax.c
+ yesno.c
+;
+
+#SEARCH on [ FGristFiles version.c ] = [ FDirName $(SUBDIR) $(DOTDOT) find ] ;
diff --git a/src/bin/findutils/lib/alloca.c b/src/bin/findutils/gnulib/lib/alloca.c
similarity index 84%
rename from src/bin/findutils/lib/alloca.c
rename to src/bin/findutils/gnulib/lib/alloca.c
index 7020f32c88..ff1cb7e9a6 100644
--- a/src/bin/findutils/lib/alloca.c
+++ b/src/bin/findutils/gnulib/lib/alloca.c
@@ -21,12 +21,22 @@
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
-#ifdef HAVE_CONFIG_H
#include
-#endif
+
+#include
+
+#include
+#include
#ifdef emacs
-#include "blockinput.h"
+# include "lisp.h"
+# include "blockinput.h"
+# ifdef EMACS_FREE
+# undef free
+# define free EMACS_FREE
+# endif
+#else
+# define memory_full() abort ()
#endif
/* If compiling with GCC 2, this file's not needed. */
@@ -34,54 +44,33 @@
/* If someone has defined alloca as a macro,
there must be some other way alloca is supposed to work. */
-#ifndef alloca
+# ifndef alloca
-#ifdef emacs
-#ifdef static
+# ifdef emacs
+# ifdef static
/* actually, only want this if static is defined as ""
-- this is for usg, in which emacs must undefine static
in order to make unexec workable
*/
-#ifndef STACK_DIRECTION
+# ifndef STACK_DIRECTION
you
lose
-- must know STACK_DIRECTION at compile-time
-#endif /* STACK_DIRECTION undefined */
-#endif /* static */
-#endif /* emacs */
+/* Using #error here is not wise since this file should work for
+ old and obscure compilers. */
+# endif /* STACK_DIRECTION undefined */
+# endif /* static */
+# endif /* emacs */
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
-#if defined (CRAY) && defined (CRAY_STACKSEG_END)
+# if defined (CRAY) && defined (CRAY_STACKSEG_END)
long i00afunc ();
-#define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
-#else
-#define ADDRESS_FUNCTION(arg) &(arg)
-#endif
-
-#if __STDC__
-typedef void *pointer;
-#else
-typedef char *pointer;
-#endif
-
-#define NULL 0
-
-/* Different portions of Emacs need to call different versions of
- malloc. The Emacs executable needs alloca to call xmalloc, because
- ordinary malloc isn't protected from input signals. On the other
- hand, the utilities in lib-src need alloca to call malloc; some of
- them are very simple, and don't have an xmalloc routine.
-
- Non-Emacs programs expect this to call use xmalloc.
-
- Callers below should use malloc. */
-
-#ifndef emacs
-#define malloc xmalloc
-#endif
-extern pointer malloc ();
+# define ADDRESS_FUNCTION(arg) (char *) i00afunc (&(arg))
+# else
+# define ADDRESS_FUNCTION(arg) &(arg)
+# endif
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
@@ -91,21 +80,21 @@ extern pointer malloc ();
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
-#ifndef STACK_DIRECTION
-#define STACK_DIRECTION 0 /* Direction unknown. */
-#endif
+# ifndef STACK_DIRECTION
+# define STACK_DIRECTION 0 /* Direction unknown. */
+# endif
-#if STACK_DIRECTION != 0
+# if STACK_DIRECTION != 0
-#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
+# define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
-#else /* STACK_DIRECTION == 0; need run-time code. */
+# else /* STACK_DIRECTION == 0; need run-time code. */
static int stack_dir; /* 1 or -1 once known. */
-#define STACK_DIR stack_dir
+# define STACK_DIR stack_dir
static void
-find_stack_direction ()
+find_stack_direction (void)
{
static char *addr = NULL; /* Address of first `dummy', once known. */
auto char dummy; /* To get stack address. */
@@ -126,7 +115,7 @@ find_stack_direction ()
}
}
-#endif /* STACK_DIRECTION == 0 */
+# endif /* STACK_DIRECTION == 0 */
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
@@ -135,9 +124,9 @@ find_stack_direction ()
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
-#ifndef ALIGN_SIZE
-#define ALIGN_SIZE sizeof(double)
-#endif
+# ifndef ALIGN_SIZE
+# define ALIGN_SIZE sizeof(double)
+# endif
typedef union hdr
{
@@ -158,27 +147,26 @@ static header *last_alloca_header = NULL; /* -> last alloca header. */
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
-pointer
-alloca (size)
- unsigned size;
+void *
+alloca (size_t size)
{
auto char probe; /* Probes stack depth: */
register char *depth = ADDRESS_FUNCTION (probe);
-#if STACK_DIRECTION == 0
+# if STACK_DIRECTION == 0
if (STACK_DIR == 0) /* Unknown growth direction. */
find_stack_direction ();
-#endif
+# endif
/* Reclaim garbage, defined as all alloca'd storage that
- was allocated from deeper in the stack than currently. */
+ was allocated from deeper in the stack than currently. */
{
register header *hp; /* Traverses linked list. */
-#ifdef emacs
+# ifdef emacs
BLOCK_INPUT;
-#endif
+# endif
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
@@ -186,7 +174,7 @@ alloca (size)
{
register header *np = hp->h.next;
- free ((pointer) hp); /* Collect garbage. */
+ free (hp); /* Collect garbage. */
hp = np; /* -> next header. */
}
@@ -195,9 +183,9 @@ alloca (size)
last_alloca_header = hp; /* -> last valid storage. */
-#ifdef emacs
+# ifdef emacs
UNBLOCK_INPUT;
-#endif
+# endif
}
if (size == 0)
@@ -206,29 +194,38 @@ alloca (size)
/* Allocate combined header + user data storage. */
{
- register pointer new = malloc (sizeof (header) + size);
/* Address of header. */
+ register header *new;
- ((header *) new)->h.next = last_alloca_header;
- ((header *) new)->h.deep = depth;
+ size_t combined_size = sizeof (header) + size;
+ if (combined_size < sizeof (header))
+ memory_full ();
- last_alloca_header = (header *) new;
+ new = malloc (combined_size);
+
+ if (! new)
+ memory_full ();
+
+ new->h.next = last_alloca_header;
+ new->h.deep = depth;
+
+ last_alloca_header = new;
/* User storage begins just after header. */
- return (pointer) ((char *) new + sizeof (header));
+ return (void *) (new + 1);
}
}
-#if defined (CRAY) && defined (CRAY_STACKSEG_END)
+# if defined (CRAY) && defined (CRAY_STACKSEG_END)
-#ifdef DEBUG_I00AFUNC
-#include
-#endif
+# ifdef DEBUG_I00AFUNC
+# include
+# endif
-#ifndef CRAY_STACK
-#define CRAY_STACK
-#ifndef CRAY2
+# ifndef CRAY_STACK
+# define CRAY_STACK
+# ifndef CRAY2
/* Stack structures for CRAY-1, CRAY X-MP, and CRAY Y-MP */
struct stack_control_header
{
@@ -280,7 +277,7 @@ struct stack_segment_linkage
long sss7;
};
-#else /* CRAY2 */
+# else /* CRAY2 */
/* The following structure defines the vector of words
returned by the STKSTAT library routine. */
struct stk_stat
@@ -333,12 +330,12 @@ struct stk_trailer
long unknown14;
};
-#endif /* CRAY2 */
-#endif /* not CRAY_STACK */
+# endif /* CRAY2 */
+# endif /* not CRAY_STACK */
-#ifdef CRAY2
+# ifdef CRAY2
/* Determine a "stack measure" for an arbitrary ADDRESS.
- I doubt that "lint" will like this much. */
+ I doubt that "lint" will like this much. */
static long
i00afunc (long *address)
@@ -407,7 +404,7 @@ i00afunc (long *address)
return (result);
}
-#else /* not CRAY2 */
+# else /* not CRAY2 */
/* Stack address function for a CRAY-1, CRAY X-MP, or CRAY Y-MP.
Determine the number of the cell within the stack,
given the address of the cell. The purpose of this
@@ -452,9 +449,9 @@ i00afunc (long address)
while (!(this_segment <= address && address <= stkl))
{
-#ifdef DEBUG_I00AFUNC
+# ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o %011o\n", this_segment, address, stkl);
-#endif
+# endif
if (pseg == 0)
break;
stkl = stkl - pseg;
@@ -473,9 +470,9 @@ i00afunc (long address)
while (pseg != 0)
{
-#ifdef DEBUG_I00AFUNC
+# ifdef DEBUG_I00AFUNC
fprintf (stderr, "%011o %011o\n", pseg, size);
-#endif
+# endif
stkl = stkl - pseg;
ssptr = (struct stack_segment_linkage *) stkl;
size = ssptr->sssize;
@@ -485,8 +482,8 @@ i00afunc (long address)
return (result);
}
-#endif /* not CRAY2 */
-#endif /* CRAY */
+# endif /* not CRAY2 */
+# endif /* CRAY */
-#endif /* no alloca */
-#endif /* not GCC version 2 */
+# endif /* no alloca */
+#endif /* not GCC version 3 */
diff --git a/src/bin/findutils/gnulib/lib/alloca.h b/src/bin/findutils/gnulib/lib/alloca.h
new file mode 100644
index 0000000000..64f320bf18
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/alloca.h
@@ -0,0 +1,55 @@
+/* DO NOT EDIT! GENERATED AUTOMATICALLY! */
+/* Memory allocation on the stack.
+
+ Copyright (C) 1995, 1999, 2001-2004, 2006-2007 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA. */
+
+/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
+ means there is a real alloca function. */
+#ifndef _GL_ALLOCA_H
+#define _GL_ALLOCA_H
+
+/* alloca (N) returns a pointer to N bytes of memory
+ allocated on the stack, which will last until the function returns.
+ Use of alloca should be avoided:
+ - inside arguments of function calls - undefined behaviour,
+ - in inline functions - the allocation may actually last until the
+ calling function returns,
+ - for huge N (say, N >= 65536) - you never know how large (or small)
+ the stack is, and when the stack cannot fulfill the memory allocation
+ request, the program just crashes.
+ */
+
+#ifndef alloca
+# ifdef __GNUC__
+# define alloca __builtin_alloca
+# elif defined _AIX
+# define alloca __alloca
+# elif defined _MSC_VER
+# include
+# define alloca _alloca
+# else
+# include
+# ifdef __cplusplus
+extern "C"
+# endif
+void *alloca (size_t);
+# endif
+#endif
+
+#endif /* _GL_ALLOCA_H */
diff --git a/src/bin/findutils/gnulib/lib/alloca.in.h b/src/bin/findutils/gnulib/lib/alloca.in.h
new file mode 100644
index 0000000000..82782884ea
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/alloca.in.h
@@ -0,0 +1,54 @@
+/* Memory allocation on the stack.
+
+ Copyright (C) 1995, 1999, 2001-2004, 2006-2007 Free Software
+ Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the terms of the GNU General Public License as published
+ by the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public
+ License along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+ USA. */
+
+/* Avoid using the symbol _ALLOCA_H here, as Bison assumes _ALLOCA_H
+ means there is a real alloca function. */
+#ifndef _GL_ALLOCA_H
+#define _GL_ALLOCA_H
+
+/* alloca (N) returns a pointer to N bytes of memory
+ allocated on the stack, which will last until the function returns.
+ Use of alloca should be avoided:
+ - inside arguments of function calls - undefined behaviour,
+ - in inline functions - the allocation may actually last until the
+ calling function returns,
+ - for huge N (say, N >= 65536) - you never know how large (or small)
+ the stack is, and when the stack cannot fulfill the memory allocation
+ request, the program just crashes.
+ */
+
+#ifndef alloca
+# ifdef __GNUC__
+# define alloca __builtin_alloca
+# elif defined _AIX
+# define alloca __alloca
+# elif defined _MSC_VER
+# include
+# define alloca _alloca
+# else
+# include
+# ifdef __cplusplus
+extern "C"
+# endif
+void *alloca (size_t);
+# endif
+#endif
+
+#endif /* _GL_ALLOCA_H */
diff --git a/src/bin/findutils/gnulib/lib/areadlink-with-size.c b/src/bin/findutils/gnulib/lib/areadlink-with-size.c
new file mode 100644
index 0000000000..d0bcb70ad5
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/areadlink-with-size.c
@@ -0,0 +1,108 @@
+/* readlink wrapper to return the link name in malloc'd storage.
+ Unlike xreadlink and xreadlink_with_size, don't ever call exit.
+
+ Copyright (C) 2001, 2003-2007 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+/* Written by Jim Meyering */
+
+#include
+
+#include "areadlink.h"
+
+#include
+#include
+#include
+#include
+#include
+#include
+
+#ifndef SIZE_MAX
+# define SIZE_MAX ((size_t) -1)
+#endif
+#ifndef SSIZE_MAX
+# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2))
+#endif
+
+/* SYMLINK_MAX is used only for an initial memory-allocation sanity
+ check, so it's OK to guess too small on hosts where there is no
+ arbitrary limit to symbolic link length. */
+#ifndef SYMLINK_MAX
+# define SYMLINK_MAX 1024
+#endif
+
+#define MAXSIZE (SIZE_MAX < SSIZE_MAX ? SIZE_MAX : SSIZE_MAX)
+
+/* Call readlink to get the symbolic link value of FILE.
+ SIZE is a hint as to how long the link is expected to be;
+ typically it is taken from st_size. It need not be correct.
+ Return a pointer to that NUL-terminated string in malloc'd storage.
+ If readlink fails, malloc fails, or if the link value is longer
+ than SSIZE_MAX, return NULL (caller may use errno to diagnose). */
+
+char *
+areadlink_with_size (char const *file, size_t size)
+{
+ /* Some buggy file systems report garbage in st_size. Defend
+ against them by ignoring outlandish st_size values in the initial
+ memory allocation. */
+ size_t symlink_max = SYMLINK_MAX;
+ size_t INITIAL_LIMIT_BOUND = 8 * 1024;
+ size_t initial_limit = (symlink_max < INITIAL_LIMIT_BOUND
+ ? symlink_max + 1
+ : INITIAL_LIMIT_BOUND);
+
+ /* The initial buffer size for the link value. */
+ size_t buf_size = size < initial_limit ? size + 1 : initial_limit;
+
+ while (1)
+ {
+ ssize_t r;
+ size_t link_length;
+ char *buffer = malloc (buf_size);
+
+ if (buffer == NULL)
+ return NULL;
+ r = readlink (file, buffer, buf_size);
+ link_length = r;
+
+ /* On AIX 5L v5.3 and HP-UX 11i v2 04/09, readlink returns -1
+ with errno == ERANGE if the buffer is too small. */
+ if (r < 0 && errno != ERANGE)
+ {
+ int saved_errno = errno;
+ free (buffer);
+ errno = saved_errno;
+ return NULL;
+ }
+
+ if (link_length < buf_size)
+ {
+ buffer[link_length] = 0;
+ return buffer;
+ }
+
+ free (buffer);
+ if (buf_size <= MAXSIZE / 2)
+ buf_size *= 2;
+ else if (buf_size < MAXSIZE)
+ buf_size = MAXSIZE;
+ else
+ {
+ errno = ENOMEM;
+ return NULL;
+ }
+ }
+}
diff --git a/src/bin/findutils/gnulib/lib/areadlink.h b/src/bin/findutils/gnulib/lib/areadlink.h
new file mode 100644
index 0000000000..8720ed9a61
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/areadlink.h
@@ -0,0 +1,23 @@
+/* Read symbolic links without size limitation.
+
+ Copyright (C) 2001, 2003, 2004, 2007 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+/* Written by Jim Meyering */
+
+#include
+
+extern char *areadlink (char const *filename);
+extern char *areadlink_with_size (char const *filename, size_t size_hint);
diff --git a/src/bin/findutils/gnulib/lib/argmatch.c b/src/bin/findutils/gnulib/lib/argmatch.c
new file mode 100644
index 0000000000..925449bfd4
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/argmatch.c
@@ -0,0 +1,277 @@
+/* argmatch.c -- find a match for a string in an array
+
+ Copyright (C) 1990, 1998, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+ Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+/* Written by David MacKenzie
+ Modified by Akim Demaille */
+
+#include
+
+/* Specification. */
+#include "argmatch.h"
+
+#include
+#include
+#include
+#include
+
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
+#include "error.h"
+#include "quotearg.h"
+#include "quote.h"
+
+#if USE_UNLOCKED_IO
+# include "unlocked-io.h"
+#endif
+
+/* When reporting an invalid argument, show nonprinting characters
+ by using the quoting style ARGMATCH_QUOTING_STYLE. Do not use
+ literal_quoting_style. */
+#ifndef ARGMATCH_QUOTING_STYLE
+# define ARGMATCH_QUOTING_STYLE locale_quoting_style
+#endif
+
+/* Non failing version of argmatch call this function after failing. */
+#ifndef ARGMATCH_DIE
+# include "exitfail.h"
+# define ARGMATCH_DIE exit (exit_failure)
+#endif
+
+#ifdef ARGMATCH_DIE_DECL
+ARGMATCH_DIE_DECL;
+#endif
+
+static void
+__argmatch_die (void)
+{
+ ARGMATCH_DIE;
+}
+
+/* Used by XARGMATCH and XARGCASEMATCH. See description in argmatch.h.
+ Default to __argmatch_die, but allow caller to change this at run-time. */
+argmatch_exit_fn argmatch_die = __argmatch_die;
+
+
+/* If ARG is an unambiguous match for an element of the
+ NULL-terminated array ARGLIST, return the index in ARGLIST
+ of the matched element, else -1 if it does not match any element
+ or -2 if it is ambiguous (is a prefix of more than one element).
+
+ If VALLIST is none null, use it to resolve ambiguities limited to
+ synonyms, i.e., for
+ "yes", "yop" -> 0
+ "no", "nope" -> 1
+ "y" is a valid argument, for `0', and "n" for `1'. */
+
+ptrdiff_t
+argmatch (const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i; /* Temporary index in ARGLIST. */
+ size_t arglen; /* Length of ARG. */
+ ptrdiff_t matchind = -1; /* Index of first nonexact match. */
+ bool ambiguous = false; /* If true, multiple nonexact match(es). */
+
+ arglen = strlen (arg);
+
+ /* Test all elements for either exact match or abbreviated matches. */
+ for (i = 0; arglist[i]; i++)
+ {
+ if (!strncmp (arglist[i], arg, arglen))
+ {
+ if (strlen (arglist[i]) == arglen)
+ /* Exact match found. */
+ return i;
+ else if (matchind == -1)
+ /* First nonexact match found. */
+ matchind = i;
+ else
+ {
+ /* Second nonexact match found. */
+ if (vallist == NULL
+ || memcmp (vallist + valsize * matchind,
+ vallist + valsize * i, valsize))
+ {
+ /* There is a real ambiguity, or we could not
+ disambiguate. */
+ ambiguous = true;
+ }
+ }
+ }
+ }
+ if (ambiguous)
+ return -2;
+ else
+ return matchind;
+}
+
+/* Error reporting for argmatch.
+ CONTEXT is a description of the type of entity that was being matched.
+ VALUE is the invalid value that was given.
+ PROBLEM is the return value from argmatch. */
+
+void
+argmatch_invalid (const char *context, const char *value, ptrdiff_t problem)
+{
+ char const *format = (problem == -1
+ ? _("invalid argument %s for %s")
+ : _("ambiguous argument %s for %s"));
+
+ error (0, 0, format, quotearg_n_style (0, ARGMATCH_QUOTING_STYLE, value),
+ quote_n (1, context));
+}
+
+/* List the valid arguments for argmatch.
+ ARGLIST is the same as in argmatch.
+ VALLIST is a pointer to an array of values.
+ VALSIZE is the size of the elements of VALLIST */
+void
+argmatch_valid (const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i;
+ const char *last_val = NULL;
+
+ /* We try to put synonyms on the same line. The assumption is that
+ synonyms follow each other */
+ fprintf (stderr, _("Valid arguments are:"));
+ for (i = 0; arglist[i]; i++)
+ if ((i == 0)
+ || memcmp (last_val, vallist + valsize * i, valsize))
+ {
+ fprintf (stderr, "\n - `%s'", arglist[i]);
+ last_val = vallist + valsize * i;
+ }
+ else
+ {
+ fprintf (stderr, ", `%s'", arglist[i]);
+ }
+ putc ('\n', stderr);
+}
+
+/* Never failing versions of the previous functions.
+
+ CONTEXT is the context for which argmatch is called (e.g.,
+ "--version-control", or "$VERSION_CONTROL" etc.). Upon failure,
+ calls the (supposed never to return) function EXIT_FN. */
+
+ptrdiff_t
+__xargmatch_internal (const char *context,
+ const char *arg, const char *const *arglist,
+ const char *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn)
+{
+ ptrdiff_t res = argmatch (arg, arglist, vallist, valsize);
+ if (res >= 0)
+ /* Success. */
+ return res;
+
+ /* We failed. Explain why. */
+ argmatch_invalid (context, arg, res);
+ argmatch_valid (arglist, vallist, valsize);
+ (*exit_fn) ();
+
+ return -1; /* To please the compilers. */
+}
+
+/* Look for VALUE in VALLIST, an array of objects of size VALSIZE and
+ return the first corresponding argument in ARGLIST */
+const char *
+argmatch_to_argument (const char *value,
+ const char *const *arglist,
+ const char *vallist, size_t valsize)
+{
+ size_t i;
+
+ for (i = 0; arglist[i]; i++)
+ if (!memcmp (value, vallist + valsize * i, valsize))
+ return arglist[i];
+ return NULL;
+}
+
+#ifdef TEST
+/*
+ * Based on "getversion.c" by David MacKenzie
+ */
+char *program_name;
+
+/* When to make backup files. */
+enum backup_type
+{
+ /* Never make backups. */
+ no_backups,
+
+ /* Make simple backups of every file. */
+ simple_backups,
+
+ /* Make numbered backups of files that already have numbered backups,
+ and simple backups of the others. */
+ numbered_existing_backups,
+
+ /* Make numbered backups of every file. */
+ numbered_backups
+};
+
+/* Two tables describing arguments (keys) and their corresponding
+ values */
+static const char *const backup_args[] =
+{
+ "no", "none", "off",
+ "simple", "never",
+ "existing", "nil",
+ "numbered", "t",
+ 0
+};
+
+static const enum backup_type backup_vals[] =
+{
+ no_backups, no_backups, no_backups,
+ simple_backups, simple_backups,
+ numbered_existing_backups, numbered_existing_backups,
+ numbered_backups, numbered_backups
+};
+
+int
+main (int argc, const char *const *argv)
+{
+ const char *cp;
+ enum backup_type backup_type = no_backups;
+
+ program_name = (char *) argv[0];
+
+ if (argc > 2)
+ {
+ fprintf (stderr, "Usage: %s [VERSION_CONTROL]\n", program_name);
+ exit (1);
+ }
+
+ if ((cp = getenv ("VERSION_CONTROL")))
+ backup_type = XARGMATCH ("$VERSION_CONTROL", cp,
+ backup_args, backup_vals);
+
+ if (argc == 2)
+ backup_type = XARGMATCH (program_name, argv[1],
+ backup_args, backup_vals);
+
+ printf ("The version control is `%s'\n",
+ ARGMATCH_TO_ARGUMENT (backup_type, backup_args, backup_vals));
+
+ return 0;
+}
+#endif
diff --git a/src/bin/findutils/gnulib/lib/argmatch.h b/src/bin/findutils/gnulib/lib/argmatch.h
new file mode 100644
index 0000000000..cc403145ac
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/argmatch.h
@@ -0,0 +1,102 @@
+/* argmatch.h -- definitions and prototypes for argmatch.c
+
+ Copyright (C) 1990, 1998, 1999, 2001, 2002, 2004, 2005 Free Software
+ Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+/* Written by David MacKenzie
+ Modified by Akim Demaille */
+
+#ifndef ARGMATCH_H_
+# define ARGMATCH_H_ 1
+
+# include
+
+# include "verify.h"
+
+# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
+
+/* Assert there are as many real arguments as there are values
+ (argument list ends with a NULL guard). */
+
+# define ARGMATCH_VERIFY(Arglist, Vallist) \
+ verify (ARRAY_CARDINALITY (Arglist) == ARRAY_CARDINALITY (Vallist) + 1)
+
+/* Return the index of the element of ARGLIST (NULL terminated) that
+ matches with ARG. If VALLIST is not NULL, then use it to resolve
+ false ambiguities (i.e., different matches of ARG but corresponding
+ to the same values in VALLIST). */
+
+ptrdiff_t argmatch (char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH(Arg, Arglist, Vallist) \
+ argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+/* xargmatch calls this function when it fails. This function should not
+ return. By default, this is a function that calls ARGMATCH_DIE which
+ in turn defaults to `exit (exit_failure)'. */
+typedef void (*argmatch_exit_fn) (void);
+extern argmatch_exit_fn argmatch_die;
+
+/* Report on stderr why argmatch failed. Report correct values. */
+
+void argmatch_invalid (char const *context, char const *value,
+ ptrdiff_t problem);
+
+/* Left for compatibility with the old name invalid_arg */
+
+# define invalid_arg(Context, Value, Problem) \
+ argmatch_invalid (Context, Value, Problem)
+
+
+
+/* Report on stderr the list of possible arguments. */
+
+void argmatch_valid (char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_VALID(Arglist, Vallist) \
+ argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
+
+
+
+/* Same as argmatch, but upon failure, reports a explanation on the
+ failure, and exits using the function EXIT_FN. */
+
+ptrdiff_t __xargmatch_internal (char const *context,
+ char const *arg, char const *const *arglist,
+ char const *vallist, size_t valsize,
+ argmatch_exit_fn exit_fn);
+
+/* Programmer friendly interface to __xargmatch_internal. */
+
+# define XARGMATCH(Context, Arg, Arglist, Vallist) \
+ ((Vallist) [__xargmatch_internal (Context, Arg, Arglist, \
+ (char const *) (Vallist), \
+ sizeof *(Vallist), \
+ argmatch_die)])
+
+/* Convert a value into a corresponding argument. */
+
+char const *argmatch_to_argument (char const *value,
+ char const *const *arglist,
+ char const *vallist, size_t valsize);
+
+# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist) \
+ argmatch_to_argument (Value, Arglist, \
+ (char const *) (Vallist), sizeof *(Vallist))
+
+#endif /* ARGMATCH_H_ */
diff --git a/src/bin/findutils/gnulib/lib/at-func.c b/src/bin/findutils/gnulib/lib/at-func.c
new file mode 100644
index 0000000000..c7963fe3d2
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/at-func.c
@@ -0,0 +1,85 @@
+/* Define an at-style functions like fstatat, unlinkat, fchownat, etc.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+/* written by Jim Meyering */
+
+#define CALL_FUNC(F) \
+ (AT_FUNC_USE_F1_COND \
+ ? AT_FUNC_F1 (F AT_FUNC_POST_FILE_ARGS) \
+ : AT_FUNC_F2 (F AT_FUNC_POST_FILE_ARGS))
+
+/* Call AT_FUNC_F1 or AT_FUNC_F2 (testing AT_FUNC_USE_F1_COND to
+ determine which) to operate on FILE, which is in the directory
+ open on descriptor FD. If possible, do it without changing the
+ working directory. Otherwise, resort to using save_cwd/fchdir,
+ then AT_FUNC_F?/restore_cwd. If either the save_cwd or the restore_cwd
+ fails, then give a diagnostic and exit nonzero. */
+int
+AT_FUNC_NAME (int fd, char const *file AT_FUNC_POST_FILE_PARAM_DECLS)
+{
+ struct saved_cwd saved_cwd;
+ int saved_errno;
+ int err;
+
+ if (fd == AT_FDCWD || IS_ABSOLUTE_FILE_NAME (file))
+ return CALL_FUNC (file);
+
+ {
+ char buf[OPENAT_BUFFER_SIZE];
+ char *proc_file = openat_proc_name (buf, fd, file);
+ if (proc_file)
+ {
+ int proc_result = CALL_FUNC (proc_file);
+ int proc_errno = errno;
+ if (proc_file != buf)
+ free (proc_file);
+ /* If the syscall succeeds, or if it fails with an unexpected
+ errno value, then return right away. Otherwise, fall through
+ and resort to using save_cwd/restore_cwd. */
+ if (0 <= proc_result)
+ return proc_result;
+ if (! EXPECTED_ERRNO (proc_errno))
+ {
+ errno = proc_errno;
+ return proc_result;
+ }
+ }
+ }
+
+ if (save_cwd (&saved_cwd) != 0)
+ openat_save_fail (errno);
+
+ if (fchdir (fd) != 0)
+ {
+ saved_errno = errno;
+ free_cwd (&saved_cwd);
+ errno = saved_errno;
+ return -1;
+ }
+
+ err = CALL_FUNC (file);
+ saved_errno = (err < 0 ? errno : 0);
+
+ if (restore_cwd (&saved_cwd) != 0)
+ openat_restore_fail (errno);
+
+ free_cwd (&saved_cwd);
+
+ if (saved_errno)
+ errno = saved_errno;
+ return err;
+}
+#undef CALL_FUNC
diff --git a/src/bin/findutils/gnulib/lib/basename.c b/src/bin/findutils/gnulib/lib/basename.c
new file mode 100644
index 0000000000..426ed40f1a
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/basename.c
@@ -0,0 +1,128 @@
+/* basename.c -- return the last element in a file name
+
+ Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free
+ Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+#include
+
+#include "dirname.h"
+
+#include
+#include "xalloc.h"
+#include "xstrndup.h"
+
+/* Return the address of the last file name component of NAME. If
+ NAME has no relative file name components because it is a file
+ system root, return the empty string. */
+
+char *
+last_component (char const *name)
+{
+ char const *base = name + FILE_SYSTEM_PREFIX_LEN (name);
+ char const *p;
+ bool saw_slash = false;
+
+ while (ISSLASH (*base))
+ base++;
+
+ for (p = base; *p; p++)
+ {
+ if (ISSLASH (*p))
+ saw_slash = true;
+ else if (saw_slash)
+ {
+ base = p;
+ saw_slash = false;
+ }
+ }
+
+ return (char *) base;
+}
+
+
+/* In general, we can't use the builtin `basename' function if available,
+ since it has different meanings in different environments.
+ In some environments the builtin `basename' modifies its argument.
+
+ Return the last file name component of NAME, allocated with
+ xmalloc. On systems with drive letters, a leading "./"
+ distinguishes relative names that would otherwise look like a drive
+ letter. Unlike POSIX basename(), NAME cannot be NULL,
+ base_name("") returns "", and the first trailing slash is not
+ stripped.
+
+ If lstat (NAME) would succeed, then { chdir (dir_name (NAME));
+ lstat (base_name (NAME)); } will access the same file. Likewise,
+ if the sequence { chdir (dir_name (NAME));
+ rename (base_name (NAME), "foo"); } succeeds, you have renamed NAME
+ to "foo" in the same directory NAME was in. */
+
+char *
+base_name (char const *name)
+{
+ char const *base = last_component (name);
+ size_t length;
+
+ /* If there is no last component, then name is a file system root or the
+ empty string. */
+ if (! *base)
+ return xstrndup (name, base_len (name));
+
+ /* Collapse a sequence of trailing slashes into one. */
+ length = base_len (base);
+ if (ISSLASH (base[length]))
+ length++;
+
+ /* On systems with drive letters, `a/b:c' must return `./b:c' rather
+ than `b:c' to avoid confusion with a drive letter. On systems
+ with pure POSIX semantics, this is not an issue. */
+ if (FILE_SYSTEM_PREFIX_LEN (base))
+ {
+ char *p = xmalloc (length + 3);
+ p[0] = '.';
+ p[1] = '/';
+ memcpy (p + 2, base, length);
+ p[length + 2] = '\0';
+ return p;
+ }
+
+ /* Finally, copy the basename. */
+ return xstrndup (base, length);
+}
+
+/* Return the length of the basename NAME. Typically NAME is the
+ value returned by base_name or last_component. Act like strlen
+ (NAME), except omit all trailing slashes. */
+
+size_t
+base_len (char const *name)
+{
+ size_t len;
+ size_t prefix_len = FILE_SYSTEM_PREFIX_LEN (name);
+
+ for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--)
+ continue;
+
+ if (DOUBLE_SLASH_IS_DISTINCT_ROOT && len == 1
+ && ISSLASH (name[0]) && ISSLASH (name[1]) && ! name[2])
+ return 2;
+
+ if (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE && prefix_len
+ && len == prefix_len && ISSLASH (name[prefix_len]))
+ return prefix_len + 1;
+
+ return len;
+}
diff --git a/src/bin/findutils/gnulib/lib/binary-io.h b/src/bin/findutils/gnulib/lib/binary-io.h
new file mode 100644
index 0000000000..273d35a9a6
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/binary-io.h
@@ -0,0 +1,63 @@
+/* Binary mode I/O.
+ Copyright (C) 2001, 2003, 2005 Free Software Foundation, Inc.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+#ifndef _BINARY_H
+#define _BINARY_H
+
+/* For systems that distinguish between text and binary I/O.
+ O_BINARY is usually declared in . */
+#include
+
+/* The MSVC7 doesn't like to be included after '#define fileno ...',
+ so we include it here first. */
+#include
+
+#if !defined O_BINARY && defined _O_BINARY
+ /* For MSC-compatible compilers. */
+# define O_BINARY _O_BINARY
+# define O_TEXT _O_TEXT
+#endif
+#ifdef __BEOS__
+ /* BeOS 5 has O_BINARY and O_TEXT, but they have no effect. */
+# undef O_BINARY
+# undef O_TEXT
+#endif
+#if O_BINARY
+# if !(defined __EMX__ || defined __DJGPP__ || defined __CYGWIN__)
+# define setmode _setmode
+# undef fileno
+# define fileno _fileno
+# endif
+# if defined __DJGPP__ || defined __CYGWIN__
+# include /* declares setmode() */
+# endif
+# ifdef __DJGPP__
+# include /* declares isatty() */
+# /* Avoid putting stdin/stdout in binary mode if it is connected to the
+# console, because that would make it impossible for the user to
+# interrupt the program through Ctrl-C or Ctrl-Break. */
+# define SET_BINARY(fd) (!isatty (fd) ? (setmode (fd, O_BINARY), 0) : 0)
+# else
+# define SET_BINARY(fd) setmode (fd, O_BINARY)
+# endif
+#else
+ /* On reasonable systems, binary I/O is the default. */
+# undef O_BINARY
+# define O_BINARY 0
+# define SET_BINARY(fd) /* nothing */
+#endif
+
+#endif /* _BINARY_H */
diff --git a/src/bin/findutils/gnulib/lib/canonicalize-lgpl.c b/src/bin/findutils/gnulib/lib/canonicalize-lgpl.c
new file mode 100644
index 0000000000..e8d2b65ebc
--- /dev/null
+++ b/src/bin/findutils/gnulib/lib/canonicalize-lgpl.c
@@ -0,0 +1,362 @@
+/* Return the canonical absolute name of a given file.
+ Copyright (C) 1996-2003, 2005-2007 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see . */
+
+#include
+
+/* Avoid a clash of our rpl_realpath() function with the prototype in
+ on Solaris 2.5.1. */
+#undef realpath
+
+#if !HAVE_CANONICALIZE_FILE_NAME || defined _LIBC
+
+#include
+
+/* Specification. */
+#include "canonicalize.h"
+
+#include
+#include
+#include
+
+#if HAVE_UNISTD_H || defined _LIBC
+# include
+#endif
+
+#include
+
+#if HAVE_SYS_PARAM_H || defined _LIBC
+# include
+#endif
+#ifndef MAXSYMLINKS
+# define MAXSYMLINKS 20
+#endif
+
+#include
+
+#include
+#ifndef _LIBC
+# define __set_errno(e) errno = (e)
+# ifndef ENAMETOOLONG
+# define ENAMETOOLONG EINVAL
+# endif
+#endif
+
+#ifdef _LIBC
+# include