8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sendmail / libsmutil / snprintf.c
blob223668edda9cf3df95bf04e2fe0add3cf020eafd
1 /*
2 * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers.
3 * All rights reserved.
4 * Copyright (c) 1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
14 #pragma ident "%Z%%M% %I% %E% SMI"
16 #include <sendmail.h>
18 SM_RCSID("@(#)$Id: snprintf.c,v 8.41 2001/08/28 23:07:01 gshapiro Exp $")
20 \f/*
21 ** SHORTENSTRING -- return short version of a string
23 ** If the string is already short, just return it. If it is too
24 ** long, return the head and tail of the string.
26 ** Parameters:
27 ** s -- the string to shorten.
28 ** m -- the max length of the string (strlen()).
30 ** Returns:
31 ** Either s or a short version of s.
34 char *
35 shortenstring(s, m)
36 register const char *s;
37 size_t m;
39 size_t l;
40 static char buf[MAXSHORTSTR + 1];
42 l = strlen(s);
43 if (l < m)
44 return (char *) s;
45 if (m > MAXSHORTSTR)
46 m = MAXSHORTSTR;
47 else if (m < 10)
49 if (m < 5)
51 (void) sm_strlcpy(buf, s, m + 1);
52 return buf;
54 (void) sm_strlcpy(buf, s, m - 2);
55 (void) sm_strlcat(buf, "...", sizeof buf);
56 return buf;
58 m = (m - 3) / 2;
59 (void) sm_strlcpy(buf, s, m + 1);
60 (void) sm_strlcat2(buf, "...", s + l - m, sizeof buf);
61 return buf;