Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add fnmatch.h #3937

Merged
merged 1 commit into from
Oct 16, 2024
Merged

Add fnmatch.h #3937

merged 1 commit into from
Oct 16, 2024

Conversation

epilys
Copy link
Contributor

@epilys epilys commented Sep 20, 2024

Add fnmatch() function and FNM_* constants.

Signed-off-by: Manos Pitsidianakis [email protected]

@rustbot
Copy link
Collaborator

rustbot commented Sep 20, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @tgross35 (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@epilys epilys force-pushed the feature/fnmatch branch 5 times, most recently from bbbeea4 to 6c55043 Compare September 20, 2024 09:36
@tgross35
Copy link
Contributor

Thanks for the PR! Could you link the relevant headers and/or docs?

Also the relevant files in libc-test/semver should be updated with the additions.

@rustbot author (just comment @rustbot review once you are all set)

Add fnmatch() function and FNM_* constants.

Documentation:

Header file:
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fnmatch.h.html

fnmatch() function:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/fnmatch.html

Signed-off-by: Manos Pitsidianakis <[email protected]>
@epilys
Copy link
Contributor Author

epilys commented Sep 25, 2024

Thank you!

Added header file documentation in commit message:

Add fnmatch() function and FNM_* constants.

Documentation:

Header file:
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fnmatch.h.html

fnmatch() function:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/fnmatch.html

Signed-off-by: Manos Pitsidianakis <[email protected]>

@rustbot review

Comment on lines +327 to +339
cfg_if! {
if #[cfg(any(
target_os = "macos",
target_os = "freebsd",
target_os = "android",
))] {
pub const FNM_PATHNAME: c_int = 1 << 1;
pub const FNM_NOESCAPE: c_int = 1 << 0;
} else {
pub const FNM_PATHNAME: c_int = 1 << 0;
pub const FNM_NOESCAPE: c_int = 1 << 1;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall this looks pretty straightforward, but do you have links to headers defining these? I am a bit surprised they are opposite on a few OSs, we should make sure that's documented in the PR.

Copy link
Contributor Author

@epilys epilys Oct 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Certainly,

macos

https://opensource.apple.com/source/Libc/Libc-825.40.1/include/fnmatch.h.auto.html

#define	FNM_NOESCAPE	0x01	/* Disable backslash escaping. */
#define	FNM_PATHNAME	0x02	/* Slash must be matched by slash. */

freebsd

https://github.com/freebsd/freebsd-src/blob/4a983f05d98ba1c5eebe65d29dd061dc3eab7594/include/fnmatch.h#L4

#define	FNM_NOESCAPE	0x01	/* Disable backslash escaping. */
#define	FNM_PATHNAME	0x02	/* Slash must be matched by slash. */

android

https://cs.android.com/android/platform/superproject/main/+/main:bionic/libc/include/fnmatch.h;drc=bbd39aa8e66dfe325732934d1aeb0da52b4750d5

/** fnmatch() flag to disable backslash escaping. */
#define FNM_NOESCAPE     0x01 
/** fnmatch() flag to ensure that slashes must be matched by slashes. */
#define FNM_PATHNAME     0x02

musl

https://git.musl-libc.org/cgit/musl/tree/include/fnmatch.h?id=03860303c298f2ec7a9c0de683a68f4ab61697f0

#define	FNM_PATHNAME 0x1
#define	FNM_NOESCAPE 0x2

glibc

https://elixir.bootlin.com/glibc/glibc-2.40.9000/source/posix/fnmatch.h#L33

#define	FNM_PATHNAME	(1 << 0) /* No wildcard can ever match `/'.  */
#define	FNM_NOESCAPE	(1 << 1) /* Backslashes don't quote special chars.  */

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks for the sources!

@tgross35 tgross35 added this pull request to the merge queue Oct 16, 2024
Merged via the queue into rust-lang:main with commit fbeb860 Oct 16, 2024
41 checks passed
@epilys epilys deleted the feature/fnmatch branch October 16, 2024 08:11
@tgross35 tgross35 added the stable-nominated This PR should be considered for cherry-pick to libc's stable release branch label Oct 16, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Oct 17, 2024
Add fnmatch() function and FNM_* constants.

Documentation:

Header file:
https://pubs.opengroup.org/onlinepubs/9799919799/basedefs/fnmatch.h.html

fnmatch() function:
https://pubs.opengroup.org/onlinepubs/9799919799/functions/fnmatch.html

Signed-off-by: Manos Pitsidianakis <[email protected]>

(backport <rust-lang#3937>)
(cherry picked from commit 70de2da)
@tgross35 tgross35 mentioned this pull request Oct 17, 2024
@tgross35 tgross35 added stable-applied This PR has been cherry-picked to libc's stable release branch and removed stable-nominated This PR should be considered for cherry-pick to libc's stable release branch labels Oct 17, 2024
@semarie
Copy link
Contributor

semarie commented Oct 17, 2024

FYI, it fails to pass tests on OpenBSD:

bad FNM_PATHNAME value at byte 0: rust: 1 (0x1) != c 2 (0x2)
bad FNM_NOESCAPE value at byte 0: rust: 2 (0x2) != c 1 (0x1)

for reference: https://github.com/openbsd/src/blob/master/include/fnmatch.h#L43

#define	FNM_NOESCAPE	0x01	/* Disable backslash escaping. */
#define	FNM_PATHNAME	0x02	/* Slash must be matched by slash. */

@tgross35
Copy link
Contributor

Ah, we need OpenBSD in CI... Are you able to put up a fix? I'll do a new release.

semarie added a commit to semarie/rust-libc that referenced this pull request Oct 17, 2024
fix FNM_PATHNAME and FNM_NOESCAPE values.
@semarie
Copy link
Contributor

semarie commented Oct 17, 2024

fix in #3983

github-merge-queue bot pushed a commit that referenced this pull request Oct 17, 2024
tgross35 pushed a commit to tgross35/rust-libc that referenced this pull request Oct 17, 2024
fix FNM_PATHNAME and FNM_NOESCAPE values.

(backport <rust-lang#3983>)
(cherry picked from commit 1f68792)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review stable-applied This PR has been cherry-picked to libc's stable release branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants