selinux\_file\_context\_cmp(3) Library Functions Manual selinux\_file\_context\_cmp(3)

# [NAME](#NAME)

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

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;selinux/selinux.h&gt;**

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

**const char \*b);**

# [DESCRIPTION](#DESCRIPTION)

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

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

# [RETURN VALUE](#RETURN_VALUE)

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

0 if they are equal.

1 if *a* is greater than *b*

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

# [ERRORS](#ERRORS)

None.

# [NOTES](#NOTES)

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

# [EXAMPLE](#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](#SEE_ALSO)

[**selinux**(8)](/man/os/libselinux/selinux.8)

08 March 2011 SELinux API documentation

---

Document: selinux_file_context_cmp(3) from libselinux 3.11-r2 (Chainguard OS)
Source: https://github.com/SELinuxProject/selinux.git
