-static char *escape( const char *psz )
-{
- if( !psz )
- return NULL;
-
- /* Count the number of ' and \ in the string */
- const char *it = psz;
- int i_esc = 0;
- while( *it != '\0')
- {
- if( *it == '\'' || *it == '\\' )
- i_esc++;
- it++;
- }
-
- if( i_esc == 0 )
- return strdup( psz );
-
- char *psz_esc = malloc( strlen( psz ) + i_esc + 1 );
- char *it2 = psz_esc;
- it = psz;
- while( *it != '\0' )
- {
- if( *it == '\'' || *it == '\\' )
- *it2++ = '\\';
- *it2++ = *it++;
- }
- *it2 = '\0';
-
- return psz_esc;
-}