-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Update OpenBSD glob implementation for Windows #16948
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a26e92e
Add reallocarray to utility functions
NattyNarwhal 3aafb04
Update OpenBSD glob implementation for Windows
NattyNarwhal cd73ebd
remove tab at end
NattyNarwhal 681d860
Convert to standard C99 type
NattyNarwhal b161035
Change four spaces to tabs
NattyNarwhal 64ff225
Put function definitions associated with body on one line
NattyNarwhal ce4c833
Move realloc array into win32/glob.c
NattyNarwhal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
+----------------------------------------------------------------------+ | ||
| Copyright (c) The PHP Group | | ||
+----------------------------------------------------------------------+ | ||
| This source file is subject to version 3.01 of the PHP license, | | ||
| that is bundled with this package in the file LICENSE, and is | | ||
| available through the world-wide-web at the following url: | | ||
| https://www.php.net/license/3_01.txt | | ||
| If you did not receive a copy of the PHP license and are unable to | | ||
| obtain it through the world-wide-web, please send a note to | | ||
| [email protected] so we can mail you a copy immediately. | | ||
+----------------------------------------------------------------------+ | ||
| Author: | | ||
+----------------------------------------------------------------------+ | ||
*/ | ||
|
||
#include "php.h" | ||
|
||
#ifdef USE_REALLOCARRAY_PHP_IMPL | ||
/* $OpenBSD: reallocarray.c,v 1.3 2015/09/13 08:31:47 guenther Exp $ */ | ||
/* | ||
* Copyright (c) 2008 Otto Moerbeek <[email protected]> | ||
* | ||
* Permission to use, copy, modify, and distribute this software for any | ||
* purpose with or without fee is hereby granted, provided that the above | ||
* copyright notice and this permission notice appear in all copies. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
*/ | ||
|
||
#include <sys/types.h> | ||
#include <errno.h> | ||
#include <stdint.h> | ||
#include <stdlib.h> | ||
|
||
/* | ||
* This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX | ||
* if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW | ||
*/ | ||
#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4)) | ||
|
||
PHPAPI void * | ||
php_reallocarray(void *optr, size_t nmemb, size_t size) | ||
{ | ||
if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) && | ||
nmemb > 0 && SIZE_MAX / nmemb < size) { | ||
errno = ENOMEM; | ||
return NULL; | ||
} | ||
return realloc(optr, size * nmemb); | ||
} | ||
|
||
#endif /* !HAVE_REALLOCARRAY */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Public domain, 2008, Todd C. Miller <[email protected]> | ||
* | ||
* $OpenBSD: charclass.h,v 1.3 2020/10/13 04:42:28 guenther Exp $ | ||
*/ | ||
|
||
/* | ||
* POSIX character class support for fnmatch() and glob(). | ||
*/ | ||
static const struct cclass { | ||
const char *name; | ||
int (*isctype)(int); | ||
} cclasses[] = { | ||
{ "alnum", isalnum }, | ||
{ "alpha", isalpha }, | ||
{ "blank", isblank }, | ||
{ "cntrl", iscntrl }, | ||
{ "digit", isdigit }, | ||
{ "graph", isgraph }, | ||
{ "lower", islower }, | ||
{ "print", isprint }, | ||
{ "punct", ispunct }, | ||
{ "space", isspace }, | ||
{ "upper", isupper }, | ||
{ "xdigit", isxdigit }, | ||
{ NULL, NULL } | ||
}; | ||
|
||
#define NCCLASSES (sizeof(cclasses) / sizeof(cclasses[0]) - 1) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should not be in main but in win32. I don't think we will want to use it in this format if glob is made common. In such case we should probably look to introducing something in zend_alloc that would respect memory_limit at some point. I know that the libc glob does not do that but it would be good thing to do eventually.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I imported reallocarray there since it's consistent with other imported utility functions like strlcpy, and we'll need it when we use this glob on not-Windows. ZendMM conversion would render this moot though.