Implement BUF_strnlen() and use it instead of strlen().
[openssl.git] / crypto / buffer / buffer.h
index 6d6da3d1861387bf6697313f0d55f6b4341ccb9b..4300d01b3ff6a95253abb1a1f0b7bf7e92152823 100644 (file)
 #ifndef HEADER_BUFFER_H
 #define HEADER_BUFFER_H
 
+#include <openssl/ossl_typ.h>
+
 #ifdef  __cplusplus
 extern "C" {
 #endif
 
-typedef struct buf_mem_st
+#include <stddef.h>
+
+#if !defined(NO_SYS_TYPES_H)
+#include <sys/types.h>
+#endif
+
+/* Already declared in ossl_typ.h */
+/* typedef struct buf_mem_st BUF_MEM; */
+
+struct buf_mem_st
        {
-       int length;     /* current number of bytes */
+       size_t length;  /* current number of bytes */
        char *data;
-       int max;        /* size of buffer */
-       } BUF_MEM;
+       size_t max;     /* size of buffer */
+       };
 
-#ifndef NOPROTO
 BUF_MEM *BUF_MEM_new(void);
 void   BUF_MEM_free(BUF_MEM *a);
-int    BUF_MEM_grow(BUF_MEM *str, int len);
-char * BUF_strdup(char *str);
-
-void ERR_load_BUF_strings(void );
-
-#else
+int    BUF_MEM_grow(BUF_MEM *str, size_t len);
+int    BUF_MEM_grow_clean(BUF_MEM *str, size_t len);
+size_t  BUF_strnlen(const char *str, size_t maxlen);
+char * BUF_strdup(const char *str);
+char * BUF_strndup(const char *str, size_t siz);
+void * BUF_memdup(const void *data, size_t siz);
+void   BUF_reverse(unsigned char *out, unsigned char *in, size_t siz);
 
-BUF_MEM *BUF_MEM_new();
-void   BUF_MEM_free();
-int    BUF_MEM_grow();
-char * BUF_strdup();
+/* safe string functions */
+size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
+size_t BUF_strlcat(char *dst,const char *src,size_t siz);
 
-void ERR_load_BUF_strings();
-
-#endif
 
 /* BEGIN ERROR CODES */
+/* The following lines are auto generated by the script mkerr.pl. Any changes
+ * made after this point may be overwritten when the script is next run.
+ */
+void ERR_load_BUF_strings(void);
+
 /* Error codes for the BUF functions. */
 
 /* Function codes. */
+#define BUF_F_BUF_MEMDUP                                103
 #define BUF_F_BUF_MEM_GROW                              100
+#define BUF_F_BUF_MEM_GROW_CLEAN                        105
 #define BUF_F_BUF_MEM_NEW                               101
 #define BUF_F_BUF_STRDUP                                102
+#define BUF_F_BUF_STRNDUP                               104
 
 /* Reason codes. */
+
 #ifdef  __cplusplus
 }
 #endif
 #endif
-