+/* Escape a set of characters */
+char *os_shell_escape(const char *src)
+{
+ /* Maximum Length of the String is 2 times the current length */
+ char shell_escapes[] = { '\\', '"', '\'', ' ', '\t', ';', '`', '>', '<', '|', '#',
+ '*', '[', ']', '{', '}', '&', '$', '!', ':', '(', ')'
+ };
+
+ char *escaped_string;
+ size_t length = 0;
+ int i = 0;
+
+ if (src == NULL) {
+ return NULL;
+ }
+
+ /* Determine how long the string will be */
+ const char *iterator = src;
+ for (; *iterator; iterator++) {
+ if ( strchr(shell_escapes, *iterator) ) {
+ length++;
+ }
+ length++;
+ }
+ /* Allocate memory */
+ if ( (escaped_string = (char *) calloc(1, length + 1 )) == NULL ) {
+ // Return NULL
+ return NULL;
+ }
+
+ /* Escape the escapable characters */
+ iterator = src;
+ for ( i = 0; *iterator; iterator++ ) {
+ if ( strchr(shell_escapes, *iterator) ) {
+ escaped_string[i] = '\\';
+ i++;
+ }
+ escaped_string[i] = *iterator;
+ i++;
+ }
+
+ return escaped_string;
+}