rflag(3)

rflag3

Bit flag routines

Usage

#include <roy.h>

RFLAG_FLAGS (struct);

RFLAG_SET (struct, flag);

RFLAG_UNSET (struct, flag);

RFLAG_ISSET (struct, flag);

RFLAG_ONLYSET (struct, flag);

Overview

These are a set of macros for setting, clearing and checking bit flags as found in a number of structures. In order for this to work, the structure must have a 'flags' member, for which you create an enumerated list of bit flags.

RFLAG_FLAGS(3) returns the struct->flags member.

RFLAG_SET(3) sets the value of flag in the flags member in struct. This is done using the bitwise & operator.

RFLAG_UNSET(3) clears the value of flag in the flags member in struct.

RFLAG_ISSET(3) returns the TRUE if the flag flag is set, or FALSE if unset.

RFLAG_ONLYSET(3) returns TRUE if flag is the only bit turned on in the flags member of struct.

Macros

These calls are all implemented with macros.

Examples

/* Create an enumerated list of flags. */

typedef enum {
FOO_NEEDS_BAR = 1 << 0,
FOO_NEEDS_BAZ = 1 << 1,
FOO_NEEDS_BAX = 1 << 2 } MyFlags;

/* Create a structure with a flags member. */

typedef struct {
/* ... */
unsigned int flags;
/* ... */ } MyStruct;

/* Example setting/checking. */

void foo (void) {
MyStruct *mys;

    /* ... */
    RFLAG_SET (mys, FOO_NEEDS_BAR);
    if (RFLAG_ISSET (mys, FOO_NEEDS_BAZ)) {
        /* do something.. */
    }
    RFLAG_UNSET (mys, FOO_NEEDS_BAR);
}

Releases

2 releases since Debian 3.0 (Woody); the text changed 1 time.

  1. 3.0
  2. 3.1

From libroy-dev 1.0.8-1 in Debian 3.1 (Sarge). Parsed by carta from the page's man source.