mirror of
https://github.com/libssh2/libssh2.git
synced 2025-11-05 09:30:35 +03:00
pem.c: reduce number of calls to strlen in readline
This commit is contained in:
18
src/pem.c
18
src/pem.c
@@ -41,15 +41,25 @@
|
|||||||
static int
|
static int
|
||||||
readline(char *line, int line_size, FILE * fp)
|
readline(char *line, int line_size, FILE * fp)
|
||||||
{
|
{
|
||||||
|
size_t len;
|
||||||
|
|
||||||
|
if (!*line) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (!fgets(line, line_size, fp)) {
|
if (!fgets(line, line_size, fp)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (*line && line[strlen(line) - 1] == '\n') {
|
|
||||||
line[strlen(line) - 1] = '\0';
|
len = strlen(line);
|
||||||
|
if (len > 0 && line[len - 1] == '\n') {
|
||||||
|
line[len - 1] = '\0';
|
||||||
}
|
}
|
||||||
if (*line && line[strlen(line) - 1] == '\r') {
|
|
||||||
line[strlen(line) - 1] = '\0';
|
len = strlen(line);
|
||||||
|
if (len > 0 && line[len - 1] == '\r') {
|
||||||
|
line[len - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user