1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00
putty-source/utils/chomp.c

27 lines
585 B
C
Raw Permalink Normal View History

/*
* Perl-style 'chomp', for a line we just read with fgetline.
*
* Unlike Perl chomp, however, we're deliberately forgiving of strange
* line-ending conventions.
*
* Also we forgive NULL on input, so you can just write 'line =
* chomp(fgetline(fp));' and not bother checking for NULL until
* afterwards.
*/
#include <string.h>
#include "defs.h"
#include "misc.h"
char *chomp(char *str)
{
if (str) {
int len = strlen(str);
while (len > 0 && (str[len-1] == '\r' || str[len-1] == '\n'))
len--;
str[len] = '\0';
}
return str;
}