~ubuntu-branches/ubuntu/quantal/open-vm-tools/quantal-201210021442

« back to all changes in this revision

Viewing changes to lib/misc/escape.c

  • Committer: Bazaar Package Importer
  • Author(s): Serge Hallyn
  • Date: 2011-03-31 14:20:05 UTC
  • mfrom: (1.4.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20110331142005-3n9red91p7ogkweo
Tags: 2011.03.28-387002-0ubuntu1
* Merge latest upstream git tag.  This has the unlocked_ioctl change
  needed to fix dkms build failures (LP: #727342)
* Changes in debian/rules:
  - work around a bug in toolbox/Makefile, where install-exec-hook is
    not happening.  This needs to get fixed the right way.
  - don't install 'vmware-user' which seems to no longer exist
  - move /etc/xdg into open-vm-toolbox (which should be done using .install)
* debian/open-vm-tools.init: add 'modprobe [-r] vmblock'. (LP: #332323)
* debian/rules and debian/open-vm-toolbox.lintian-overrides:
  - Make vmware-user-suid-wrapper suid-root (LP: #332323)

Show diffs side-by-side

added added

removed removed

Lines of Context:
684
684
   return 0;
685
685
}
686
686
#endif
 
687
 
 
688
 
 
689
/*
 
690
 *-----------------------------------------------------------------------------
 
691
 *
 
692
 * Escape_Comma --
 
693
 *
 
694
 *       Use backslash character as an escape character to handle comma
 
695
 *       character escaping.
 
696
 *
 
697
 * Results:
 
698
 *       Returns a newly allocated string with comma and backslash characters
 
699
 *       escaped.
 
700
 *
 
701
 * Side effects:
 
702
 *       None.  It is a caller responsibility to deallocate the result.
 
703
 *
 
704
 *-----------------------------------------------------------------------------
 
705
 */
 
706
 
 
707
char *
 
708
Escape_Comma(const char *string) // IN
 
709
{
 
710
   DynBuf b;
 
711
 
 
712
   if (NULL == string) {
 
713
      return NULL;
 
714
   }
 
715
 
 
716
   DynBuf_Init(&b);
 
717
 
 
718
   for (; *string; ++string) {
 
719
      char c = *string;
 
720
 
 
721
      if (c == ',' || c == '\\') {
 
722
         if (!DynBuf_Append(&b, "\\", 1)) {
 
723
            goto out_of_memory;
 
724
         }
 
725
      }
 
726
      if (!DynBuf_Append(&b, string, 1)) {
 
727
         goto out_of_memory;
 
728
      }
 
729
   }
 
730
 
 
731
   DynBuf_Append(&b, string, 1);
 
732
 
 
733
   return DynBuf_Get(&b);
 
734
 
 
735
out_of_memory:
 
736
   DynBuf_Destroy(&b);
 
737
   return NULL;
 
738
}
 
739
 
 
740
 
 
741
#if 0
 
742
/* Unit test suite for Escape_Comma() */
 
743
int
 
744
main(int argc,
 
745
     char **argv)
 
746
{
 
747
   static struct {
 
748
      const char *in;
 
749
      const char *out;
 
750
   } tests[] = {
 
751
      { "123# ", "123# ", },
 
752
      { "123,", "123\\,", },
 
753
      { "'123\\", "'123\\\\", },
 
754
   };
 
755
   unsigned int i;
 
756
 
 
757
   for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
 
758
      char *out;
 
759
 
 
760
      out = Escape_Comma(tests[i].in);
 
761
      if (strcmp(out, tests[i].out) != 0) {
 
762
         printf("test %u failed: \"%s\" : \"%s\"\n", i, tests[i].in, out);
 
763
         exit(1);
 
764
      }
 
765
      free(out);
 
766
   }
 
767
 
 
768
   printf("all tests passed\n");
 
769
 
 
770
   return 0;
 
771
}
 
772
 
 
773
#endif
 
774