linux系统库函数之strcpy、strncpy
来源:互联网 发布:中软国际 知乎 编辑:程序博客网 时间:2024/04/29 18:20
92 /**
93 * strcpy - Copy a %NUL terminated string
94 * @dest: Where to copy the string to
95 * @src: Where to copy the string from
96 */
97 #undef strcpy
98 char *strcpy(char *dest, const char *src)
99 {
100 char *tmp = dest;
101
102 while ((*dest++ = *src++) != '\0')
103 /* nothing */;
104 return tmp;
105 }
106 EXPORT_SYMBOL(strcpy);
107 #endif
strcpy函数为字符串拷贝函数,它只能拷贝字符串,遇到字符串的结束符'/0'拷贝结束。要是没有这个结束符,后果可想而知。
109 #ifndef __HAVE_ARCH_STRNCPY
110 /**
111 * strncpy - Copy a length-limited, %NUL-terminated string
112 * @dest: Where to copy the string to
113 * @src: Where to copy the string from
114 * @count: The maximum number of bytes to copy
115 *
116 * The result is not %NUL-terminated if the source exceeds
117 * @count bytes.
118 *
119 * In the case where the length of @src is less than that of
120 * count, the remainder of @dest will be padded with %NUL.
121 *
122 */
123 char *strncpy(char *dest, const char *src, size_t count)
124 {
125 char *tmp = dest;
126
127 while (count) {
128 if ((*tmp = *src) != 0)
129 src++;
130 tmp++;
131 count--;
132 }
133 return dest;
134 }
135 EXPORT_SYMBOL(strncpy);
136 #endif
strncpy也是字符串拷贝函数,遇到字符串结束符就停止拷贝,但它和strcpy不同的是,如果没有遇到字符串结束符,它只拷贝count字节大小数据。有两种用途,一是,我只需要count字节大小数据,二是,如果拷贝的数据没有字符串结束符,它还可以自己结束数据拷贝。
- linux系统库函数之strcpy、strncpy
- C库函数之strcpy,strncpy,memcpy
- linux下C编程(二)之 strcpy strncpy
- C语言字符串相关库函数的实现strcpy、memcpy、strncpy、strcat、strncpy、memset、memcpy、strcpy
- 几个重要库函数的实现-strcpy,strncpy,memcpy,memset
- 几个重要库函数的实现-strcpy,strncpy,memcpy,memset
- 几个重要库函数的实现-strcpy,strncpy,memcpy,memset
- 几个重要库函数的实现-strcpy,strncpy,memcpy,memset
- 几个重要库函数的实现-strcpy,strncpy,memcpy,memset
- 几个重要库函数的实现-strcpy,strncpy,memcpy,memset
- 字符串库函数strlen,strcmp,strcpy,strncpy,strcat,strncat自定义实现
- 几个重要的库函数strcpy , strncpy, memcpy实现
- strcpy,strncpy函数实现——string.h库函数
- strcpy strncpy memcpy等系列库函数剖析与实现
- 手写几个重要的库函数 strcpy,strncpy,memcpy,memset
- C语言库函数(strcpy、strncpy、memcpy、memset)
- strcpy和strncpy库函数的实现和比较
- linux系统库函数之memcpy
- mahout分类算法效果评估指标
- 使用cron,logrotate来管理日志文件
- 为Android加入busybox工具
- 广播接收器 broadcast sendOrderedBroadcast android
- 新的地址
- linux系统库函数之strcpy、strncpy
- ORACLE ASM详解
- Linux 磁盘和文件系统
- 自定义App.config
- iOS中AlertView添加输入框
- “代理XP”组件已作为此服务器安全配置的一部分被关闭的解决办法
- 具有Flash Access保护的HTTP Dynamic Streaming
- Oracle RAC 实例不能启动解决方案
- SQLite的查询优化