+ /* NOTREACHED */
+}
+
+/*
+ * Check whether an allocation of 'len' will fit in the buffer
+ * This must follow the same math as buffer_append_space
+ */
+int
+buffer_check_alloc(Buffer *buffer, u_int len)
+{
+ u_int buf_max;
+ u_int buf_alloc_sz;
+
+ if (buffer->offset == buffer->end) {
+ buffer->offset = 0;
+ buffer->end = 0;
+ }
+ restart:
+ if (buffer->end + len < buffer->alloc)
+ return (1);
+ if (buffer_compact(buffer))
+ goto restart;
+
+ /* if hpn is disabled use the smaller buffer size */
+ buf_max = BUFFER_MAX_LEN_HPN;
+ buf_alloc_sz = BUFFER_ALLOCSZ_HPN;
+
+ if (roundup(buffer->alloc + len, buf_alloc_sz) <= buf_max)
+ return (1);
+ return (0);