1 .\" $NetBSD: cgetcap.3,v 1.5 2008/08/26 05:04:19 lukem Exp $
3 .\" Copyright (c) 1992, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" This code is derived from software contributed to Berkeley by
7 .\" Casey Leedom of Lawrence Livermore National Laboratory.
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
17 .\" 3. Neither the name of the University nor the names of its contributors
18 .\" may be used to endorse or promote products derived from this software
19 .\" without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" @(#)getcap.3 8.4 (Berkeley) 5/13/94
50 .Nd capability database access routines
56 .Fn cgetent "char **buf" "const char * const *db_array" "const char *name"
58 .Fn cgetset "const char *ent"
60 .Fn cgetmatch "const char *buf" "const char *name"
62 .Fn cgetcap "char *buf" "const char *cap" "int type"
64 .Fn cgetnum "char *buf" "const char *cap" "long *num"
66 .Fn cgetstr "char *buf" "const char *cap" "char **str"
68 .Fn cgetustr "char *buf" "const char *cap" "char **str"
70 .Fn cgetfirst "char **buf" "const char * const *db_array"
72 .Fn cgetnext "char **buf" "const char * const *db_array"
76 .Fn csetexpandtc "int expandtc"
79 extracts the capability
81 from the database specified by the
85 and returns a pointer to a
90 will first look for files ending in
99 must be retained through all subsequent calls to
109 On success 0 is returned, 1 if the returned record contains an unresolved
111 expansion, \-1 if the requested record couldn't be found, \-2 if
112 a system error was encountered (couldn't open/read a file, etc.)
115 and \-3 if a potential reference loop is detected (see
120 enables the addition of a character buffer containing a single capability
121 record entry to the capability database.
122 Conceptually, the entry is added as the first
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.
137 It must be called before the
140 If a sequential access is being performed (see below), it must be called
141 before the first sequential access call
147 or be directly preceded by a
150 On success 0 is returned and \-1 on failure.
155 is one of the names of the capability record
160 searches the capability record
168 is specified using any single character.
171 is used, an untyped capability will be searched
172 for (see below for explanation of types).
173 A pointer to the value of
177 is returned on success,
179 if the requested capability couldn't be found.
180 The end of the capability value is signaled by a
185 (see below for capability database syntax).
188 retrieves the value of the numeric capability
190 from the capability record pointed to by
192 The numeric value is returned in the
196 0 is returned on success,
197 \-1 if the requested numeric capability couldn't be found.
200 retrieves the value of the string capability
202 from the capability record pointed to by
204 A pointer to a decoded,
208 copy of the string is returned in the
212 The number of characters in the decoded string not including the trailing
214 is returned on success, \-1 if the requested string capability couldn't
215 be found, \-2 if a system error was encountered (storage allocation
221 except that it does not expand special characters, but rather returns each
222 character of the capability string literally.
226 comprise a function group that provides for sequential access of the
228 pointer terminated array of file names,
231 returns the first record in the database and resets the access
234 returns the next record in the database with respect to the
235 record returned by the previous
240 If there is no such previous call,
241 the first record in the database is returned.
242 Each record is returned in a
247 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.
262 closes the sequential access and frees any memory and file descriptors
264 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 text editors.
270 Blank lines and lines beginning with a
272 are comments and are ignored.
275 indicate that the next line is a continuation
276 of the current line; the
278 and following newline are ignored.
279 Long lines are usually continued onto several physical
280 lines by ending each line except the last with a
283 Capability databases consist of a series of records, one per logical line.
284 Each record contains a variable number of
285 .So \&: Sc Ns -separated
286 fields (capabilities).
287 Empty fields consisting entirely of white space
288 characters (spaces and tabs) are ignored.
290 The first capability of each record specifies its names, separated by
293 These names are used to reference records in the database.
294 By convention, the last name is usually a comment and is not intended as
302 .Dl "d0\||\|vt100\||\|vt100-am\||\|vt100am\||\|dec vt100:"
304 giving four names that can be used to access the record.
306 The remaining non-empty capabilities describe a set of (name, value)
307 bindings, consisting of a name optionally followed by a typed value:
308 .Bl -column "nameTvalue"
309 .It name Ta "typeless [boolean] capability"
310 .Em name No "is present [true]"
311 .It name Ns Em \&T Ns value Ta capability
315 .It name@ Ta "no capability" Em name No exists
316 .It name Ns Em T Ns \&@ Ta capability
321 Names consist of one or more characters.
322 Names may contain any character except
324 but it's usually best
325 to restrict them to the printable characters and avoid use of
333 Types are single characters used to separate capability names from
334 their associated typed values.
335 Types may be any character except a
337 Typically, graphics like
342 Values may be any number of characters and may contain any character except
344 .Sh CAPABILITY DATABASE SEMANTICS
345 Capability records describe a set of (name, value) bindings.
346 Names may have multiple values bound to them.
347 Different values for a name are distinguished by their
350 will return a pointer to a value of a name given the capability name and
351 the type of the value.
357 are conventionally used to denote numeric and
358 string typed values, but no restriction on those types is enforced.
363 can be used to implement the traditional syntax and semantics of
367 Typeless capabilities are typically used to denote boolean objects with
368 presence or absence indicating truth and false values respectively.
369 This interpretation is conveniently represented by:
371 .Dl "(getcap(buf, name, ':') != NULL)"
373 A special capability,
375 is used to indicate that the record specified by
377 should be substituted for the
381 capabilities may interpolate records which also contain
383 capabilities and more than one
385 capability may be used in a record.
388 expansion scope (i.e. where the argument is searched for) contains the
391 is declared and all subsequent files in the file array.
394 can be used to control if
396 expansion is performed or not.
398 When a database is searched for a capability record, the first matching
399 record in the search is returned.
400 When a record is scanned for a capability, the first matching
401 capability is returned; the capability
403 will hide any following definition of a value of type
409 will prevent any following values of
413 These features combined with
415 capabilities can be used to generate variations of other databases and
416 records by either adding new capabilities, overriding definitions with new
417 definitions, or hiding following definitions via
421 .Bd -unfilled -offset indent
422 example\||\|an example of binding multiple values to names:\e
423 :foo%bar:foo^blah:foo@:\e
424 :abc%xyz:abc^frap:abc$@:\e
430 has two values bound to it
440 and any other value bindings are hidden.
443 also has two values bound but only a value of type
446 being defined in the capability record more.
448 .Bd -unfilled -offset indent
450 new\||\|new_record\||\|a modification of "old":\e
451 :fript=bar:who-cares@:tc=old:blah:tc=extensions:
453 old\||\|old_record\||\|an old database record:\e
454 :fript=foo:who-cares:glork#200:
457 The records are extracted by calling
463 In the capability record
468 overrides the definition of
470 interpolated from the capability record
475 prevents the definition of any who-cares definitions in
483 and anything defined by the record extensions is added to those
486 Note that the position of the
493 If they were after, the definitions in
495 would take precedence.
496 .Sh CGETNUM AND CGETSTR SYNTAX AND SEMANTICS
497 Two types are predefined by
501 .Bl -column "nameXnumber"
502 .It Em name Ns \&# Ns Em number Ta numeric
507 .It Em name Ns = Ns Em string Ta "string capability"
511 .It Em name Ns \&#@ Ns Ta "the numeric capability"
514 .It Em name Ns \&=@ Ns Ta "the string capability"
519 Numeric capability values may be given in one of three numeric bases.
520 If the number starts with either
524 it is interpreted as a hexadecimal number (both upper and lower case a-f
525 may be used to denote the extended hexadecimal digits).
526 Otherwise, if the number starts with a
528 it is interpreted as an octal number.
529 Otherwise the number is interpreted as a decimal number.
531 String capability values may contain any character.
534 codes, new lines, and colons may be conveniently represented by the use
536 .Bl -column "\e\|X,X\e\|X" "(ASCII octal nnn)"
537 .It ^X ('\fIX\fP' \*[Am] 037) control-\fIX\fP
538 .It \e\|b, \e\|B (ASCII 010) backspace
539 .It \e\|t, \e\|T (ASCII 011) tab
540 .It \e\|n, \e\|N (ASCII 012) line feed (newline)
541 .It \e\|f, \e\|F (ASCII 014) form feed
542 .It \e\|r, \e\|R (ASCII 015) carriage return
543 .It \e\|e, \e\|E (ASCII 027) escape
544 .It \e\|c, \e\|C (:) colon
545 .It \e\|\e (\e\|) back slash
547 .It \e\|\fInnn\fP (ASCII octal \fInnn\fP)
552 followed by up to three octal digits directly specifies
553 the numeric code for a character.
558 encoded, causes all sorts of problems and must be used with care since
560 are typically used to denote the end of strings; many applications
575 return a value greater than or equal to 0 on success and a value less
578 returns a character pointer on success and a
589 for any of the errors specified for the library functions:
606 No memory to allocate.
614 can't be used in names, types, or values.
616 There are no checks for
621 The buffer added to the database by a call to
623 is not unique to the database but is rather prepended to any database used.