⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 42.html

📁 linux 0.11中文版 有注释
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<html>
<head>
<title>include/string.h</title>
<meta name='robots' content='noindex,nofollow'>
<meta name='generator' content='GLOBAL-5.4.1'>
</head>
<body text='#191970' bgcolor='#f5f5dc' vlink='gray'>
<a name='TOP'><h2><a href='../mains.html'>root</a>/<a href='../files/99.html'>include</a>/string.h</h2>
<i><font color='green'>/* [&lt;][&gt;]<a href='#L40'>[^]</a><a href='#L495'>[v]</a>[top]<a href='#BOTTOM'>[bottom]</a><a href='../mains.html'>[index]</a><a href='../help.html'>[help]</a> */</font></i>
<hr>
<h2><a href='../J/42.html' title='Multiple included from 12 places.'>INCLUDED FROM</a></h2>
<hr>
<h2>DEFINITIONS</h2>
This source file includes following definitions.
<ol>
<li><a href='#L40' title='Defined at 40.'>strcpy</a>
<li><a href='#L56' title='Defined at 56.'>strncpy</a>
<li><a href='#L75' title='Defined at 75.'>strcat</a>
<li><a href='#L94' title='Defined at 94.'>strncat</a>
<li><a href='#L119' title='Defined at 119.'>strcmp</a>
<li><a href='#L142' title='Defined at 142.'>strncmp</a>
<li><a href='#L168' title='Defined at 168.'>strchr</a>
<li><a href='#L190' title='Defined at 190.'>strrchr</a>
<li><a href='#L211' title='Defined at 211.'>strspn</a>
<li><a href='#L240' title='Defined at 240.'>strcspn</a>
<li><a href='#L269' title='Defined at 269.'>strpbrk</a>
<li><a href='#L300' title='Defined at 300.'>strstr</a>
<li><a href='#L333' title='Defined at 333.'>strlen</a>
<li><a href='#L358' title='Defined at 358.'>strtok</a>
<li><a href='#L420' title='Defined at 420.'>memcpy</a>
<li><a href='#L435' title='Defined at 435.'>memmove</a>
<li><a href='#L456' title='Defined at 456.'>memcmp</a>
<li><a href='#L476' title='Defined at 476.'>memchr</a>
<li><a href='#L495' title='Defined at 495.'>memset</a>
</ol>
<hr>
<pre>
<a name='L1'><font color='darkred'>#ifndef</font> <a href='../S/42.html#L2' title='Defined at 2 in include/string.h.'>_STRING_H_</a>
<a name='L2'><font color='darkred'>#define</font> <a href='../S/42.html#L1' title='Refered from 1 in include/string.h.'>_STRING_H_</a>
<a name='L3'>
<a name='L4'><font color='darkred'>#ifndef</font> <a href='../D/261.html' title='Multiple defined in 12 places.'>NULL</a>
<a name='L5'><font color='darkred'>#define</font> <a href='../R/149.html' title='Multiple refered from 109 places.'>NULL</a> ((<b>void</b> *) 0)
<a name='L6'><font color='darkred'>#endif</font>
<a name='L7'>
<a name='L8'><font color='darkred'>#ifndef</font> <a href='../D/595.html' title='Multiple defined in 4 places.'>_SIZE_T</a>
<a name='L9'><font color='darkred'>#define</font> <a href='../R/346.html' title='Multiple refered from 4 places.'>_SIZE_T</a>
<a name='L10'><b>typedef</b> <b>unsigned</b> <b>int</b> <a href='../R/611.html' title='Multiple refered from 2 places.'>size_t</a>;
<a name='L11'><font color='darkred'>#endif</font>
<a name='L12'>
<a name='L13'><b>extern</b> <b>char</b> *strerror (<b>int</b> errno);
<a name='L14'>
<a name='L15'><i><font color='green'>/*</font></i>
<a name='L16'><i><font color='green'>* This string-include defines all string functions as inline</font></i>
<a name='L17'><i><font color='green'>* functions. Use gcc. It also assumes ds=es=data space, this should be</font></i>
<a name='L18'><i><font color='green'>* normal. Most of the string-functions are rather heavily hand-optimized,</font></i>
<a name='L19'><i><font color='green'>* see especially strtok,strstr,str[c]spn. They should work, but are not</font></i>
<a name='L20'><i><font color='green'>* very easy to understand. Everything is done entirely within the register</font></i>
<a name='L21'><i><font color='green'>* set, making the functions fast and clean. String instructions have been</font></i>
<a name='L22'><i><font color='green'>* used through-out, making for "slightly" unclear code :-)</font></i>
<a name='L23'><i><font color='green'>*</font></i>
<a name='L24'><i><font color='green'>* (C) 1991 Linus Torvalds</font></i>
<a name='L25'><i><font color='green'>*/</font></i>
<a name='L26'><i><font color='green'>/*</font></i>
<a name='L27'><i><font color='green'>* 这个字符串头文件以内嵌函数的形式定义了所有字符串操作函数。使用gcc 时,同时</font></i>
<a name='L28'><i><font color='green'>* 假定了ds=es=数据空间,这应该是常规的。绝大多数字符串函数都是经手工进行大量</font></i>
<a name='L29'><i><font color='green'>* 优化的,尤其是函数strtok、strstr、str[c]spn。它们应该能正常工作,但却不是那</font></i>
<a name='L30'><i><font color='green'>* 么容易理解。所有的操作基本上都是使用寄存器集来完成的,这使得函数即快有整洁。</font></i>
<a name='L31'><i><font color='green'>* 所有地方都使用了字符串指令,这又使得代码“稍微”难以理解?</font></i>
<a name='L32'><i><font color='green'>*</font></i>
<a name='L33'><i><font color='green'>* (C) 1991 Linus Torvalds</font></i>
<a name='L34'><i><font color='green'>*/</font></i>
<a name='L35'>
<a name='L36'><i><font color='green'>//// 将一个字符串(src)拷贝到另一个字符串(dest),直到遇到NULL 字符后停止。</font></i>
<a name='L37'><i><font color='green'>// 参数:dest - 目的字符串指针,src - 源字符串指针。</font></i>
<a name='L38'><i><font color='green'>// %0 - esi(src),%1 - edi(dest)。</font></i>
<a name='L39'><b>extern</b> <b>inline</b> <b>char</b> *
<a name='L40'><a href='../R/621.html' title='Multiple refered from 2 places.'>strcpy</a> (<b>char</b> *dest, <b>const</b> <b>char</b> *src)
<a name='L41'><font color='red'>{</font>
<a name='L42'>  <b>__asm__</b> ("cld\n"              <i><font color='green'>// 清方向位。</font></i>
<a name='L43'>           "1:\tlodsb\n\t"      <i><font color='green'>// 加载DS:[esi]处1 字节??al,并更新esi。</font></i>
<a name='L44'>           "stosb\n\t"          <i><font color='green'>// 存储字节al??ES:[edi],并更新edi。</font></i>
<a name='L45'>           "testb %%al,%%al\n\t"        <i><font color='green'>// 刚存储的字节是0?</font></i>
<a name='L46'>           "jne 1b"             <i><font color='green'>// 不是则向后跳转到标号1 处,否则结束。</font></i>
<a name='L47'>::"S" (src), "D" (dest):"si", "di", "ax");
<a name='L48'>  <b>return</b> dest;                  <i><font color='green'>// 返回目的字符串指针。</font></i>
<a name='L49'><font color='red'>}</font>
<a name='L50'>
<a name='L51'><i><font color='green'>//// 拷贝源字符串count 个字节到目的字符串。</font></i>
<a name='L52'><i><font color='green'>// 如果源串长度小于count 个字节,就附加空字符(NULL)到目的字符串。</font></i>
<a name='L53'><i><font color='green'>// 参数:dest - 目的字符串指针,src - 源字符串指针,count - 拷贝字节数。</font></i>
<a name='L54'><i><font color='green'>// %0 - esi(src),%1 - edi(dest),%2 - ecx(count)。</font></i>
<a name='L55'><b>extern</b> <b>inline</b> <b>char</b> *
<a name='L56'><a href='../S/8.html#L364' title='Refered from 364 in fs/exec.c.'>strncpy</a> (<b>char</b> *dest, <b>const</b> <b>char</b> *src, <b>int</b> count)
<a name='L57'><font color='red'>{</font>
<a name='L58'>  <b>__asm__</b> ("cld\n"              <i><font color='green'>// 清方向位。</font></i>
<a name='L59'>           "1:\tdecl %2\n\t"    <i><font color='green'>// 寄存器ecx--(count--)。</font></i>
<a name='L60'>           "js 2f\n\t"          <i><font color='green'>// 如果count&lt;0 则向前跳转到标号2,结束。</font></i>
<a name='L61'>           "lodsb\n\t"          <i><font color='green'>// 取ds:[esi]处1 字节??al,并且esi++。</font></i>
<a name='L62'>           "stosb\n\t"          <i><font color='green'>// 存储该字节??es:[edi],并且edi++。</font></i>
<a name='L63'>           "testb %%al,%%al\n\t"        <i><font color='green'>// 该字节是0?</font></i>
<a name='L64'>           "jne 1b\n\t"         <i><font color='green'>// 不是,则向前跳转到标号1 处继续拷贝。</font></i>
<a name='L65'>           "rep\n\t"            <i><font color='green'>// 否则,在目的串中存放剩余个数的空字符。</font></i>
<a name='L66'>"stosb\n" "2:"::"S" (src), "D" (dest), "c" (<a href='../D/738.html' title='Multiple defined in 17 places.'>count</a>):"si", "di", "ax",
<a name='L67'>           "cx");
<a name='L68'>  <b>return</b> dest;                  <i><font color='green'>// 返回目的字符串指针。</font></i>
<a name='L69'><font color='red'>}</font>
<a name='L70'>
<a name='L71'><i><font color='green'>//// 将源字符串拷贝到目的字符串的末尾处。</font></i>
<a name='L72'><i><font color='green'>// 参数:dest - 目的字符串指针,src - 源字符串指针。</font></i>
<a name='L73'><i><font color='green'>// %0 - esi(src),%1 - edi(dest),%2 - eax(0),%3 - ecx(-1)。</font></i>
<a name='L74'><b>extern</b> <b>inline</b> <b>char</b> *
<a name='L75'>strcat (<b>char</b> *dest, <b>const</b> <b>char</b> *src)
<a name='L76'><font color='red'>{</font>
<a name='L77'>  <b>__asm__</b> ("cld\n\t"            <i><font color='green'>// 清方向位。</font></i>
<a name='L78'>           "repne\n\t"          <i><font color='green'>// 比较al 与es:[edi]字节,并更新edi++,</font></i>
<a name='L79'>           "scasb\n\t"          <i><font color='green'>// 直到找到目的串中是0 的字节,此时edi 已经指向后1 字节。</font></i>
<a name='L80'>           "decl %1\n"          <i><font color='green'>// 让es:[edi]指向0 值字节。</font></i>
<a name='L81'>           "1:\tlodsb\n\t"      <i><font color='green'>// 取源字符串字节ds:[esi]??al,并esi++。</font></i>
<a name='L82'>           "stosb\n\t"          <i><font color='green'>// 将该字节存到es:[edi],并edi++。</font></i>
<a name='L83'>           "testb %%al,%%al\n\t"        <i><font color='green'>// 该字节是0?</font></i>
<a name='L84'>           "jne 1b"             <i><font color='green'>// 不是,则向后跳转到标号1 处继续拷贝,否则结束。</font></i>
<a name='L85'>::"S" (src), "D" (dest), "a" (0), "c" (0xffffffff):"si", "di", "ax",
<a name='L86'>           "cx");
<a name='L87'>  <b>return</b> dest;                  <i><font color='green'>// 返回目的字符串指针。</font></i>
<a name='L88'><font color='red'>}</font>
<a name='L89'>
<a name='L90'><i><font color='green'>//// 将源字符串的count 个字节复制到目的字符串的末尾处,最后添一空字符。</font></i>
<a name='L91'><i><font color='green'>// 参数:dest - 目的字符串,src - 源字符串,count - 欲复制的字节数。</font></i>
<a name='L92'><i><font color='green'>// %0 - esi(src),%1 - edi(dest),%2 - eax(0),%3 - ecx(-1),%4 - (count)。</font></i>
<a name='L93'><b>extern</b> <b>inline</b> <b>char</b> *
<a name='L94'>strncat (<b>char</b> *dest, <b>const</b> <b>char</b> *src, <b>int</b> count)
<a name='L95'><font color='red'>{</font>
<a name='L96'>  <b>__asm__</b> ("cld\n\t"            <i><font color='green'>// 清方向位。</font></i>
<a name='L97'>           "repne\n\t"          <i><font color='green'>// 比较al 与es:[edi]字节,edi++。</font></i>
<a name='L98'>           "scasb\n\t"          <i><font color='green'>// 直到找到目的串的末端0 值字节。</font></i>
<a name='L99'>           "decl %1\n\t"        <i><font color='green'>// edi 指向该0 值字节。</font></i>
<a name='L100'>           "movl %4,%3\n"       <i><font color='green'>// 欲复制字节数??ecx。</font></i>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -