Home | History | Annotate | Download | only in man3

$Id: parse_open_flags.3,v 1.1 2000/07/27 16:59:03 alaffin Exp $

Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.

This program is free software; you can redistribute it and/or modify it
under the terms of version 2 of the GNU General Public License as
published by the Free Software Foundation.

This program is distributed in the hope that it would be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Further, this software is distributed without any warranty that it is
free of the rightful claim of any third person regarding infringement
or the like. Any license provided herein, whether implied or
otherwise, applies only to this software file. Patent licenses, if
any, provided herein do not apply to combinations of this program with
other software, or any other product whatsoever.

You should have received a copy of the GNU General Public License along
with this program; if not, write the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
Mountain View, CA 94043, or:

http://www.sgi.com

For further information regarding this notice, see:

http://oss.sgi.com/projects/GenInfo/NoticeExplan/

PARSE_OPEN_FLAGS 3 07/25/2000 "Linux Test Project"
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) flag symbols (i.e. O_TRUNC) into the bitmask that can be used by open(2). 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), /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 openflagsbits\n\t%s symbols\n", argv[0], argv[0]);
 exit(1);
 }

 if ( sscanf(argv[1], "%i", &bits) == 1 ) {
 printf("openflags2symbols(%#o, \",\", 1) returned %s\n",
 bits, openflags2symbols(bits, ",", 1));

 } else {
 ret=parse_open_flags(argv[1], &err);
 if ( ret == -1 )
 printf("parse_open_flags(%s, &err) returned -1, err = %s\n",
 argv[0], err);
 else
 printf("parse_open_flags(%s, &err) returned %#o\n", 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.