---
name: "selinux_file_context_cmp"
section: "3"
platform: "linux"
package: "libselinux1-dev"
version: "3.8.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/selinux_file_context_cmp"
---

# selinux\_file\_context\_cmp(3)

Compare two SELinux security contexts excluding the 'user' component

## NAME

selinux\_file\_context\_cmp - Compare two SELinux security contexts excluding the 'user' component

## SYNOPSIS

**#include \<selinux/selinux.h\>**

**int selinux\_file\_context\_cmp(const char \****a***,**

**const char \****b***);**

## DESCRIPTION

**selinux\_file\_context\_cmp**() compares two context strings excluding the user component with [**strcmp**(3)](/strcmp/3.md) as shown in the **EXAMPLE** section.

This is useful as for most object contexts, the user component is not relevant.

## RETURN VALUE

The return values follow the [**strcmp**(3)](/strcmp/3.md) function, where:

0  if they are equal.

1  if *a* is greater than *b*

\-1 if *a* is less than *b*

## ERRORS

None.

## NOTES

The contexts being compared do not specifically need to be file contexts.

## EXAMPLE

If context *a* is:

user\_u:user\_r:user\_t:s0

and context *b* is:

root:user\_r:user\_t:s0

then the actual strings compared are:

:user\_r:user\_t:s0 and :user\_r:user\_t:s0

Therefore they will match and **selinux\_file\_context\_cmp**() will return zero.

## SEE ALSO

[**selinux**(8)](/selinux/8.md)
