1 /* 2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the OpenSSL license (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10 #ifndef OPENSSL_HEADER_BUFFER_H 11 #define OPENSSL_HEADER_BUFFER_H 12 13 #include <openssl/base.h> 14 15 #if defined(__cplusplus) 16 extern "C" { 17 #endif 18 19 20 // Memory and string functions, see also mem.h. 21 22 23 // buf_mem_st (aka |BUF_MEM|) is a generic buffer object used by OpenSSL. 24 struct buf_mem_st { 25 size_t length; // current number of bytes 26 char *data; 27 size_t max; // size of buffer 28 }; 29 30 // BUF_MEM_new creates a new BUF_MEM which has no allocated data buffer. 31 OPENSSL_EXPORT BUF_MEM *BUF_MEM_new(void); 32 33 // BUF_MEM_free frees |buf->data| if needed and then frees |buf| itself. 34 OPENSSL_EXPORT void BUF_MEM_free(BUF_MEM *buf); 35 36 // BUF_MEM_reserve ensures |buf| has capacity |cap| and allocates memory if 37 // needed. It returns one on success and zero on error. 38 OPENSSL_EXPORT int BUF_MEM_reserve(BUF_MEM *buf, size_t cap); 39 40 // BUF_MEM_grow ensures that |buf| has length |len| and allocates memory if 41 // needed. If the length of |buf| increased, the new bytes are filled with 42 // zeros. It returns the length of |buf|, or zero if there's an error. 43 OPENSSL_EXPORT size_t BUF_MEM_grow(BUF_MEM *buf, size_t len); 44 45 // BUF_MEM_grow_clean calls |BUF_MEM_grow|. BoringSSL always zeros memory 46 // allocated memory on free. 47 OPENSSL_EXPORT size_t BUF_MEM_grow_clean(BUF_MEM *buf, size_t len); 48 49 // BUF_MEM_append appends |in| to |buf|. It returns one on success and zero on 50 // error. 51 OPENSSL_EXPORT int BUF_MEM_append(BUF_MEM *buf, const void *in, size_t len); 52 53 54 // Deprecated functions. 55 56 // BUF_strdup calls |OPENSSL_strdup|. 57 OPENSSL_EXPORT char *BUF_strdup(const char *str); 58 59 // BUF_strnlen calls |OPENSSL_strnlen|. 60 OPENSSL_EXPORT size_t BUF_strnlen(const char *str, size_t max_len); 61 62 // BUF_strndup calls |OPENSSL_strndup|. 63 OPENSSL_EXPORT char *BUF_strndup(const char *str, size_t size); 64 65 // BUF_memdup calls |OPENSSL_memdup|. 66 OPENSSL_EXPORT void *BUF_memdup(const void *data, size_t size); 67 68 // BUF_strlcpy calls |OPENSSL_strlcpy|. 69 OPENSSL_EXPORT size_t BUF_strlcpy(char *dst, const char *src, size_t dst_size); 70 71 // BUF_strlcat calls |OPENSSL_strlcat|. 72 OPENSSL_EXPORT size_t BUF_strlcat(char *dst, const char *src, size_t dst_size); 73 74 75 #if defined(__cplusplus) 76 } // extern C 77 78 extern "C++" { 79 80 BSSL_NAMESPACE_BEGIN 81 82 BORINGSSL_MAKE_DELETER(BUF_MEM, BUF_MEM_free) 83 84 BSSL_NAMESPACE_END 85 86 } // extern C++ 87 88 #endif 89 90 #endif // OPENSSL_HEADER_BUFFER_H 91