---
name: "parse_open_flags"
section: "3"
platform: "linux"
package: "ltp-dev"
version: "20091231+dfsg-1"
release: "Debian 6.0 (Squeeze)"
platforms: ["linux"]
url: "https://new.carta.tech/parse_open_flags"
---

# parse\_open\_flags(3)

converts open flag symbols into bitmask openflags2symbols - converts open flag bitmask into symbols

## NAME

parse\_open\_flags - converts open flag symbols into bitmask\
 openflags2symbols - converts open flag bitmask into symbols

## SYNOPSIS

int\
 **parse\_open\_flags**(*symbols, badname*)\
 char \**symbols*;\
 char \*\**badname*;

char \*\
 **openflags2symbols**(*openflags, sep, mode*)\
 int *openflags*;\
 char \**sep*;\
 int *mode*;

## DESCRIPTION

The **parse\_open\_flags** function can be used to convert a list of comma separated [**open**(2)](/open/2.md) flag symbols (i.e. O\_TRUNC) into the bitmask that can be used by [open(2)](/open/2.md). If a symbol is unknown and *badname* is not NULL, *badname* will updated to point that symbol in *symbols*. **Parse\_open\_flags** will return -1 on this error. Otherwise **parse\_open\_flags** will return the open flag bitmask. If **parse\_open\_flags** returns, *string* will left unchanged.

The **openflags2symbols** function attempts to convert open flag bits into human readable  symbols (i.e. O\_TRUNC).  If there are more than one symbol, the **sep** string will be placed as a separator between symbols.  Commonly used separators would be a comma "," or pipe "\|".  If *mode* is one and not all *openflags* bits can be converted to symbols, the **UNKNOWN** symbol will be added to return string. Openflags2symbols will return the identified symbols. If no symbols are recognized the return value will be a empty string or the **UNKNOWN** symbol.

If the **O\_WRONLY** and **O\_RDWR** bits are not set, **openflags2symbols** assumes that **O\_RDONLY** symbol is wanted.

## SEE ALSO

[open(2)](/open/2.md), /usr/include/sys/fcntl.h.

## EXAMPLES

```
/*
 * The following code provides a UNIT test main for
 * parse_open_flags and openflags2symbols functions.
 */
#include <stdio.h>
main(argc, argv)
int argc;
char **argv;
{
    int bits;
    int ret;
    char *err;
    if (argc == 1 ) {
        printf("Usage: %s openflagsbits0t%s symbols0, argv[0], argv[0]);
        exit(1);
    }
    if ( sscanf(argv[1], "%i", &bits) == 1 ) {
        printf("openflags2symbols(%#o,
            bits, openflags2symbols(bits, ",", 1));
    } else {
        ret=parse_open_flags(argv[1], &err);
        if ( ret == -1 )
            printf("parse_open_flags(%s, &err) returned -1, err = %s0,
                argv[0], err);
        else
            printf("parse_open_flags(%s, &err) returned %#o0, argv[0], ret);
    }
    exit(0);
}
```

## LIMITATIONS

Currently (06/96) all known symbols are coded into **openflags2symbols**. If new open flags are added this function code will have to updated to know about them or they will not be recognized.

The static space where **openflags2symbols** stores open flag symbols with callers separators is limited to 512 characters. This should be large enough for most open flags symbols as long as the separator is kept short.
