JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
man pages section 3: Extended Library Functions
search filter icon
search icon

Document Information

Preface

Extended Library Functions - Part 1

Extended Library Functions - Part 2

Extended Library Functions - Part 3

Extended Library Functions - Part 4

MP_EnableAutoProbing(3MPAPI)

MP_EnablePath(3MPAPI)

MP_FreeOidList(3MPAPI)

mp_gcd(3MP)

MP_GetAssociatedPathOidList(3MPAPI)

MP_GetAssociatedPluginOid(3MPAPI)

MP_GetAssociatedTPGOidList(3MPAPI)

MP_GetDeviceProductOidList(3MPAPI)

MP_GetDeviceProductProperties(3MPAPI)

MP_GetInitiatorPortOidList(3MPAPI)

MP_GetInitiatorPortProperties(3MPAPI)

MP_GetLibraryProperties(3MPAPI)

MP_GetMPLogicalUnitProperties(3MPAPI)

MP_GetMPLuOidListFromTPG(3MPAPI)

MP_GetMultipathLus(3MPAPI)

MP_GetObjectType(3MPAPI)

MP_GetPathLogicalUnitProperties(3MPAPI)

MP_GetPluginOidList(3MPAPI)

MP_GetPluginProperties(3MPAPI)

MP_GetProprietaryLoadBalanceOidList(3MPAPI)

MP_GetProprietaryLoadBalanceProperties(3MPAPI)

MP_GetTargetPortGroupProperties(3MPAPI)

MP_GetTargetPortOidList(3MPAPI)

MP_GetTargetPortProperties(3MPAPI)

mp_itom(3MP)

mp_madd(3MP)

mp_mcmp(3MP)

mp_mdiv(3MP)

mp_mfree(3MP)

mp_min(3MP)

mp_mout(3MP)

mp_msqrt(3MP)

mp_msub(3MP)

mp_mtox(3MP)

mp_mult(3MP)

mp_pow(3MP)

MP_RegisterForObjectPropertyChanges(3MPAPI)

MP_RegisterForObjectVisibilityChanges(3MPAPI)

MP_RegisterPlugin(3MPAPI)

mp_rpow(3MP)

mp_sdiv(3MP)

MP_SetFailbackPollingRate(3MPAPI)

MP_SetLogicalUnitLoadBalanceType(3MPAPI)

MP_SetOverridePath(3MPAPI)

MP_SetPathWeight(3MPAPI)

MP_SetPluginLoadBalanceType(3MPAPI)

MP_SetProbingPollingRate(3MPAPI)

MP_SetProprietaryProperties(3MPAPI)

MP_SetTPGAccess(3MPAPI)

mp_xtom(3MP)

m_setvalues_layout(3LAYOUT)

m_transform_layout(3LAYOUT)

m_wtransform_layout(3LAYOUT)

nan(3M)

nanf(3M)

nanl(3M)

nearbyint(3M)

nearbyintf(3M)

nearbyintl(3M)

new_CplFileConf(3TECLA)

newDmiOctetString(3DMI)

newDmiString(3DMI)

new_ExpandFile(3TECLA)

new_GetLine(3TECLA)

new_PathCache(3TECLA)

new_PcaPathConf(3TECLA)

new_WordCompletion(3TECLA)

nextafter(3M)

nextafterf(3M)

nextafterl(3M)

nexttoward(3M)

nexttowardf(3M)

nexttowardl(3M)

nlist(3ELF)

NOTE(3EXT)

_NOTE(3EXT)

nv_alloc_fini(3NVPAIR)

nv_alloc_init(3NVPAIR)

nv_alloc_reset(3NVPAIR)

nvlist_add_boolean(3NVPAIR)

nvlist_add_boolean_array(3NVPAIR)

nvlist_add_boolean_value(3NVPAIR)

nvlist_add_byte(3NVPAIR)

nvlist_add_byte_array(3NVPAIR)

nvlist_add_int16(3NVPAIR)

nvlist_add_int16_array(3NVPAIR)

nvlist_add_int32(3NVPAIR)

nvlist_add_int32_array(3NVPAIR)

nvlist_add_int64(3NVPAIR)

nvlist_add_int64_array(3NVPAIR)

nvlist_add_int8(3NVPAIR)

nvlist_add_int8_array(3NVPAIR)

nvlist_add_nvlist(3NVPAIR)

nvlist_add_nvlist_array(3NVPAIR)

nvlist_add_nvpair(3NVPAIR)

nvlist_add_string(3NVPAIR)

nvlist_add_string_array(3NVPAIR)

nvlist_add_uint16(3NVPAIR)

nvlist_add_uint16_array(3NVPAIR)

nvlist_add_uint32(3NVPAIR)

nvlist_add_uint32_array(3NVPAIR)

nvlist_add_uint64(3NVPAIR)

nvlist_add_uint64_array(3NVPAIR)

nvlist_add_uint8(3NVPAIR)

nvlist_add_uint8_array(3NVPAIR)

nvlist_alloc(3NVPAIR)

nvlist_dup(3NVPAIR)

nvlist_free(3NVPAIR)

nvlist_lookup_boolean(3NVPAIR)

nvlist_lookup_boolean_array(3NVPAIR)

nvlist_lookup_boolean_value(3NVPAIR)

nvlist_lookup_byte(3NVPAIR)

nvlist_lookup_byte_array(3NVPAIR)

nvlist_lookup_int16(3NVPAIR)

nvlist_lookup_int16_array(3NVPAIR)

nvlist_lookup_int32(3NVPAIR)

nvlist_lookup_int32_array(3NVPAIR)

nvlist_lookup_int64(3NVPAIR)

nvlist_lookup_int64_array(3NVPAIR)

nvlist_lookup_int8(3NVPAIR)

nvlist_lookup_int8_array(3NVPAIR)

nvlist_lookup_nv_alloc(3NVPAIR)

nvlist_lookup_nvlist(3NVPAIR)

nvlist_lookup_nvlist_array(3NVPAIR)

nvlist_lookup_pairs(3NVPAIR)

nvlist_lookup_string(3NVPAIR)

nvlist_lookup_string_array(3NVPAIR)

nvlist_lookup_uint16(3NVPAIR)

nvlist_lookup_uint16_array(3NVPAIR)

nvlist_lookup_uint32(3NVPAIR)

nvlist_lookup_uint32_array(3NVPAIR)

nvlist_lookup_uint64(3NVPAIR)

nvlist_lookup_uint64_array(3NVPAIR)

nvlist_lookup_uint8(3NVPAIR)

nvlist_lookup_uint8_array(3NVPAIR)

nvlist_merge(3NVPAIR)

nvlist_next_nvpair(3NVPAIR)

nvlist_pack(3NVPAIR)

nvlist_remove(3NVPAIR)

nvlist_remove_all(3NVPAIR)

nvlist_size(3NVPAIR)

nvlist_unpack(3NVPAIR)

nvlist_xalloc(3NVPAIR)

nvlist_xdup(3NVPAIR)

nvlist_xpack(3NVPAIR)

nvlist_xunpack(3NVPAIR)

nvpair_name(3NVPAIR)

nvpair_type(3NVPAIR)

nvpair_value_boolean_array(3NVPAIR)

nvpair_value_boolean_value(3NVPAIR)

nvpair_value_byte(3NVPAIR)

nvpair_value_byte_array(3NVPAIR)

nvpair_value_int16(3NVPAIR)

nvpair_value_int16_array(3NVPAIR)

nvpair_value_int32(3NVPAIR)

nvpair_value_int32_array(3NVPAIR)

nvpair_value_int64(3NVPAIR)

nvpair_value_int64_array(3NVPAIR)

nvpair_value_int8(3NVPAIR)

nvpair_value_int8_array(3NVPAIR)

nvpair_value_nvlist(3NVPAIR)

nvpair_value_nvlist_array(3NVPAIR)

nvpair_value_string(3NVPAIR)

nvpair_value_string_array(3NVPAIR)

nvpair_value_uint16(3NVPAIR)

nvpair_value_uint16_array(3NVPAIR)

nvpair_value_uint32(3NVPAIR)

nvpair_value_uint32_array(3NVPAIR)

nvpair_value_uint64(3NVPAIR)

nvpair_value_uint64_array(3NVPAIR)

nvpair_value_uint8(3NVPAIR)

nvpair_value_uint8_array(3NVPAIR)

p2close(3GEN)

p2open(3GEN)

pam(3PAM)

pam_acct_mgmt(3PAM)

pam_authenticate(3PAM)

pam_chauthtok(3PAM)

pam_close_session(3PAM)

pam_end(3PAM)

pam_get_data(3PAM)

pam_getenv(3PAM)

pam_getenvlist(3PAM)

pam_get_item(3PAM)

pam_get_user(3PAM)

pam_open_session(3PAM)

pam_putenv(3PAM)

pam_setcred(3PAM)

pam_set_data(3PAM)

pam_set_item(3PAM)

pam_sm(3PAM)

pam_sm_acct_mgmt(3PAM)

pam_sm_authenticate(3PAM)

pam_sm_chauthtok(3PAM)

pam_sm_close_session(3PAM)

pam_sm_open_session(3PAM)

pam_sm_setcred(3PAM)

pam_start(3PAM)

pam_strerror(3PAM)

papiAttributeListAddBoolean(3PAPI)

papiAttributeListAddCollection(3PAPI)

papiAttributeListAddDatetime(3PAPI)

papiAttributeListAddInteger(3PAPI)

papiAttributeListAddMetadata(3PAPI)

papiAttributeListAddRange(3PAPI)

papiAttributeListAddResolution(3PAPI)

papiAttributeListAddString(3PAPI)

papiAttributeListAddValue(3PAPI)

papiAttributeListDelete(3PAPI)

papiAttributeListFind(3PAPI)

papiAttributeListFree(3PAPI)

papiAttributeListFromString(3PAPI)

papiAttributeListGetBoolean(3PAPI)

papiAttributeListGetCollection(3PAPI)

papiAttributeListGetDatetime(3PAPI)

papiAttributeListGetInteger(3PAPI)

papiAttributeListGetMetadata(3PAPI)

papiAttributeListGetNext(3PAPI)

papiAttributeListGetRange(3PAPI)

papiAttributeListGetResolution(3PAPI)

papiAttributeListGetString(3PAPI)

papiAttributeListGetValue(3PAPI)

papiAttributeListToString(3PAPI)

papiJobCancel(3PAPI)

papiJobFree(3PAPI)

papiJobGetAttributeList(3PAPI)

papiJobGetId(3PAPI)

papiJobGetJobTicket(3PAPI)

papiJobGetPrinterName(3PAPI)

papiJobHold(3PAPI)

papiJobListFree(3PAPI)

papiJobModify(3PAPI)

papiJobMove(3PAPI)

papiJobPromote(3PAPI)

papiJobQuery(3PAPI)

papiJobRelease(3PAPI)

papiJobRestart(3PAPI)

papiJobStreamClose(3PAPI)

papiJobStreamOpen(3PAPI)

papiJobStreamWrite(3PAPI)

papiJobSubmit(3PAPI)

papiJobSubmitByReference(3PAPI)

papiJobValidate(3PAPI)

papiLibrarySupportedCall(3PAPI)

papiLibrarySupportedCalls(3PAPI)

papiPrinterAdd(3PAPI)

papiPrinterDisable(3PAPI)

papiPrinterEnable(3PAPI)

papiPrinterFree(3PAPI)

papiPrinterGetAttributeList(3PAPI)

papiPrinterListFree(3PAPI)

papiPrinterListJobs(3PAPI)

papiPrinterModify(3PAPI)

papiPrinterPause(3PAPI)

papiPrinterPurgeJobs(3PAPI)

papiPrinterQuery(3PAPI)

papiPrinterRemove(3PAPI)

papiPrinterResume(3PAPI)

papiPrintersList(3PAPI)

papiServiceCreate(3PAPI)

papiServiceDestroy(3PAPI)

papiServiceGetAppData(3PAPI)

papiServiceGetAttributeList(3PAPI)

papiServiceGetEncryption(3PAPI)

papiServiceGetPassword(3PAPI)

papiServiceGetServiceName(3PAPI)

papiServiceGetStatusMessage(3PAPI)

papiServiceGetUserName(3PAPI)

papiServiceSetAppData(3PAPI)

papiServiceSetAuthCB(3PAPI)

papiServiceSetEncryption(3PAPI)

papiServiceSetPassword(3PAPI)

papiServiceSetUserName(3PAPI)

papiStatusString(3PAPI)

pathfind(3GEN)

pca_last_error(3TECLA)

pca_lookup_file(3TECLA)

pca_path_completions(3TECLA)

pca_scan_path(3TECLA)

pca_set_check_fn(3TECLA)

pctx_capture(3CPC)

pctx_create(3CPC)

pctx_release(3CPC)

pctx_run(3CPC)

pctx_set_events(3CPC)

picld_log(3PICLTREE)

picld_plugin_register(3PICLTREE)

picl_find_node(3PICL)

picl_get_first_prop(3PICL)

picl_get_frutree_parent(3PICL)

picl_get_next_by_col(3PICL)

picl_get_next_by_row(3PICL)

picl_get_next_prop(3PICL)

picl_get_node_by_path(3PICL)

picl_get_prop_by_name(3PICL)

picl_get_propinfo(3PICL)

picl_get_propinfo_by_name(3PICL)

picl_get_propval(3PICL)

picl_get_propval_by_name(3PICL)

picl_get_root(3PICL)

picl_initialize(3PICL)

picl_set_propval(3PICL)

picl_set_propval_by_name(3PICL)

picl_shutdown(3PICL)

picl_strerror(3PICL)

picl_wait(3PICL)

picl_walk_tree_by_class(3PICL)

pool_associate(3POOL)

pool_component_info(3POOL)

pool_component_to_elem(3POOL)

pool_conf_alloc(3POOL)

pool_conf_close(3POOL)

pool_conf_commit(3POOL)

pool_conf_export(3POOL)

pool_conf_free(3POOL)

pool_conf_info(3POOL)

pool_conf_location(3POOL)

pool_conf_open(3POOL)

pool_conf_remove(3POOL)

pool_conf_rollback(3POOL)

pool_conf_status(3POOL)

pool_conf_to_elem(3POOL)

pool_conf_update(3POOL)

pool_conf_validate(3POOL)

pool_create(3POOL)

pool_destroy(3POOL)

pool_dissociate(3POOL)

pool_dynamic_location(3POOL)

pool_error(3POOL)

pool_get_binding(3POOL)

pool_get_owning_resource(3POOL)

pool_get_pool(3POOL)

pool_get_property(3POOL)

pool_get_resource(3POOL)

pool_get_resource_binding(3POOL)

pool_get_status(3POOL)

pool_info(3POOL)

pool_put_property(3POOL)

pool_query_components(3POOL)

pool_query_pool_resources(3POOL)

pool_query_pools(3POOL)

pool_query_resource_components(3POOL)

pool_query_resources(3POOL)

pool_resource_create(3POOL)

pool_resource_destroy(3POOL)

pool_resource_info(3POOL)

pool_resource_to_elem(3POOL)

pool_resource_transfer(3POOL)

pool_resource_type_list(3POOL)

pool_resource_xtransfer(3POOL)

pool_rm_property(3POOL)

pool_set_binding(3POOL)

pool_set_status(3POOL)

pool_static_location(3POOL)

pool_strerror(3POOL)

pool_to_elem(3POOL)

pool_value_alloc(3POOL)

pool_value_free(3POOL)

pool_value_get_bool(3POOL)

pool_value_get_double(3POOL)

pool_value_get_int64(3POOL)

pool_value_get_name(3POOL)

pool_value_get_string(3POOL)

Extended Library Functions - Part 5

Extended Library Functions - Part 6

pca_lookup_file

, del_PathCache

, del_PcaPathConf

, new_PathCache

, new_PcaPathConf

, pca_last_error

, pca_path_completions

, pca_scan_path

, pca_set_check_fn

, ppc_file_start

, ppc_literal_escapes

- lookup a file in a list of directories

Synopsis

cc [ flag… ] file-ltecla [ library… ] 
#include <libtecla.h>

char *pca_lookup_file(PathCache *pc, const char *name,
     int name_len, int literal);
PathCache *del_PathCache(PathCache *pc);
PcaPathConf *del_PcaPathConf(PcaPathConf *ppc);
PathCache *new_PathCache(void);
PcaPathConf *new_PcaPathConf(PathCache *pc);
const char *pca_last_error(PathCache *pc);
CPL_MATCH_FN(pca_path_completions);
int pca_scan_path(PathCache *pc, const char *path);
void pca_set_check_fn(PathCache *pc, CplCheckFn *check_fn,
     void *data);
void ppc_file_start(PcaPathConf *ppc, int start_index);
void ppc_literal_escapes(PcaPathConf *ppc, int literal);

Description

The PathCache object is part of the libtecla(3LIB) library. PathCache objects allow an application to search for files in any colon separated list of directories, such as the UNIX execution PATH environment variable. Files in absolute directories are cached in a PathCache object, whereas relative directories are scanned as needed. Using a PathCache object, you can look up the full pathname of a simple filename, or you can obtain a list of the possible completions of a given filename prefix. By default all files in the list of directories are targets for lookup and completion, but a versatile mechanism is provided for only selecting specific types of files. The obvious application of this facility is to provide Tab-completion and lookup of executable commands in the UNIX PATH, so an optional callback which rejects all but executable files, is provided.

An Example

Under UNIX, the following example program looks up and displays the full pathnames of each of the command names on the command line.

#include <stdio.h>
#include <stdlib.h>
#include <libtecla.h>

int main(int argc, char *argv[])
{
        int i;
        /*
        * Create a cache for executable files.
        */
        PathCache *pc = new_PathCache();
        if(!pc)
          exit(1);
        /*
        * Scan the user's PATH for executables.
        */
        if(pca_scan_path(pc, getenv("PATH"))) {
          fprintf(stderr, "%s\n", pca_last_error(pc));
          exit(1);
        }
        /*
        * Arrange to only report executable files.
        */
        pca_set_check_fn(pc, cpl_check_exe, NULL);
        /*
        * Lookup and display the full pathname of each of the
        * commands listed on the command line.
        */
        for(i=1; i<argc; i++) {
          char *cmd = pca_lookup_file(pc, argv[i], -1, 0);
          printf("The full pathname of '%s' is %s\\n", argv[i],
                 cmd ? cmd : "unknown");
        }
        pc = del_PathCache(pc);  /* Clean up */
        return 0;
}

The following is an example of what this does on a laptop under LINUX:

$ ./example less more blob
The full pathname of 'less' is /usr/bin/less
The full pathname of 'more' is /bin/more
The full pathname of 'blob' is unknown
$

Function Descriptions

To use the facilities of this module, you must first allocate a PathCache object by calling the new_PathCache() constructor function. This function creates the resources needed to cache and lookup files in a list of directories. It returns NULL on error.

Populating The Cache

Once you have created a cache, it needs to be populated with files. To do this, call the pca_scan_path() function. Whenever this function is called, it discards the current contents of the cache, then scans the list of directories specified in its path argument for files. The path argument must be a string containing a colon-separated list of directories, such as “/usr/bin:/home/mcs/bin:”. This can include directories specified by absolute pathnames such as “/usr/bin”, as well as sub-directories specified by relative pathnames such as “.” or “bin”. Files in the absolute directories are immediately cached in the specified PathCache object, whereas subdirectories, whose identities obviously change whenever the current working directory is changed, are marked to be scanned on the fly whenever a file is looked up.

On success this function return 0. On error it returns 1, and a description of the error can be obtained by calling pca_last_error(pc).

Looking Up Files

Once the cache has been populated with files, you can look up the full pathname of a file, simply by specifying its filename to pca_lookup_file().

To make it possible to pass this function a filename which is actually part of a longer string, the name_len argument can be used to specify the length of the filename at the start of the name[] argument. If you pass -1 for this length, the length of the string will be determined with strlen. If the name[] string might contain backslashes that escape the special meanings of spaces and tabs within the filename, give the literal argument the value 0. Otherwise, if backslashes should be treated as normal characters, pass 1 for the value of the literal argument.

Filename Completion

Looking up the potential completions of a filename-prefix in the filename cache is achieved by passing the provided pca_path_completions() callback function to the cpl_complete_word(3TECLA) function.

This callback requires that its data argument be a pointer to a PcaPathConf object. Configuration objects of this type are allocated by calling new_PcaPathConf().

This function returns an object initialized with default configuration parameters, which determine how the cpl_path_completions() callback function behaves. The functions which allow you to individually change these parameters are discussed below.

By default, the pca_path_completions() callback function searches backwards for the start of the filename being completed, looking for the first un-escaped space or the start of the input line. If you wish to specify a different location, call ppc_file_start() with the index at which the filename starts in the input line. Passing start_index=-1 re-enables the default behavior.

By default, when pca_path_completions() looks at a filename in the input line, each lone backslash in the input line is interpreted as being a special character which removes any special significance of the character which follows it, such as a space which should be taken as part of the filename rather than delimiting the start of the filename. These backslashes are thus ignored while looking for completions, and subsequently added before spaces, tabs and literal backslashes in the list of completions. To have unescaped backslashes treated as normal characters, call ppc_literal_escapes() with a non-zero value in its literal argument.

When you have finished with a PcaPathConf variable, you can pass it to the del_PcaPathConf() destructor function to reclaim its memory.

Being Selective

If you are only interested in certain types or files, such as, for example, executable files, or files whose names end in a particular suffix, you can arrange for the file completion and lookup functions to be selective in the filenames that they return. This is done by registering a callback function with your PathCache object. Thereafter, whenever a filename is found which either matches a filename being looked up or matches a prefix which is being completed, your callback function will be called with the full pathname of the file, plus any application-specific data that you provide. If the callback returns 1 the filename will be reported as a match. If it returns 0, it will be ignored. Suitable callback functions and their prototypes should be declared with the following macro. The CplCheckFn typedef is also provided in case you wish to declare pointers to such functions

#define CPL_CHECK_FN(fn) int (fn)(void *data, const char *pathname)
typedef CPL_CHECK_FN(CplCheckFn);

Registering one of these functions involves calling the pca_set_check_fn() function. In addition to the callback function passed with the check_fn argument, you can pass a pointer to anything with the data argument. This pointer will be passed on to your callback function by its own data argument whenever it is called, providing a way to pass application-specific data to your callback. Note that these callbacks are passed the full pathname of each matching file, so the decision about whether a file is of interest can be based on any property of the file, not just its filename. As an example, the provided cpl_check_exe() callback function looks at the executable permissions of the file and the permissions of its parent directories, and only returns 1 if the user has execute permission to the file. This callback function can thus be used to lookup or complete command names found in the directories listed in the user's PATH environment variable. The example program above provides a demonstration of this.

Beware that if somebody tries to complete an empty string, your callback will get called once for every file in the cache, which could number in the thousands. If your callback does anything time consuming, this could result in an unacceptable delay for the user, so callbacks should be kept short.

To improve performance, whenever one of these callbacks is called, the choice that it makes is cached, and the next time the corresponding file is looked up, instead of calling the callback again, the cached record of whether it was accepted or rejected is used. Thus if somebody tries to complete an empty string, and hits tab a second time when nothing appears to happen, there will only be one long delay, since the second pass will operate entirely from the cached dispositions of the files. These cached dipositions are discarded whenever pca_scan_path() is called, and whenever pca_set_check_fn() is called with changed callback function or data arguments.

Error Handling

If pca_scan_path() reports that an error occurred by returning 1, you can obtain a terse description of the error by calling pca_last_error(pc). This returns an internal string containing an error message.

Cleaning Up

Once you have finished using a PathCache object, you can reclaim its resources by passing it to the del_PathCache() destructor function. This takes a pointer to one of these objects, and always returns NULL.

Thread Safety

It is safe to use the facilities of this module in multiple threads, provided that each thread uses a separately allocated PathCache object. In other words, if two threads want to do path searching, they should each call new_PathCache() to allocate their own caches.

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Evolving
MT-Level
MT-Safe

See Also

cpl_complete_word(3TECLA), ef_expand_file(3TECLA), gl_get_line(3TECLA), libtecla(3LIB), attributes(5)