mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-25 01:02:24 +00:00
Utility function: 'chomp'.
Basically like Perl's, only we forgive \r\n line endings.
This commit is contained in:
parent
6912888c8a
commit
6179c5cc7c
18
misc.c
18
misc.c
@ -473,6 +473,24 @@ char *fgetline(FILE *fp)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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.
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/* ----------------------------------------------------------------------
|
/* ----------------------------------------------------------------------
|
||||||
* Core base64 encoding and decoding routines.
|
* Core base64 encoding and decoding routines.
|
||||||
*/
|
*/
|
||||||
|
1
misc.h
1
misc.h
@ -42,6 +42,7 @@ void burnstr(char *string);
|
|||||||
int toint(unsigned);
|
int toint(unsigned);
|
||||||
|
|
||||||
char *fgetline(FILE *fp);
|
char *fgetline(FILE *fp);
|
||||||
|
char *chomp(char *str);
|
||||||
|
|
||||||
void base64_encode_atom(unsigned char *data, int n, char *out);
|
void base64_encode_atom(unsigned char *data, int n, char *out);
|
||||||
int base64_decode_atom(char *atom, unsigned char *out);
|
int base64_decode_atom(char *atom, unsigned char *out);
|
||||||
|
Loading…
Reference in New Issue
Block a user