1 .\" Copyright (c) 1992, 1993
2 .\" The Regents of the University of California. All rights reserved.
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Casey Leedom of Lawrence Livermore National Laboratory.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by the University of
18 .\" California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\" may be used to endorse or promote products derived from this software
21 .\" without specific prior written permission.
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 .\" @(#)getcap.3 8.4 (Berkeley) 5/13/94
36 .\" $FreeBSD: src/lib/libc/gen/getcap.3,v 1.20 2001/10/01 16:08:50 ru Exp $
52 .Nd capability database access routines
58 .Fn cgetent "char **buf" "char **db_array" "char *name"
60 .Fn cgetset "char *ent"
62 .Fn cgetmatch "char *buf" "char *name"
64 .Fn cgetcap "char *buf" "char *cap" "int type"
66 .Fn cgetnum "char *buf" "char *cap" "long *num"
68 .Fn cgetstr "char *buf" "char *cap" "char **str"
70 .Fn cgetustr "char *buf" "char *cap" "char **str"
72 .Fn cgetfirst "char **buf" "char **db_array"
74 .Fn cgetnext "char **buf" "char **db_array"
80 function extracts the capability
82 from the database specified by the
86 and returns a pointer to a
92 function will first look for files ending in
96 before accessing the ASCII file.
98 must be retained through all subsequent calls to
107 On success 0 is returned, 1 if the returned
108 record contains an unresolved
111 \-1 if the requested record couldn't be found,
112 \-2 if a system error was encountered (couldn't open/read a file, etc.) also
115 and \-3 if a potential reference loop is detected (see
121 function enables the addition of a character buffer containing a single capability
123 to the capability database.
124 Conceptually, the entry is added as the first ``file'' in the database, and
125 is therefore searched first on the call to
127 The entry is passed in
133 the current entry is removed from the database.
136 must precede the database traversal. It must be called before the
138 call. If a sequential access is being performed (see below), it must be called
139 before the first sequential access call
143 or be directly preceded by a
146 On success 0 is returned and \-1 on failure.
150 function will return 0 if
152 is one of the names of the capability record
159 function searches the capability record
167 is specified using any single character. If a colon (`:') is used, an
168 untyped capability will be searched for (see below for explanation of
169 types). A pointer to the value of
173 is returned on success,
175 if the requested capability couldn't be
176 found. The end of the capability value is signaled by a `:' or
179 (see below for capability database syntax).
183 function retrieves the value of the numeric capability
185 from the capability record pointed to by
187 The numeric value is returned in the
191 0 is returned on success, \-1 if the requested numeric capability couldn't
196 function retrieves the value of the string capability
198 from the capability record pointed to by
200 A pointer to a decoded,
204 copy of the string is returned in the
208 The number of characters in the decoded string not including the trailing
210 is returned on success, \-1 if the requested string capability couldn't
211 be found, \-2 if a system error was encountered (storage allocation
216 function is identical to
218 except that it does not expand special characters, but rather returns each
219 character of the capability string literally.
225 functions comprise a function group that provides for sequential
228 pointer terminated array of file names,
232 function returns the first record in the database and resets the access
236 function returns the next record in the database with respect to the
237 record returned by the previous
241 call. If there is no such previous call, the first record in the database is
243 Each record is returned in a
248 expansion is done (see
251 Upon completion of the database 0 is returned, 1 is returned upon successful
252 return of record with possibly more remaining (we haven't reached the end of
253 the database yet), 2 is returned if the record contains an unresolved
255 expansion, \-1 is returned if an system error occurred, and \-2
256 is returned if a potential reference loop is detected (see
259 Upon completion of database (0 return) the database is closed.
263 function closes the sequential access and frees any memory and file descriptors
264 being used. Note that it does not erase the buffer pushed by a call to
266 .Sh CAPABILITY DATABASE SYNTAX
267 Capability databases are normally
269 and may be edited with standard
270 text editors. Blank lines and lines beginning with a `#' are comments
271 and are ignored. Lines ending with a `\|\e' indicate that the next line
272 is a continuation of the current line; the `\|\e' and following newline
273 are ignored. Long lines are usually continued onto several physical
274 lines by ending each line except the last with a `\|\e'.
276 Capability databases consist of a series of records, one per logical
277 line. Each record contains a variable number of `:'-separated fields
278 (capabilities). Empty fields consisting entirely of white space
279 characters (spaces and tabs) are ignored.
281 The first capability of each record specifies its names, separated by `|'
282 characters. These names are used to reference records in the database.
283 By convention, the last name is usually a comment and is not intended as
284 a lookup tag. For example, the
290 .Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:"
292 giving four names that can be used to access the record.
294 The remaining non-empty capabilities describe a set of (name, value)
295 bindings, consisting of a names optionally followed by a typed value:
296 .Bl -column "nameTvalue"
297 .It name Ta "typeless [boolean] capability"
298 .Em name No "is present [true]"
299 .It name Ns Em \&T Ns value Ta capability
303 .It name@ Ta "no capability" Em name No exists
304 .It name Ns Em T Ns \&@ Ta capability
309 Names consist of one or more characters. Names may contain any character
310 except `:', but it's usually best to restrict them to the printable
311 characters and avoid use of graphics like `#', `=', `%', `@', etc. Types
312 are single characters used to separate capability names from their
313 associated typed values. Types may be any character except a `:'.
314 Typically, graphics like `#', `=', `%', etc. are used. Values may be any
315 number of characters and may contain any character except `:'.
316 .Sh CAPABILITY DATABASE SEMANTICS
317 Capability records describe a set of (name, value) bindings. Names may
318 have multiple values bound to them. Different values for a name are
319 distinguished by their
323 function will return a pointer to a value of a name given the capability
324 name and the type of the value.
326 The types `#' and `=' are conventionally used to denote numeric and
327 string typed values, but no restriction on those types is enforced. The
332 can be used to implement the traditional syntax and semantics of `#'
334 Typeless capabilities are typically used to denote boolean objects with
335 presence or absence indicating truth and false values respectively.
336 This interpretation is conveniently represented by:
338 .Dl "(getcap(buf, name, ':') != NULL)"
340 A special capability,
342 is used to indicate that the record specified by
344 should be substituted for the
348 capabilities may interpolate records which also contain
350 capabilities and more than one
352 capability may be used in a record. A
354 expansion scope (i.e., where the argument is searched for) contains the
357 is declared and all subsequent files in the file array.
359 When a database is searched for a capability record, the first matching
360 record in the search is returned. When a record is scanned for a
361 capability, the first matching capability is returned; the capability
363 will hide any following definition of a value of type
369 will prevent any following values of
373 These features combined with
375 capabilities can be used to generate variations of other databases and
376 records by either adding new capabilities, overriding definitions with new
377 definitions, or hiding following definitions via `@' capabilities.
379 .Bd -unfilled -offset indent
380 example\||\|an example of binding multiple values to names:\e
381 :foo%bar:foo^blah:foo@:\e
382 :abc%xyz:abc^frap:abc$@:\e
386 The capability foo has two values bound to it (bar of type `%' and blah of
387 type `^') and any other value bindings are hidden. The capability abc
388 also has two values bound but only a value of type `$' is prevented from
389 being defined in the capability record more.
391 .Bd -unfilled -offset indent
393 new\||\|new_record\||\|a modification of "old":\e
394 :fript=bar:who-cares@:tc=old:blah:tc=extensions:
396 old\||\|old_record\||\|an old database record:\e
397 :fript=foo:who-cares:glork#200:
400 The records are extracted by calling
402 with file1 preceding file2.
403 In the capability record new in file1, fript=bar overrides the definition
404 of fript=foo interpolated from the capability record old in file2,
405 who-cares@ prevents the definition of any who-cares definitions in old
406 from being seen, glork#200 is inherited from old, and blah and anything
407 defined by the record extensions is added to those definitions in old.
408 Note that the position of the fript=bar and who-cares@ definitions before
409 tc=old is important here. If they were after, the definitions in old
410 would take precedence.
411 .Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
412 Two types are predefined by
416 .Bl -column "nameXnumber"
418 .It Em name No \&# Em number Ta numeric
425 .It Em name No = Em string Ta "string capability"
431 .It Em name No \&#@ Ta "the numeric capability"
436 .It Em name No \&=@ Ta "the string capability"
442 Numeric capability values may be given in one of three numeric bases.
443 If the number starts with either
447 it is interpreted as a hexadecimal number (both upper and lower case a-f
448 may be used to denote the extended hexadecimal digits).
449 Otherwise, if the number starts with a
451 it is interpreted as an octal number.
452 Otherwise the number is interpreted as a decimal number.
454 String capability values may contain any character. Non-printable
456 codes, new lines, and colons may be conveniently represented by the use
458 .Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
459 ^X ('X' & 037) control-X
460 \e\|b, \e\|B (ASCII 010) backspace
461 \e\|t, \e\|T (ASCII 011) tab
462 \e\|n, \e\|N (ASCII 012) line feed (newline)
463 \e\|f, \e\|F (ASCII 014) form feed
464 \e\|r, \e\|R (ASCII 015) carriage return
465 \e\|e, \e\|E (ASCII 027) escape
466 \e\|c, \e\|C (:) colon
467 \e\|\e (\e\|) back slash
469 \e\|nnn (ASCII octal nnn)
472 A `\|\e' may be followed by up to three octal digits directly specifies
473 the numeric code for a character. The use of
477 encoded, causes all sorts of problems and must be used with care since
479 are typically used to denote the end of strings; many applications
480 use `\e\|200' to represent a
494 return a value greater than or equal to 0 on success and a value less
498 function returns a character pointer on success and a
506 functions may fail and set
508 for any of the errors specified for the library functions:
527 No memory to allocate.
533 Colons (`:') can't be used in names, types, or values.
535 There are no checks for
536 .Ic tc Ns = Ns Ic name
540 The buffer added to the database by a call to
542 is not unique to the database but is rather prepended to any database used.