Skip to content

Check major, minor and makedev with Autoconf's AC_HEADER_MAJOR #13706

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

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,11 @@ if test "$GCC" = "yes"; then
PHP_BROKEN_GCC_STRLEN_OPT
fi

dnl Detect the headers required to use makedev, major, and minor.
dnl Autoconf <= 2.69 didn't check glibc 2.25 deprecated macros in sys/types.h.
m4_version_prereq([2.70],,[ac_cv_header_sys_types_h_makedev=no])
AC_HEADER_MAJOR

dnl Checks for typedefs, structures, and compiler characteristics.
dnl ----------------------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions ext/fileinfo/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ if test "$PHP_FILEINFO" != "no"; then
libmagic/readcdf.c libmagic/softmagic.c libmagic/der.c \
libmagic/buffer.c libmagic/is_csv.c"

AC_CHECK_HEADERS([sys/sysmacros.h])

AC_CHECK_FUNCS([strcasestr],,[
AC_MSG_NOTICE(using libmagic strcasestr implementation)
libmagic_sources="$libmagic_sources libmagic/strcasestr.c"
Expand Down
16 changes: 13 additions & 3 deletions ext/posix/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@ if test "$PHP_POSIX" = "yes"; then
AC_DEFINE(HAVE_POSIX, 1, [whether to include POSIX-like functions])
PHP_NEW_EXTENSION(posix, posix.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)

AC_CHECK_HEADERS([sys/mkdev.h sys/sysmacros.h])

AC_CHECK_FUNCS(seteuid setegid setsid getsid getpgid ctermid mkfifo mknod setrlimit getrlimit getgroups makedev initgroups getgrgid_r eaccess)
AC_CHECK_FUNCS(seteuid setegid setsid getsid getpgid ctermid mkfifo mknod setrlimit getrlimit getgroups initgroups getgrgid_r eaccess)

dnl Check for makedev. If it's defined as a macro, AC_CHECK_FUNCS won't work.
dnl Required headers are included by the AC_HEADER_MAJOR logic.
AC_CHECK_FUNCS([makedev],,
[AC_CHECK_DECL([makedev], [AC_DEFINE([HAVE_MAKEDEV], [1])],, [
#include <sys/types.h>
#ifdef MAJOR_IN_MKDEV
# include <sys/mkdev.h>
#elif defined(MAJOR_IN_SYSMACROS)
# include <sys/sysmacros.h>
#endif
])])

dnl Skip pathconf and fpathconf check on musl libc due to limited implementation
dnl (first argument is not validated and has different error).
Expand Down
7 changes: 3 additions & 4 deletions ext/posix/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,9 @@
#include <errno.h>
#include <grp.h>
#include <pwd.h>
#ifdef HAVE_SYS_MKDEV_H
#ifdef MAJOR_IN_MKDEV
# include <sys/mkdev.h>
#endif
#ifdef HAVE_SYS_SYSMACROS_H
#elif defined(MAJOR_IN_SYSMACROS)
# include <sys/sysmacros.h>
#endif

Expand Down Expand Up @@ -620,7 +619,7 @@ PHP_FUNCTION(posix_mknod)
zend_argument_value_error(3, "cannot be 0 for the POSIX_S_IFCHR and POSIX_S_IFBLK modes");
RETURN_THROWS();
} else {
#if defined(HAVE_MAKEDEV) || defined(makedev)
#ifdef HAVE_MAKEDEV
php_dev = makedev(major, minor);
#else
php_error_docref(NULL, E_WARNING, "Cannot create a block or character device, creating a normal file instead");
Expand Down