- extern char *error_message();
- extern client *cur_client;
-
- struct iovec strings[7];
- char buf[32];
- if (cur_client)
- (void) sprintf(buf, "[#%d]", cur_client->id);
- else buf[0]='\0';
-
- strings[1].iov_base = buf;
- strings[1].iov_len = strlen(buf);
-
- strings[0].iov_base = whoami;
- if (whoami) {
- strings[0].iov_len = strlen(whoami);
- strings[2].iov_base = ": ";
- strings[2].iov_len = 2;
- } else {
- strings[0].iov_len = 0;
- strings[2].iov_base = " ";
- strings[2].iov_len = 1;
+ char *buf, **qargv;
+ int i, len;
+ char *bp;
+
+ qargv = xmalloc(argc * sizeof(char *));
+
+ for (i = len = 0; i < argc; i++)
+ {
+ qargv[i] = requote(argv[i]);
+ len += strlen(qargv[i]) + 2;
+ }
+
+ buf = xmalloc(len + 1);
+
+ for (i = 0, *buf = '\0'; i < argc; i++)
+ {
+ if (i)
+ strcat(buf, ", ");
+ strcat(buf, qargv[i]);
+ free(qargv[i]);
+ }
+ free(qargv);
+
+ com_err(whoami, 0, "%s[%d]: %s", tag, version, buf);
+ free(buf);
+}
+
+void mr_com_err(const char *whoami, long code, const char *fmt, va_list pvar)
+{
+ extern client *cur_client;
+
+ if (whoami)
+ {
+ fputs(whoami, stderr);
+ if (cur_client)
+ fprintf(stderr, "[#%d]", cur_client->id);
+ fputs(": ", stderr);
+ }
+ if (code) {
+ fputs(error_message(code), stderr);
+ fputs(" ", stderr);
+ }
+ if (fmt)
+ vfprintf(stderr, fmt, pvar);
+ putc('\n', stderr);
+}
+
+
+/* mr_trim_args: passed an argument vector, it will trim any trailing
+ * 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(int argc, char **argv)
+{
+ char **arg;
+ unsigned char *p, *lastch;
+
+ for (arg = argv; argc--; arg++)
+ {
+ 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;