c/c++库函数整理1

1、getopt()

头文件 #include <unistd.h>

定义函数:int getopt(int argc, char * const argv[], const char * optstring);

函数说明:getopt()用来分析命令行参数。
1、参数argc 和argv 是由main()传递的参数个数和内容。
2、参数optstring 则代表欲处理的选项字符串。

返回值: 如果当前处理的参数为选项元素,且该选项字符在optstring字符串中, 即为你定义的选项, 则返回该

选项字符,如果该选项字符不是你定义的, 那么返回字符'?', 并更新全局变量optind, 指向argc数组中的下一

个参数. 如果当前处理的参数不是选项元素, 则optind偏移向下一个参数, 直到找到第一个选项元素为止,  然后

再按之前描述的操作,如果找不到选项元素, 说明解析结束, 则返回-1.

2、struct pci_id_match

struct pci_id_match {
    /**
     * \name Device / vendor matching controls
     * 
     * Control the search based on the device, vendor, subdevice, or subvendor
     * IDs.  Setting any of these fields to \c PCI_MATCH_ANY will cause the
     * field to not be used in the comparison.
     */
    /*@{*/
    uint32_t    vendor_id;
    uint32_t    device_id;
    uint32_t    subvendor_id;
    uint32_t    subdevice_id;
    /*@}*/


    /**
     * \name Device class matching controls
     * 
     */
    /*@{*/
    uint32_t    device_class;
    uint32_t    device_class_mask;
    /*@}*/

    intptr_t    match_data;
};


3, struct pci_device_iterator
struct pci_device_iterator {
    unsigned next_index;

    enum {
	match_any,
	match_slot,
	match_id
    } mode;

    union {
	struct pci_slot_match   slot;
	struct pci_id_match     id;
    } match;
};




4, 

int pci_system_init( void    )

Initialize the PCI subsystem for access

returns:
Zero on success or an errno value on failure. In particular, if no platform-specific initializers are available,  ENOSYS will be returned.

5, 

struct pci_device_iterator* pci_id_match_iterator_create( const struct pci_id_match *  match )

  Create an iterator based on a regular expression.

Returns:
A pointer to a fully initialized  pci_device_iterator structure on success, or  NULL on failure.


6. pci_device_next
/**
 * Iterate to the next PCI device.
 *
 * \param iter  Device iterator returned by \c pci_device_iterate.
 *
 * \return
 * A pointer to a \c pci_device, or \c NULL when all devices have been
 * iterated.
 */
struct pci_device *
pci_device_next( struct pci_device_iterator * iter )
{
    struct pci_device_private * d = NULL;

    if (!iter)
	return NULL;

    switch( iter->mode ) {
    case match_any:
	if ( iter->next_index < pci_sys->num_devices ) {
	    d = & pci_sys->devices[ iter->next_index ];
	    iter->next_index++;
	}

	break;

    case match_slot: {
	while ( iter->next_index < pci_sys->num_devices ) {
	    struct pci_device_private * const temp =
	      & pci_sys->devices[ iter->next_index ];

	    iter->next_index++;
	    if ( PCI_ID_COMPARE( iter->match.slot.domain, temp->base.domain )
		 && PCI_ID_COMPARE( iter->match.slot.bus, temp->base.bus )
		 && PCI_ID_COMPARE( iter->match.slot.dev, temp->base.dev )
		 && PCI_ID_COMPARE( iter->match.slot.func, temp->base.func ) ) {
		d = temp;
		break;
	    }
	}

	break;
    }

    case match_id: {
	while ( iter->next_index < pci_sys->num_devices ) {
	    struct pci_device_private * const temp =
	      & pci_sys->devices[ iter->next_index ];

	    iter->next_index++;
	    if ( PCI_ID_COMPARE( iter->match.id.vendor_id, temp->base.vendor_id )
		 && PCI_ID_COMPARE( iter->match.id.device_id, temp->base.device_id )
		 && PCI_ID_COMPARE( iter->match.id.subvendor_id, temp->base.subvendor_id )
		 && PCI_ID_COMPARE( iter->match.id.subdevice_id, temp->base.subdevice_id )
		 && ((temp->base.device_class & iter->match.id.device_class_mask)
		     == iter->match.id.device_class) ) {
		d = temp;
		break;
	    }
	}

	break;
    }
    }

    return (struct pci_device *) d;
}



7, pci_device_probe

int pci_device_probe( struct pci_device *  dev )  

Probe a PCI device to learn information about the device.

Probes a PCI device to learn various information about the device. Before calling this function, the only public fields in the pci_device structure that have valid values are pci_device::domainpci_device::buspci_device::dev, and pci_device::func.

Parameters:
  dev Device to be probed.
Returns:
Zero on success or an  errno value on failure.

8,  pci_iterator_destory

void pci_iterator_destroy( struct pci_device_iterator *  iter )  

Destroy an iterator previously created with pci_iterator_create.

Parameters:
  iter Iterator to be destroyed.


9, 

NAME
readlink - read the contents of a symbolic link
SYNOPSIS

#include <unistd.h>

ssize_t readlink(const char *restrict
 path, char *restrict buf,
       size_t
 bufsize);

DESCRIPTION

The readlink() function shall place the contents of the symbolic link referred to by path in the buffer buf which has size bufsize. If the number of bytes in the symbolic link is less than bufsize, the contents of the remainder of buf are unspecified. If the buf argument is not large enough to contain the link content, the first bufsize bytes shall be placed in buf.

If the value of bufsize is greater than {SSIZE_MAX}, the result is implementation-defined.

RETURN VALUE

Upon successful completion, readlink() shall return the count of bytes placed in the buffer. Otherwise, it shall return a value of -1, leave the buffer unchanged, and set errno to indicate the error.


10,

NAME
basename - return the last component of a pathname
SYNOPSIS
[XSI] [Option Start] #include <libgen.h>

char *basename(char *
path); [Option End]

DESCRIPTION

The basename() function shall take the pathname pointed to by path and return a pointer to the final component of the pathname, deleting any trailing '/' characters.

If the string pointed to by path consists entirely of the '/' character, basename() shall return a pointer to the string "/". If the string pointed to by path is exactly "//", it is implementation-defined whether '/' or "//" is returned.

If path is a null pointer or points to an empty string, basename() shall return a pointer to the string ".".

The basename() function may modify the string pointed to by path, and may return a pointer to static storage that may then be overwritten by a subsequent call to basename().

The basename() function need not be reentrant. A function that is not required to be reentrant is not required to be thread-safe.

RETURN VALUE

The basename() function shall return a pointer to the final component of path.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值