天天看点

c++string头文件_of_property_read_string 剖析~前言函数引用的头文件CONFIG_OF 宏有什么用?of_property_read_string 函数本体of_property_read_string 函数剖析关于二级指针举个例子

前言

今天在一个群里面看到的一个朋友提交,说of_property_read_string 这个函数有两个定义,到底是用了哪个呢?

所以这篇文章就说下这个函数。

函数引用的头文件

引用的头文件位置在

其中一个是

还有一个是

但是并不是两个都用到,他们用了一个宏  CONFIG_OF 来选择

CONFIG_OF 宏有什么用?

这个宏的解释是

Open Firmware. This was invented long time ago when Apple was producing laptops based on PowerPC CPUs. Openfirmware provides a good description of the devices connected to the platform. In Linux kernel the part that works with device data is called Device Tree (DT). More details in theUsage model.

他的作用是

Openfirmware provides a good description of the devices connected to the platform

他提供了一种更好的方式来连接设备和驱动。

他是名字是

called Device Tree (DT)

DTS,那很明显了,开了这个宏,就表示使用了DTS设备树的方式来连接设备和驱动程序。

of_property_read_string 函数本体

函数位置

函数原型

函数的作用:

返回propname对应dts节点对应的值。

使用方式:

c++string头文件_of_property_read_string 剖析~前言函数引用的头文件CONFIG_OF 宏有什么用?of_property_read_string 函数本体of_property_read_string 函数剖析关于二级指针举个例子

传入np,就是设备树的节点,然后返回 "clock-output-names" 字符串对应的值,存入clk_name 里面。

of_property_read_string 函数剖析

c++string头文件_of_property_read_string 剖析~前言函数引用的头文件CONFIG_OF 宏有什么用?of_property_read_string 函数本体of_property_read_string 函数剖析关于二级指针举个例子
  • of_find_property 这个是找到这个dts节点,怎么找,可以再去这个函数分析一下。
  • strnlen功能「获取字符串实际字符个数,不包括结尾的'\0';如果实际个数 <= 第二个参数,则返回字符串实际字符个数,否则返回第二个参数。」
  • prop->length 是之前预设的一个值,strnlen正常情况返回的就是字符串的长度 减1「去掉\n字符」。
  • *out_string = prop->value 这里就是二级指针起到作用了,没有重新分配内存,直接把指针指向字符串位置。

我们再看看prop 的结构体,就一目了然了。

关于二级指针举个例子

c++string头文件_of_property_read_string 剖析~前言函数引用的头文件CONFIG_OF 宏有什么用?of_property_read_string 函数本体of_property_read_string 函数剖析关于二级指针举个例子
专辑|Linux文章汇总
           
专辑|程序人生
           

===========

c++string头文件_of_property_read_string 剖析~前言函数引用的头文件CONFIG_OF 宏有什么用?of_property_read_string 函数本体of_property_read_string 函数剖析关于二级指针举个例子

PS:想加入技术群的同学,加了我好友后,就给我发「篮球的大肚子」这句话,有可能机器人打瞌睡,可以多发几次,不要发与技术无关的消息或者推广。

如果想获取学习资料,就在公众号后台回复「1024」,足够多的学习资料可以让你学习。

继续阅读