diff options
author | Dr. David von Oheimb <David.von.Oheimb@siemens.com> | 2020-09-23 10:11:53 +0200 |
---|---|---|
committer | Dr. David von Oheimb <dev@ddvo.net> | 2021-05-19 09:23:30 +0200 |
commit | 184238794fe52353f5e042fa9b943fbc59a5b9cb (patch) | |
tree | d14328fd18bc044dc99b103a9596e36bc1533c3b /crypto/bio | |
parent | c4fca3f705a220fba8e15354d57d258e69a2d9b4 (diff) |
bio_lib: Add BIO_get_line, correct doc of BIO_gets
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/12959)
Diffstat (limited to 'crypto/bio')
-rw-r--r-- | crypto/bio/bio_lib.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/crypto/bio/bio_lib.c b/crypto/bio/bio_lib.c index 3fa8ff4f16..9f25376e95 100644 --- a/crypto/bio/bio_lib.c +++ b/crypto/bio/bio_lib.c @@ -477,6 +477,37 @@ int BIO_gets(BIO *b, char *buf, int size) return ret; } +int BIO_get_line(BIO *bio, char *buf, int size) +{ + int ret = 0; + char *ptr = buf; + + if (buf == NULL) { + ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER); + return -1; + } + if (size <= 0) { + ERR_raise(ERR_LIB_BIO, BIO_R_INVALID_ARGUMENT); + return -1; + } + *buf = '\0'; + + if (bio == NULL) { + ERR_raise(ERR_LIB_BIO, ERR_R_PASSED_NULL_PARAMETER); + return -1; + } + if (!bio->init) { + ERR_raise(ERR_LIB_BIO, BIO_R_UNINITIALIZED); + return -1; + } + + while (size-- > 1 && (ret = BIO_read(bio, ptr, 1)) > 0) + if (*ptr++ == '\n') + break; + *ptr = '\0'; + return ret > 0 || BIO_eof(bio) ? ptr - buf : ret; +} + int BIO_indent(BIO *b, int indent, int max) { if (indent < 0) |