A B*_*was 1 linux system-calls
我想知道 strcpy 或 strcat 之类的函数是否会导致任何系统调用,还是由操作系统内部处理?
不涉及系统调用。事实上,大多数(如果不是全部)实现的源代码如下所示:
char *
strcpy(char *s1, const char *s2) {
char *s = s1;
while ((*s++ = *s2++) != 0) ;
return (s1);
}
Run Code Online (Sandbox Code Playgroud)
strcat 是相似的:
char *
strcat(char *s1, const char *s2)
{
strcpy(&s1[strlen(s1)], s2);
return s1;
}
Run Code Online (Sandbox Code Playgroud)