---
name: "rtapi_open_as_root"
section: "3rtapi"
platform: "linux"
package: "linuxcnc-uspace-dev"
version: "1:2.9.4-2+deb13u1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/rtapi_open_as_root"
---

# rtapi\_open\_as\_root(3rtapi)

Open a file with "root" privilege

## NAME

rtapi\_open\_as\_root - Open a file with "root" privilege

## SYNTAX

```
#include <rtapi.h>
int rtapi_open_as_root(const char *filename, int flags)
```

## ARGUMENTS

- *filename*

  The filename to open, as in **[open(2)](/open/2.md)**.  Note that rtapi has no well-defined "current directory", so this should be an absolute path, but this is not enforced.

- *flags*

  The open flags, as in **[open(2)](/open/2.md)**.  Should never include bits that open or create files (e.g., O\_CREAT, O\_APPEND, etc) as this API is not intended for creating or writing files, but this is not enforced.

## DESCRIPTION

In "uspace" realtime, root privileges are dropped whenever possible.  This API temporarily switches on root privileges to open a file, and switches them off before returning.  This can be useful for example when accessing device nodes or memory-mapped I/O.

In the case of PCI devices on x86 and x86-64 systems, prefer the linux-style PCI interfaces provided in **\<rtapi\_pci.h\>**.

## RETURN VALUE

In case of success, the nonnegative file descriptor opened.  If the caller does not close it, it remains open until rtapi\_app exits.

In case of failure, a negative errno value.

## REALTIME CONSIDERATIONS

Call only from realtime initcode in "uspace" realtime.

## SEE ALSO

**[open(2)](/open/2.md)**, **rtapi\_pci(3)**
