Rewrite of cli_chomp

git-svn: trunk@626
remotes/push_mirror/metadata
Nigel Horne 21 years ago
parent 81aade769a
commit 8f0f9d56b4
  1. 5
      clamav-devel/ChangeLog
  2. 34
      clamav-devel/libclamav/str.c
  3. 2
      clamav-devel/libclamav/str.h

@ -1,3 +1,8 @@
Tue Jun 22 11:58:06 BST 2004 (njh/trog)
---------------------------------------
* libclamav/str.c: Rewrote cli_chomp() as discussed in the clamav-devel
mailing list
Tue Jun 22 05:09:54 BST 2004 (njh)
----------------------------------
* clamav-milter: Avoid unlocking an already unlocked mutex in

@ -73,7 +73,7 @@ short int *cl_hex2str(const char *hex)
val = c;
if((c = cli_hex2int(hex[i+1])) >= 0) {
val = (val << 4) + c;
} else {
} else {
free(str);
return NULL;
}
@ -122,26 +122,30 @@ int cli_strbcasestr(const char *haystack, const char *needle)
return !strcasecmp(pt, needle);
}
void cli_chomp(char *string)
/*
* Remove trailing NL and CR characters from the end of the given string.
* Return the new length of the string (ala strlen)
*/
int
cli_chomp(char *string)
{
size_t l = strlen(string);
int l;
if(string == NULL)
return -1;
if(l == 0)
return;
l = strlen(string);
--l;
if((string[l] == '\n') || (string[l] == '\r')) {
string[l] = '\0';
if(l == 0)
return 0;
if(l > 0) {
--l;
if(string[l] == '\r')
string[l] = '\0';
}
}
}
--l;
while((l >= 0) && ((string[l] == '\n') || (string[l] == '\r')))
string[l--] = '\0';
return l + 1;
}
/*
* char *cli_strok(const char *line, int fieldno, char *delim)

@ -20,7 +20,7 @@
#define __STRINGS_H
int cli_strbcasestr(const char *haystack, const char *needle);
void cli_chomp(char *string);
int cli_chomp(char *string);
char *cli_strtok(const char *line, int field, const char *delim);
#endif

Loading…
Cancel
Save