summaryrefslogtreecommitdiff
path: root/usr/src/cmd/sendmail/libsmutil/snprintf.c
diff options
context:
space:
mode:
authorstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
committerstevel@tonic-gate <none@none>2005-06-14 00:00:00 -0700
commit7c478bd95313f5f23a4c958a745db2134aa03244 (patch)
treec871e58545497667cbb4b0a4f2daf204743e1fe7 /usr/src/cmd/sendmail/libsmutil/snprintf.c
downloadillumos-joyent-7c478bd95313f5f23a4c958a745db2134aa03244.tar.gz
OpenSolaris Launch
Diffstat (limited to 'usr/src/cmd/sendmail/libsmutil/snprintf.c')
-rw-r--r--usr/src/cmd/sendmail/libsmutil/snprintf.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/usr/src/cmd/sendmail/libsmutil/snprintf.c b/usr/src/cmd/sendmail/libsmutil/snprintf.c
new file mode 100644
index 0000000000..223668edda
--- /dev/null
+++ b/usr/src/cmd/sendmail/libsmutil/snprintf.c
@@ -0,0 +1,62 @@
+/*
+ * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
+ * All rights reserved.
+ * Copyright (c) 1997 Eric P. Allman. All rights reserved.
+ * Copyright (c) 1988, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * By using this file, you agree to the terms and conditions set
+ * forth in the LICENSE file which can be found at the top level of
+ * the sendmail distribution.
+ *
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sendmail.h>
+
+SM_RCSID("@(#)$Id: snprintf.c,v 8.41 2001/08/28 23:07:01 gshapiro Exp $")
+
+ /*
+** SHORTENSTRING -- return short version of a string
+**
+** If the string is already short, just return it. If it is too
+** long, return the head and tail of the string.
+**
+** Parameters:
+** s -- the string to shorten.
+** m -- the max length of the string (strlen()).
+**
+** Returns:
+** Either s or a short version of s.
+*/
+
+char *
+shortenstring(s, m)
+ register const char *s;
+ size_t m;
+{
+ size_t l;
+ static char buf[MAXSHORTSTR + 1];
+
+ l = strlen(s);
+ if (l < m)
+ return (char *) s;
+ if (m > MAXSHORTSTR)
+ m = MAXSHORTSTR;
+ else if (m < 10)
+ {
+ if (m < 5)
+ {
+ (void) sm_strlcpy(buf, s, m + 1);
+ return buf;
+ }
+ (void) sm_strlcpy(buf, s, m - 2);
+ (void) sm_strlcat(buf, "...", sizeof buf);
+ return buf;
+ }
+ m = (m - 3) / 2;
+ (void) sm_strlcpy(buf, s, m + 1);
+ (void) sm_strlcat2(buf, "...", s + l - m, sizeof buf);
+ return buf;
+}