---
name: "rlist"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rlist"
---

# rlist(3)

Roy doublely linked list implementation

## NAME

rlist - Roy doublely linked list implementation

## SYNOPSIS

\#include \<roy.h\>

## DESCRIPTION

The rlist code strings together list entries wihout having the over head of the extra pointer dereference. These list entries are defined and allocated by the user.

- The User Defined Entry

  In order to use these lists, you must create your own structure to be used as the entrys of the list.  This structure \*MUST\* start with the first entry as 'RLIST\_HEADER;'.

  ```
          struct FooEntry {
                  RLIST_HEADER;
                  char *foodata;
                  /* ... */
          };
  ```

  You can create the toplevel RList structure by using [*rlist\_new*(3)](/rlist_new/3.md) (free with [*rlist\_free*(3)](/rlist_free/3.md)), or you can allocate the list structure yourself, and call RLIST\_INIT(list) on it.  This initializes the list, setting up the tail and head pointers.

- RLIST\_INIT (list)

  Initialize a newly created list structure. The 'list' argument needs to be an RList struct.

  ```
          {
                  RList list;
  ```

  ```
                  RLIST_INIT (&list);
                  /* ... rlist functions ... */
          }
  ```

- RLIST\_DESTRUCT (list)

  Set the head and tail pointers of the 'list' argument to point to NULL, effectivly destorying the list.

  ```
          {
                  RList list;
  ```

  ```
                  RLIST_INIT (&list);
                  /* ... */
                  RLIST_DESTRUCT (&list);
          }
  ```

- RLIST\_FOREACH (list, entry)

  This macro walks through a list, assigning 'entry' to the list item through each iteration.  The programmer can use `"break"`, `"continue"`, or `"goto"` safely.  All rlist functions except [*rlist\_free*(3)](/rlist_free/3.md) can be called safely inside the RLIST\_FOREACH macro.  Note that this includes [*rlist\_remove*(3)](/rlist_remove/3.md) on the current item.  Operations should not be performed on the next item in the list however, as a pointer is kept to that item through each iteration.

  ```
          RLIST_FOREACH (list, entry) {
                  if (entry->foodata == NULL)
                          break;
                  printf ("Data: %s.\n", entry->foodata);
          } RFOREACH_CLOSE;
  ```

- RLIST\_FOREACH\_REVERSE (list, entry)

  Same as RLIST\_FOREACH, but start at the end of the list, and walk backwards.

## SEE ALSO

[*rlist\_append*(3)](/rlist_append/3.md), [*rlist\_compare*(3)](/rlist_compare/3.md),  [*rlist\_first*(3)](/rlist_first/3.md), [*rlist\_free*(3)](/rlist_free/3.md),  [*rlist\_last*(3)](/rlist_last/3.md), [*rlist\_new*(3)](/rlist_new/3.md),  [*rlist\_next*(3)](/rlist_next/3.md), [*rlist\_nth*(3)](/rlist_nth/3.md),  [*rlist\_prepend*(3)](/rlist_prepend/3.md), [*rlist\_prev*(3)](/rlist_prev/3.md),  [*rlist\_remove*(3)](/rlist_remove/3.md), [*roy*(3)](/roy/3.md)
