⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 getcap.3

📁 早期freebsd实现
💻 3
字号:
.\" Copyright (c) 1992, 1993.\"	The Regents of the University of California.  All rights reserved..\".\" This code is derived from software contributed to Berkeley by.\" Casey Leedom of Lawrence Livermore National Laboratory..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\"    notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\"    notice, this list of conditions and the following disclaimer in the.\"    documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\"    must display the following acknowledgement:.\"	This product includes software developed by the University of.\"	California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\"    may be used to endorse or promote products derived from this software.\"    without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\"	@(#)getcap.3	8.3 (Berkeley) 4/19/94.\".Dd "April 19, 1994".Dt GETCAP 3 .Os.Sh NAME.Nm cgetent ,.Nm cgetset ,.Nm cgetmatch ,.Nm cgetcap ,.Nm cgetnum ,.Nm cgetstr ,.Nm cgetustr ,.Nm cgetfirst ,.Nm cgetnext ,.Nm cgetclose.Nd capability database access routines.Sh SYNOPSIS.Fd #include <stdlib.h>.Ft int.Fn cgetent "char **buf" "char **db_array" "char *name".Ft int.Fn cgetset "char *ent".Ft int.Fn cgetmatch "char *buf" "char *name".Ft char *.Fn cgetcap "char *buf" "char *cap" "char type".Ft int.Fn cgetnum "char *buf" "char *cap" "long *num".Ft int.Fn cgetstr "char *buf" "char *cap" "char **str".Ft int.Fn cgetustr "char *buf" "char *cap" "char **str".Ft int.Fn cgetfirst "char **buf" "char **db_array".Ft int.Fn cgetnext "char **buf" "char **db_array".Ft int.Fn cgetclose "void".Sh DESCRIPTION.Fn Cgetentextracts the capability rec.Fa namefrom the database specified by the.Dv NULLterminated file array.Fa db_arrayand returns a pointer to a.Xr malloc Ns \&'dcopy of it in.Fa buf .  .Nm Cgetentwill first look for files ending in .Nm .db (see.Xr cap_mkdb 1) before accessing the ASCII file..Fa Bufmust be retained through all subsequent calls to.Fn cgetmatch ,.Fn cgetcap ,.Fn cgetnum ,.Fn cgetstr ,and.Fn cgetustr ,but may then be.Xr free Ns \&'d.On success 0 is returned, 1 if the returnedrecord contains an unresolved .Nm tc expansion,\-1 if the requested record couldn't be found,\-2 if a system error was encountered (couldn't open/read a file, etc.) alsosetting.Va errno , and \-3 if a potential reference loop is detected (see.Ic tc=comments below)..Pp.Nm Cgetset enables the addition of a character buffer containing a single capabilityrecord entryto the capability database.  Conceptually, the entry is added as the first ``file'' in the database, andis therefore searched first on the call to .Nm cgetent .The entry is passed in .Fa ent .If .Fa ent is.Dv NULL ,the current entry is removed from the database.  .Nm Cgetset must precede the database traversal.  It must be called before the .Nm cgetent call. If a sequential access is being performed (see below), it must be calledbefore the first sequential access call (.Nm cgetfirstor.Nm cgetnext), or be directly preceded by a .Nm cgetclosecall.On success 0 is returned and \-1 on failure..Pp.Nm Cgetmatchwill return 0 if.Fa nameis one of the names of the capability record.Fa buf ,\-1 ifnot..Pp.Nm Cgetcapsearches the capability record.Fa buffor the capability.Fa capwith type.Fa type .A.Fa typeis specified using any single character.  If a colon (`:') is used, anuntyped capability will be searched for (see below for explanation oftypes).  A pointer to the value of.Fa capin.Fa bufis returned on success,.Dv NULLif the requested capability couldn't befound.  The end of the capability value is signaled by a `:' or.Tn ASCII.Dv NUL(see below for capability database syntax)..Pp.Nm Cgetnumretrieves the value of the numeric capability.Fa capfrom the capability record pointed to by.Fa buf .The numeric value is returned in the.Ft longpointed to by.Fa num .0 is returned on success, \-1 if the requested numeric capability couldn'tbe found..Pp.Nm Cgetstrretrieves the value of the string capability.Fa capfrom the capability record pointed to by.Fa buf .A pointer to a decoded,.Dv NULterminated,.Xr malloc Ns \&'dcopy of the string is returned in the.Ft char *pointed to by.Fa str .The number of characters in the decoded string not including the trailing.Dv NULis returned on success, \-1 if the requested string capability couldn'tbe found, \-2 if a system error was encountered (storage allocationfailure)..Pp.Nm Cgetustris identical to .Nm cgetstr except that it does not expand special characters, but rather returns eachcharacter of the capability string literally..Pp.Nm Cgetfirst ,.Nm cgetnext , comprise a function group that provides for sequentialaccess of the.Dv NULLpointer terminated array of file names,.Fa db_array ..Nm Cgetfirst returns the first record in the database and resets the accessto the first record..Nm Cgetnext returns the next record in the database with respect to therecord returned by the previous.Nm cgetfirstor.Nm cgetnext call.  If there is no such previous call, the first record in the database isreturned.Each record is returned in a.Xr malloc Ns \&'d copy pointed to by .Fa buf .  .Ic Tcexpansion is done (see.Ic tc= comments below).Upon completion of the database 0 is returned,  1 is returned upon successfulreturn of record with possibly more remaining (we haven't reached the end of the database yet), 2 is returned if the record contains an unresolved.Nm tc expansion, \-1 is returned if an system error occurred, and \-2is returned if a potential reference loop is detected (see .Ic tc=comments below).Upon completion of database (0 return) the database is closed..Pp.Nm Cgetclose closes the sequential access and frees any memory and file descriptors being used.  Note that it does not erase the buffer pushed by a call to .Nm cgetset ..Sh CAPABILITY DATABASE SYNTAXCapability databases are normally.Tn ASCIIand may be edited with standardtext editors.  Blank lines and lines beginning with a `#' are commentsand are ignored.  Lines ending with a `\|\e' indicate that the next lineis a continuation of the current line; the `\|\e' and following newlineare ignored.  Long lines are usually continued onto several physicallines by ending each line except the last with a `\|\e'..PpCapability databases consist of a series of records, one per logicalline.  Each record contains a variable number of `:'-separated fields(capabilities).  Empty fields consisting entirely of white spacecharacters (spaces and tabs) are ignored..PpThe first capability of each record specifies its names, separated by `|'characters.  These names are used to reference records in the database.By convention, the last name is usually a comment and is not intended asa lookup tag.  For example, the.Em vt100record from the.Nm termcapdatabase begins:.Pp.Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:".Ppgiving four names that can be used to access the record..PpThe remaining non-empty capabilities describe a set of (name, value)bindings, consisting of a names optionally followed by a typed values:.Bl -column "nameTvalue".It name Ta "typeless [boolean] capability".Em name No "is present [true]".It name Ns Em \&T Ns value Ta capability.Pq Em name , \&Thas value.Em value.It name@ Ta "no capability" Em name No exists.It name Ns Em T Ns \&@ Ta capability.Pq Em name , Tdoes not exist.El.PpNames consist of one or more characters.  Names may contain any characterexcept `:', but it's usually best to restrict them to the printablecharacters and avoid use of graphics like `#', `=', `%', `@', etc.  Typesare single characters used to separate capability names from theirassociated typed values.  Types may be any character except a `:'.Typically, graphics like `#', `=', `%', etc. are used.  Values may be anynumber of characters and may contain any character except `:'..Sh CAPABILITY DATABASE SEMANTICSCapability records describe a set of (name, value) bindings.  Names mayhave multiple values bound to them.  Different values for a name aredistinguished by their.Fa types ..Nm Cgetcapwill return a pointer to a value of a name given the capability name andthe type of the value..PpThe types `#' and `=' are conventionally used to denote numeric andstring typed values, but no restriction on those types is enforced.  Thefunctions.Nm cgetnumand.Nm cgetstrcan be used to implement the traditional syntax and semantics of `#'and `='.Typeless capabilities are typically used to denote boolean objects withpresence or absence indicating truth and false values respectively.This interpretation is conveniently represented by:.Pp.Dl "(getcap(buf, name, ':') != NULL)".PpA special capability,.Ic tc= name ,is used to indicate that the record specified by.Fa nameshould be substituted for the.Ic tccapability..Ic Tccapabilities may interpolate records which also contain.Ic tccapabilities and more than one.Ic tccapability may be used in a record.  A.Ic tcexpansion scope (i.e., where the argument is searched for) contains thefile in which the.Ic tcis declared and all subsequent files in the file array..PpWhen a database is searched for a capability record, the first matchingrecord in the search is returned.  When a record is scanned for acapability, the first matching capability is returned; the capability.Ic :nameT@:will hide any following definition of a value of type.Em Tfor.Fa name ;and the capability.Ic :name@:will prevent any following values of.Fa namefrom being seen..PpThese features combined with.Ic tccapabilities can be used to generate variations of other databases andrecords by either adding new capabilities, overriding definitions with newdefinitions, or hiding following definitions via `@' capabilities..Sh EXAMPLES.Bd -unfilled -offset indentexample\||\|an example of binding multiple values to names:\e	:foo%bar:foo^blah:foo@:\e	:abc%xyz:abc^frap:abc$@:\e	:tc=more:.Ed.PpThe capability foo has two values bound to it (bar of type `%' and blah oftype `^') and any other value bindings are hidden.  The capability abcalso has two values bound but only a value of type `$' is prevented frombeing defined in the capability record more..Pp.Bd -unfilled -offset indentfile1: 	new\||\|new_record\||\|a modification of "old":\e		:fript=bar:who-cares@:tc=old:blah:tc=extensions:file2:	old\||\|old_record\||\|an old database record:\e		:fript=foo:who-cares:glork#200:.Ed.PpThe records are extracted by calling.Nm cgetentwith file1 preceding file2.In the capability record new in file1, fript=bar overrides the definitionof fript=foo interpolated from the capability record old in file2,who-cares@ prevents the definition of any who-cares definitions in oldfrom being seen, glork#200 is inherited from old, and blah and anythingdefined by the record extensions is added to those definitions in old.Note that the position of the fript=bar and who-cares@ definitions beforetc=old is important here.  If they were after, the definitions in oldwould take precedence..Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICSTwo types are predefined by.Nm cgetnumand.Nm cgetstr :.Bl -column "nameXnumber".Sm off.It Em name No \&# Em number Ta numericcapability.Em namehas value.Em number.It Em name No = Em string Ta "string capability".Em namehas value .Em string.It Em name No \&#@ Ta "the numeric capability".Em namedoes not exist.It Em name No \&=@ Ta "the string capability".Em namedoes not exist.El.PpNumeric capability values may be given in one of three numeric bases.If the number starts with either.Ql 0xor.Ql 0Xit is interpreted as a hexadecimal number (both upper and lower case a-fmay be used to denote the extended hexadecimal digits).Otherwise, if the number starts with a.Ql 0it is interpreted as an octal number.Otherwise the number is interpreted as a decimal number..PpString capability values may contain any character.  Non-printable.Dv ASCIIcodes, new lines, and colons may be conveniently represented by the useof escape sequences:.Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"^X	('\fIX\fP' & 037)	control-\fIX\fP\e\|b, \e\|B	(ASCII 010)	backspace\e\|t, \e\|T	(ASCII 011)	tab\e\|n, \e\|N	(ASCII 012)	line feed (newline)\e\|f, \e\|F	(ASCII 014)	form feed\e\|r, \e\|R	(ASCII 015)	carriage return\e\|e, \e\|E	(ASCII 027)	escape\e\|c, \e\|C	(:)	colon\e\|\e	(\e\|)	back slash\e\|^	(^)	caret\e\|\fInnn\fP	(ASCII octal \fInnn\fP).El.PpA `\|\e' may be followed by up to three octal digits directly specifiesthe numeric code for a character.  The use of.Tn ASCII.Dv NUL Ns s ,while easilyencoded, causes all sorts of problems and must be used with care since.Dv NUL Ns sare typically used to denote the end of strings; many applicationsuse `\e\|200' to represent a.Dv NUL ..Sh DIAGNOSTICS.Nm Cgetent ,.Nm cgetset ,.Nm cgetmatch ,.Nm cgetnum ,.Nm cgetstr ,.Nm cgetustr ,.Nm cgetfirst ,and.Nm cgetnextreturn a value greater than or equal to 0 on success and a value lessthan 0 on failure..Nm Cgetcapreturns a character pointer on success and a.Dv NULLon failure..Pp.Nm Cgetent ,and .Nm cgetseqmay fail and set .Va errnofor any of the errors specified for the library functions:.Xr fopen 2 , .Xr fclose 2 ,.Xr open 2 ,and .Xr close 2 ..Pp.Nm Cgetent ,.Nm cgetset ,.Nm cgetstr ,and.Nm cgetustr may fail and set .Va errno as follows:.Bl -tag -width Er.It Bq Er ENOMEMNo memory to allocate..El.Sh SEE ALSO.Xr cap_mkdb 1 ,.Xr malloc 3.Sh BUGSColons (`:') can't be used in names, types, or values..PpThere are no checks for.Ic tc= nameloops in.Nm cgetent ..PpThe buffer added to the database by a call to .Nm cgetset is not unique to the database but is rather prepended to any database used.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -