对字符串用引号括起来,对其中的单引号进行转义,主要用于执行一些系统命令(system(cmd))。
  比如:ls -al 会变成 ‘ls -al’
  比如:ls -a’l会变成’ls -a’l’
/*
* Concatenates any number of strings, escapes any OS quote in the result then
* surround the whole affair in another set of quotes which is finally appended
* to specified DYNAMIC_STRING. This function is especially useful when
* building strings to be executed with the system() function.
*
* @param str Dynamic String which will have addtional strings appended.
* @param append String to be appended.
* @param ... Optional. Additional string(s) to be appended.
*
* @ note The final argument in the list must be NullS even if no additional
* options are passed.
*
* @return True = Success.
*/
my_bool dynstr_append_os_quoted( DYNAMIC_STRING *str, const char *append, ... )
{
const char*quote_str= "'";
const uintquote_len= 1;
my_boolret= TRUE;
va_listdirty_text;
ret &= dynstr_append_mem( str, quote_str, quote_len ); /* Leading quote */
va_start( dirty_text, append );
while ( append != NullS )
{
const char*cur_pos= append;
const char*next_pos= cur_pos;
/* Search for quote in each string and replace with escaped quote */
while ( *(next_pos = strcend( cur_pos, quote_str[0] ) ) != '' )
{
ret&= dynstr_append_mem( str, cur_pos, (uint) (next_pos - cur_pos) );
ret&= dynstr_append_mem( str, "\", 1 );
ret&= dynstr_append_mem( str, quote_str, quote_len );
cur_pos = next_pos + 1;
}
ret&= dynstr_append_mem( str, cur_pos, (uint) (next_pos - cur_pos) );
append= va_arg( dirty_text, char * );
}
va_end( dirty_text );
ret &= dynstr_append_mem( str, quote_str, quote_len ); /* Trailing quote */
return(ret);
}
  通过定义动态字符串的结构体信息,每次分次进行字符串添加更多字符,都会根据字符串的当前的长度动态的扩容。而且每次扩容后,该结构体都记录的当前字符串的实际信息(当前字符串的长度,缓冲器可容纳字符串的长度,进行扩容的单元长度)。这样,动态字符串的处理操作变得非常方便了。