summaryrefslogtreecommitdiffstats
path: root/minadbd21/utils.h
diff options
context:
space:
mode:
authorEthan Yonker <dees_troy@teamw.in>2017-05-10 23:11:35 +0200
committerEthan Yonker <dees_troy@teamw.in>2017-05-10 23:11:35 +0200
commit84d61ce31c48d0da495617f64edb724eeb36d3bc (patch)
tree443d459f7e0e3b0b7080522891dd1b92dfb2e6c7 /minadbd21/utils.h
parentAdopted Storage: backup keys but do not wipe them (diff)
parentAdd a checker for signature boundary in verifier am: 54ea136fde am: 0a34b17c8b am: fb80b4f72d am: d3d5e54a45 am: 6ea9888d51 am: a055eb93c3 am: 15ca2a4763 am: ca50d7b66a am: 64f0de7a13 am: e4ec60e045 (diff)
downloadandroid_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.tar
android_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.tar.gz
android_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.tar.bz2
android_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.tar.lz
android_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.tar.xz
android_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.tar.zst
android_bootable_recovery-84d61ce31c48d0da495617f64edb724eeb36d3bc.zip
Diffstat (limited to 'minadbd21/utils.h')
-rw-r--r--minadbd21/utils.h68
1 files changed, 68 insertions, 0 deletions
diff --git a/minadbd21/utils.h b/minadbd21/utils.h
new file mode 100644
index 000000000..f70ecd24d
--- /dev/null
+++ b/minadbd21/utils.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#ifndef _ADB_UTILS_H
+#define _ADB_UTILS_H
+
+/* bounded buffer functions */
+
+/* all these functions are used to append data to a bounded buffer.
+ *
+ * after each operation, the buffer is guaranteed to be zero-terminated,
+ * even in the case of an overflow. they all return the new buffer position
+ * which allows one to use them in succession, only checking for overflows
+ * at the end. For example:
+ *
+ * BUFF_DECL(temp,p,end,1024);
+ * char* p;
+ *
+ * p = buff_addc(temp, end, '"');
+ * p = buff_adds(temp, end, string);
+ * p = buff_addc(temp, end, '"');
+ *
+ * if (p >= end) {
+ * overflow detected. note that 'temp' is
+ * zero-terminated for safety.
+ * }
+ * return strdup(temp);
+ */
+
+/* tries to add a character to the buffer, in case of overflow
+ * this will only write a terminating zero and return buffEnd.
+ */
+char* buff_addc (char* buff, char* buffEnd, int c);
+
+/* tries to add a string to the buffer */
+char* buff_adds (char* buff, char* buffEnd, const char* s);
+
+/* tries to add a bytes to the buffer. the input can contain zero bytes,
+ * but a terminating zero will always be appended at the end anyway
+ */
+char* buff_addb (char* buff, char* buffEnd, const void* data, int len);
+
+/* tries to add a formatted string to a bounded buffer */
+char* buff_add (char* buff, char* buffEnd, const char* format, ... );
+
+/* convenience macro used to define a bounded buffer, as well as
+ * a 'cursor' and 'end' variables all in one go.
+ *
+ * note: this doesn't place an initial terminating zero in the buffer,
+ * you need to use one of the buff_ functions for this. or simply
+ * do _cursor[0] = 0 manually.
+ */
+#define BUFF_DECL(_buff,_cursor,_end,_size) \
+ char _buff[_size], *_cursor=_buff, *_end = _cursor + (_size)
+
+#endif /* _ADB_UTILS_H */