Logo Search packages:      
Sourcecode: fence-agents version File versions  Download package

static char* str_prepare_for_sh ( char *  dest,
char *  source,
int  max_len 
) [static]

Prepare string for use in sh style environment. This function take source string and prepend/append quote (') to start/end of source string to dest string. Any occurence of quote in source string is replaced by '\'' sequence. Dest string must be preallocated.

Parameters:
destDestination string
sourceSource string
max_lenMaximum length of data written to dest string (including end 0)
Returns:
Pointer to start of destination string.

Definition at line 218 of file ipmilan.c.

                                                                     {
  char *dest_p=dest;
  char *max_dest=dest+max_len;

  if (dest_p+1>=max_dest) {*dest_p=0;return dest;}
  *dest_p++='\'';

  while (*source) {
    if (*source=='\'') {
      if (dest_p+4>=max_dest) {*dest_p=0;return dest;}

      memcpy(dest_p,"'\\''",4);dest_p+=4;
    } else {
      if (dest_p+1>=max_dest) {*dest_p=0;return dest;}

      *dest_p++=*source;
    }
    source++;
  }

  if (dest_p+2>=max_dest) {*dest_p=0;return dest;}

  *dest_p++='\'';*dest_p=0;

  return dest;
}

Generated by  Doxygen 1.6.0   Back to index