Project:Toolchain/Glibc 2.26 porting notes/sysmacros.h

From Gentoo Wiki
Jump to:navigation Jump to:search

Description

To support upcoming c++ standards glibc plans to remove <sys/sysmacros.h> from glibc's <sys/types.h>. See the announcement.

<sys/sysmacros.h> defines the following macros:

  • major()
  • minor()
  • makedev()

Build breakage usually looks like that:

 bdev/lxclvm.c: In function 'lvm_detect':
 bdev/lxclvm.c:140:4: error: implicit declaration of function 'major' [-Werror=implicit-function-declaration]
   major(statbuf.st_rdev), minor(statbuf.st_rdev));
   ^Grknight (talk) 14:53, 10 August 2021 (UTC)
 bdev/lxclvm.c:140:28: error: implicit declaration of function 'minor' [-Werror=implicit-function-declaration]
   major(statbuf.st_rdev), minor(statbuf.st_rdev));
                           ^Grknight (talk) 14:53, 10 August 2021 (UTC)

How to fix

autoconf-based systems

Note: <sys/sysmacros.h> is a non-standard header. Most portable fix across various libcs is to use [AC_HEADER_MAJOR] macro.

# somewhere in configure.ac:
# lookup major()/minor()/makedev()
AC_HEADER_MAJOR
CODE
/* somewhere in C code */
#ifdef MAJOR_IN_MKDEV
#    include <sys/mkdev.h>
#endif
#ifdef MAJOR_IN_SYSMACROS
#    include <sys/sysmacros.h>
#endif

Links