-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstringfunc.c
74 lines (63 loc) · 1.42 KB
/
stringfunc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Hans Liss <[email protected]>
*
* This is based in part on code from IP-login2 from the same author,
* which uses ICMP ping code from Mike Muuss 'ping' program.
*
*/
#include <ctype.h>
#ifndef WIN32
#include "config.h"
#else
#define HAVE_STRING_H 1
#endif
#if HAVE_STRINGS_H==1
#include <strings.h>
#endif
#if HAVE_STRING_H==1
#include <string.h>
#endif
/* Functions for cleaning up random strings for logging */
int isjunk(char c)
{
return ((c < ' ') || (c>126));
}
void dejunkifyforlog(char *s)
{
unsigned int i;
if (strlen(s)>32)
s[32]='\0';
for (i=0; i<strlen(s); i++)
if (isjunk(s[i]))
s[i]='.';
}
/* Remove line breaks at end of string */
int choppable(int c)
{
return (isspace(c));
}
void chop(char *string)
{
if (string)
{
while (strlen(string) && choppable(string[strlen(string)-1]))
string[strlen(string)-1]='\0';
}
}
/* Remove all blanks at the beginning and end of a string */
void cleanupstring(char *string)
{
int i=strlen(string)-1;
while (i>0 && isspace((int)string[i]))
i--;
string[i+1]='\0';
i=0;
while (isspace((int)string[i]))
i++;
memmove(string,&(string[i]),strlen(&(string[i]))+1);
}