char *base, *bound, *next;
} asn1buf;
+
+/**************** Private Procedures ****************/
+
+int asn1buf_size
+ PROTOTYPE((const asn1buf *buf));
+/* requires *buf has been created and not destroyed
+ effects Returns the total size
+ PROTOTYPE((in octets) of buf's octet buffer. */
+#define asn1buf_size(buf) \
+ (((buf) == NULL || (buf)->base == NULL) \
+ ? 0 \
+ : ((buf)->bound - (buf)->base + 1))
+
+int asn1buf_free
+ PROTOTYPE((const asn1buf *buf));
+/* requires *buf is allocated
+ effects Returns the number of unused, allocated octets in *buf. */
+#define asn1buf_free(buf) \
+ (((buf) == NULL || (buf)->base == NULL) \
+ ? 0 \
+ : ((buf)->bound - (buf)->next + 1))
+
+
+asn1_error_code asn1buf_ensure_space
+ PROTOTYPE((asn1buf *buf, const int amount));
+/* requires *buf is allocated
+ modifies *buf
+ effects If buf has less than amount octets of free space, then it is
+ expanded to have at least amount octets of free space.
+ Returns ENOMEM memory is exhausted. */
+#define asn1buf_ensure_space(buf,amount) \
+ ((asn1buf_free(buf) < (amount)) \
+ ? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \
+ : 0)
+
+
+asn1_error_code asn1buf_expand
+ PROTOTYPE((asn1buf *buf, int inc));
+/* requires *buf is allocated
+ modifies *buf
+ effects Expands *buf by allocating space for inc more octets.
+ Returns ENOMEM if memory is exhausted. */
+
+int asn1buf_len
+ PROTOTYPE((const asn1buf *buf));
+/* requires *buf is allocated
+ effects Returns the length of the encoding in *buf. */
+#define asn1buf_len(buf) ((buf)->next - (buf)->base)
+
+/****** End of private procedures *****/
+
/*
Overview
/* requires *buf is allocated
effects Inserts o into the buffer *buf, expanding the buffer if
necessary. Returns ENOMEM memory is exhausted. */
-#if __GNUC__ >= 2
-#define asn1buf_insert_octet(BUF,O) \
- (asn1buf_ensure_space ((BUF),1) \
- ? /* leave this empty -- gcc returns value of first operand */ \
- : (*(BUF)->next++ = (O), 0))
+#if ((__GNUC__ >= 2) && !defined(ASN1BUF_OMIT_INLINE_FUNCS))
+extern inline asn1_error_code asn1buf_insert_octet(buf, o)
+ asn1buf * buf;
+ const int o;
+{
+ asn1_error_code retval;
+
+ retval = asn1buf_ensure_space(buf,1);
+ if(retval) return retval;
+ *(buf->next) = (char)o;
+ (buf->next)++;
+ return 0;
+}
#endif
asn1_error_code asn1buf_insert_octetstring
modifies *buf
effects Returns the number of unprocessed octets remaining in *buf. */
-/**************** Private Procedures ****************/
-
-int asn1buf_size
- PROTOTYPE((const asn1buf *buf));
-/* requires *buf has been created and not destroyed
- effects Returns the total size
- PROTOTYPE((in octets) of buf's octet buffer. */
-#define asn1buf_size(buf) \
- (((buf) == NULL || (buf)->base == NULL) \
- ? 0 \
- : ((buf)->bound - (buf)->base + 1))
-
-int asn1buf_free
- PROTOTYPE((const asn1buf *buf));
-/* requires *buf is allocated
- effects Returns the number of unused, allocated octets in *buf. */
-#define asn1buf_free(buf) \
- (((buf) == NULL || (buf)->base == NULL) \
- ? 0 \
- : ((buf)->bound - (buf)->next + 1))
-
-
-asn1_error_code asn1buf_ensure_space
- PROTOTYPE((asn1buf *buf, const int amount));
-/* requires *buf is allocated
- modifies *buf
- effects If buf has less than amount octets of free space, then it is
- expanded to have at least amount octets of free space.
- Returns ENOMEM memory is exhausted. */
-#define asn1buf_ensure_space(buf,amount) \
- ((asn1buf_free(buf) < (amount)) \
- ? (asn1buf_expand((buf), (amount)-asn1buf_free(buf))) \
- : 0)
-
-
-asn1_error_code asn1buf_expand
- PROTOTYPE((asn1buf *buf, int inc));
-/* requires *buf is allocated
- modifies *buf
- effects Expands *buf by allocating space for inc more octets.
- Returns ENOMEM if memory is exhausted. */
-
-int asn1buf_len
- PROTOTYPE((const asn1buf *buf));
-/* requires *buf is allocated
- effects Returns the length of the encoding in *buf. */
-#define asn1buf_len(buf) ((buf)->next - (buf)->base)
-
#endif