gnunet-android

GNUnet for Android
Log | Files | Refs | README

buf.h (2978B)


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