在live555的UsageEnvironment目录内的include/strDup.hh头文件和strDup.cpp程序文件,重新实现了标准C库函数strDup()和strDupSize(),用于实现字符串的拷贝和新建字符串同等的内存空间。
strDup.hh源码解析:
1.#ifndef _STRDUP_HH //条件宏定义,防止重复包含相同头文件
2.#define _STRDUP_HH //若未定义_STRDUP__HH,则定义
3.#include <string.h> //包含标准库字符串处理函数相关头文件string.h
4.//声明字符串拷贝函数strDup
5.//返回备份字符串的指针。若形参str为NULL,则返回NULL。
6.char* strDup(char const* str);
7.
8.char* strDupSize(char const* str);
9.// Like "strDup()", except that it *doesn't* copy the original.
10.//类似“strDup()”,其不能复制原字符串。
11.// (Instead, it just allocates a string of the same size as the original.)
12.//其仅分配一个和原字符串同样的内存空间。
13.//其返回分配的内存空间指针。
14.
15.char* strDupSize(char const* str, size_t& resultBufSize);
16.// An alternative form of "strDupSize()" that also returns the size of the allocated buffer.
17.//另一种“strDupSize()”