]> andersk Git - moira.git/blobdiff - server/mr_util.c
lint
[moira.git] / server / mr_util.c
index a8190ca81c8856d7ad0d37b4d4e8d0624cf4a79a..9926446eb854d43c503a02da2c77089c04d1b95a 100644 (file)
@@ -99,7 +99,8 @@ void mr_com_err(whoami, code, fmt, pvar)
 
 
 /* mr_trim_args: passed an argument vector, it will trim any trailing
- * spaces on the args by writing a null into the string.
+ * spaces on the args by writing a null into the string.  If an argument
+ * appears to be binary instead of ASCII, it will not be trimmed.
  */
 
 int mr_trim_args(argc, argv)
@@ -107,12 +108,22 @@ int argc;
 char **argv;
 {
     register char **arg;
-    register char *p, *lastch;
+    register unsigned char *p, *lastch;
 
     for (arg = argv; argc--; arg++) {
-       for (lastch = p = *arg; *p; p++)
-         if (!isspace(*p))
-           lastch = p;
+       for (lastch = p = (unsigned char *) *arg; *p; p++) {
+           /* If any byte in the string has the high bit set, assume
+            * that it is binary and we do not want to trim it.
+            * Setting p = lastch will cause us not to trim the string
+            * when we break out of this inner loop.
+            */
+           if (*p >= 0x80) {
+               p = lastch;
+               break;
+           }
+           if (!isspace(*p))
+             lastch = p;
+       }
        if (p != lastch) {
            if (isspace(*lastch))
              *lastch = 0;
@@ -122,3 +133,21 @@ char **argv;
     }
     return(0);
 }
+
+
+/* returns a copy of the argv and all of it's strings */
+
+char **mr_copy_args(argv, argc)
+char **argv;
+int argc;
+{
+    char **a;
+    int i;
+
+    a = (char **) malloc(argc * sizeof(char *));
+    if (a == 0)
+      return(a);
+    for (i = 0; i < argc; i++)
+      a[i] = strsave(argv[i]);
+    return(a);
+}
This page took 0.032328 seconds and 4 git commands to generate.