Skip to content

Commit

Permalink
scons: check *xattr functions with correct arguments
Browse files Browse the repository at this point in the history
`SCons.Conftest.CheckFunc(context, "lgetxattr", "#include <sys/types.h>\n#include <sys/xattr.h>")`
will generate following C code:

```
#include <assert.h>
#include <sys/types.h>
#include <sys/xattr.h>

#if _MSC_VER && !__INTEL_COMPILER
    #pragma function(lgetxattr)
#endif

int main(void) {
#if defined (__stub_lgetxattr) || defined (__stub___lgetxattr)
   #error "lgetxattr has a GNU stub, cannot check"
#else
   lgetxattr();
#endif

     return 0;
}
```

This code snippet will fail to compile on armhf on Ubuntu 24.04 (noble):

```
$ gcc -o test test.c
test.c: In function ‘main’:
test.c:13:11: error: too few arguments to function ‘lgetxattr’
   13 | lgetxattr();
      | ^~~~~~~~~
In file included from test2.c:3:
/usr/include/arm-linux-gnueabihf/sys/xattr.h:67:16: note: declared here
   67 | extern ssize_t lgetxattr (const char *__path, const char *__name,
      | ^~~~~~~~~
```

So pass valid arguments to the *xttr functions.

**Note**: The `funcargs` parameter requires SCons >= 4.7.0!

Bug-Ubuntu: https://launchpad.net/bugs/2066970
  • Loading branch information
bdrung committed May 28, 2024
1 parent 254cf96 commit 1c0bfaf
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,14 @@ def check_posix_fadvise(context):
def check_xattr(context):
rc = 1

for func in ['getxattr', 'setxattr', 'removexattr', 'listxattr']:
for func, funcargs in (
('getxattr', '"path", "name", NULL, 0'),
('setxattr', '"path", "name", NULL, 0, 0'),
('removexattr', '"path", "name"'),
('listxattr', '"path", "name", 0'),
):
if tests.CheckFunc(
context, func,
context, func, funcargs=funcargs,
header=
'#include <sys/types.h>'
'#include <sys/xattr.h>'
Expand All @@ -291,9 +296,14 @@ def check_xattr(context):
def check_lxattr(context):
rc = 1

for func in ['lgetxattr', 'lsetxattr', 'lremovexattr', 'llistxattr']:
for func, funcargs in (
('lgetxattr', '"path", "name", NULL, 0'),
('lsetxattr', '"path", "name", NULL, 0, 0'),
('lremovexattr', '"path", "name"'),
('llistxattr', '"path", "name", 0'),
):
if tests.CheckFunc(
context, func,
context, func, funcargs=funcargs,
header=
'#include <sys/types.h>'
'#include <sys/xattr.h>'
Expand Down

0 comments on commit 1c0bfaf

Please sign in to comment.