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

bufchain: new combined fetch + consume functions.

bufchain_fetch_consume is a one-stop function that moves a given
number of bytes out of the head of a bufchain into an output buffer,
removing them from the bufchain in the process.

That function will fail an assertion (just like bufchain_fetch) if the
bufchain doesn't actually _have_ at least that many bytes to read, so
I also provide bufchain_try_fetch_consume which will return a success
or failure status.

Nothing uses these functions yet, but they will.
This commit is contained in:
Simon Tatham 2018-05-18 07:22:57 +01:00
parent e3bdd6231e
commit 9d96c3eb02
2 changed files with 18 additions and 0 deletions

16
misc.c
View File

@ -751,6 +751,22 @@ void bufchain_fetch(bufchain *ch, void *data, int len)
}
}
void bufchain_fetch_consume(bufchain *ch, void *data, int len)
{
bufchain_fetch(ch, data, len);
bufchain_consume(ch, len);
}
int bufchain_try_fetch_consume(bufchain *ch, void *data, int len)
{
if (ch->buffersize >= len) {
bufchain_fetch_consume(ch, data, len);
return TRUE;
} else {
return FALSE;
}
}
/* ----------------------------------------------------------------------
* My own versions of malloc, realloc and free. Because I want
* malloc and realloc to bomb out and exit the program if they run

2
misc.h
View File

@ -82,6 +82,8 @@ void bufchain_add(bufchain *ch, const void *data, int len);
void bufchain_prefix(bufchain *ch, void **data, int *len);
void bufchain_consume(bufchain *ch, int len);
void bufchain_fetch(bufchain *ch, void *data, int len);
void bufchain_fetch_consume(bufchain *ch, void *data, int len);
int bufchain_try_fetch_consume(bufchain *ch, void *data, int len);
int validate_manual_hostkey(char *key);