/contrib/ntp/include/isc/buffer.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 800 lines · 269 code · 66 blank · 465 comment · 24 complexity · 89d3032428a80c9209d732e7c9437da9 MD5 · raw file

  1. /*
  2. * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1998-2002 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id: buffer.h,v 1.39.12.2 2004/03/08 09:04:51 marka Exp $ */
  18. #ifndef ISC_BUFFER_H
  19. #define ISC_BUFFER_H 1
  20. /*****
  21. ***** Module Info
  22. *****/
  23. /*
  24. * Buffers
  25. *
  26. * A buffer is a region of memory, together with a set of related subregions.
  27. * Buffers are used for parsing and I/O operations.
  28. *
  29. * The 'used region' and the 'available' region are disjoint, and their
  30. * union is the buffer's region. The used region extends from the beginning
  31. * of the buffer region to the last used byte. The available region
  32. * extends from one byte greater than the last used byte to the end of the
  33. * buffer's region. The size of the used region can be changed using various
  34. * buffer commands. Initially, the used region is empty.
  35. *
  36. * The used region is further subdivided into two disjoint regions: the
  37. * 'consumed region' and the 'remaining region'. The union of these two
  38. * regions is the used region. The consumed region extends from the beginning
  39. * of the used region to the byte before the 'current' offset (if any). The
  40. * 'remaining' region the current pointer to the end of the used
  41. * region. The size of the consumed region can be changed using various
  42. * buffer commands. Initially, the consumed region is empty.
  43. *
  44. * The 'active region' is an (optional) subregion of the remaining region.
  45. * It extends from the current offset to an offset in the remaining region
  46. * that is selected with isc_buffer_setactive(). Initially, the active region
  47. * is empty. If the current offset advances beyond the chosen offset, the
  48. * active region will also be empty.
  49. *
  50. * /------------entire length---------------\
  51. * /----- used region -----\/-- available --\
  52. * +----------------------------------------+
  53. * | consumed | remaining | |
  54. * +----------------------------------------+
  55. * a b c d e
  56. *
  57. * a == base of buffer.
  58. * b == current pointer. Can be anywhere between a and d.
  59. * c == active pointer. Meaningful between b and d.
  60. * d == used pointer.
  61. * e == length of buffer.
  62. *
  63. * a-e == entire length of buffer.
  64. * a-d == used region.
  65. * a-b == consumed region.
  66. * b-d == remaining region.
  67. * b-c == optional active region.
  68. *
  69. * The following invariants are maintained by all routines:
  70. *
  71. * length > 0
  72. *
  73. * base is a valid pointer to length bytes of memory
  74. *
  75. * 0 <= used <= length
  76. *
  77. * 0 <= current <= used
  78. *
  79. * 0 <= active <= used
  80. * (although active < current implies empty active region)
  81. *
  82. * MP:
  83. * Buffers have no synchronization. Clients must ensure exclusive
  84. * access.
  85. *
  86. * Reliability:
  87. * No anticipated impact.
  88. *
  89. * Resources:
  90. * Memory: 1 pointer + 6 unsigned integers per buffer.
  91. *
  92. * Security:
  93. * No anticipated impact.
  94. *
  95. * Standards:
  96. * None.
  97. */
  98. /***
  99. *** Imports
  100. ***/
  101. #include <isc/lang.h>
  102. #include <isc/magic.h>
  103. #include <isc/types.h>
  104. /*
  105. * To make many functions be inline macros (via #define) define this.
  106. * If it is undefined, a function will be used.
  107. */
  108. #define ISC_BUFFER_USEINLINE
  109. ISC_LANG_BEGINDECLS
  110. /***
  111. *** Magic numbers
  112. ***/
  113. #define ISC_BUFFER_MAGIC 0x42756621U /* Buf!. */
  114. #define ISC_BUFFER_VALID(b) ISC_MAGIC_VALID(b, ISC_BUFFER_MAGIC)
  115. /*
  116. * The following macros MUST be used only on valid buffers. It is the
  117. * caller's responsibility to ensure this by using the ISC_BUFFER_VALID
  118. * check above, or by calling another isc_buffer_*() function (rather than
  119. * another macro.)
  120. */
  121. /*
  122. * Fundamental buffer elements. (A through E in the introductory comment.)
  123. */
  124. #define isc_buffer_base(b) ((void *)(b)->base) /*a*/
  125. #define isc_buffer_current(b) \
  126. ((void *)((unsigned char *)(b)->base + (b)->current)) /*b*/
  127. #define isc_buffer_active(b) \
  128. ((void *)((unsigned char *)(b)->base + (b)->active)) /*c*/
  129. #define isc_buffer_used(b) \
  130. ((void *)((unsigned char *)(b)->base + (b)->used)) /*d*/
  131. #define isc_buffer_length(b) ((b)->length) /*e*/
  132. /*
  133. * Derived lengths. (Described in the introductory comment.)
  134. */
  135. #define isc_buffer_usedlength(b) ((b)->used) /* d-a */
  136. #define isc_buffer_consumedlength(b) ((b)->current) /* b-a */
  137. #define isc_buffer_remaininglength(b) ((b)->used - (b)->current) /* d-b */
  138. #define isc_buffer_activelength(b) ((b)->active - (b)->current) /* c-b */
  139. #define isc_buffer_availablelength(b) ((b)->length - (b)->used) /* e-d */
  140. /*
  141. * Note that the buffer structure is public. This is principally so buffer
  142. * operations can be implemented using macros. Applications are strongly
  143. * discouraged from directly manipulating the structure.
  144. */
  145. struct isc_buffer {
  146. unsigned int magic;
  147. void *base;
  148. /* The following integers are byte offsets from 'base'. */
  149. unsigned int length;
  150. unsigned int used;
  151. unsigned int current;
  152. unsigned int active;
  153. /* linkable */
  154. ISC_LINK(isc_buffer_t) link;
  155. /* private internal elements */
  156. isc_mem_t *mctx;
  157. };
  158. /***
  159. *** Functions
  160. ***/
  161. isc_result_t
  162. isc_buffer_allocate(isc_mem_t *mctx, isc_buffer_t **dynbuffer,
  163. unsigned int length);
  164. /*
  165. * Allocate a dynamic linkable buffer which has "length" bytes in the
  166. * data region.
  167. *
  168. * Requires:
  169. * "mctx" is valid.
  170. *
  171. * "dynbuffer" is non-NULL, and "*dynbuffer" is NULL.
  172. *
  173. * Returns:
  174. * ISC_R_SUCCESS - success
  175. * ISC_R_NOMEMORY - no memory available
  176. *
  177. * Note:
  178. * Changing the buffer's length field is not permitted.
  179. */
  180. void
  181. isc_buffer_free(isc_buffer_t **dynbuffer);
  182. /*
  183. * Release resources allocated for a dynamic buffer.
  184. *
  185. * Requires:
  186. * "dynbuffer" is not NULL.
  187. *
  188. * "*dynbuffer" is a valid dynamic buffer.
  189. *
  190. * Ensures:
  191. * "*dynbuffer" will be NULL on return, and all memory associated with
  192. * the dynamic buffer is returned to the memory context used in
  193. * isc_buffer_allocate().
  194. */
  195. void
  196. isc__buffer_init(isc_buffer_t *b, const void *base, unsigned int length);
  197. /*
  198. * Make 'b' refer to the 'length'-byte region starting at base.
  199. *
  200. * Requires:
  201. *
  202. * 'length' > 0
  203. *
  204. * 'base' is a pointer to a sequence of 'length' bytes.
  205. *
  206. */
  207. void
  208. isc__buffer_invalidate(isc_buffer_t *b);
  209. /*
  210. * Make 'b' an invalid buffer.
  211. *
  212. * Requires:
  213. * 'b' is a valid buffer.
  214. *
  215. * Ensures:
  216. * If assertion checking is enabled, future attempts to use 'b' without
  217. * calling isc_buffer_init() on it will cause an assertion failure.
  218. */
  219. void
  220. isc__buffer_region(isc_buffer_t *b, isc_region_t *r);
  221. /*
  222. * Make 'r' refer to the region of 'b'.
  223. *
  224. * Requires:
  225. *
  226. * 'b' is a valid buffer.
  227. *
  228. * 'r' points to a region structure.
  229. */
  230. void
  231. isc__buffer_usedregion(isc_buffer_t *b, isc_region_t *r);
  232. /*
  233. * Make 'r' refer to the used region of 'b'.
  234. *
  235. * Requires:
  236. *
  237. * 'b' is a valid buffer.
  238. *
  239. * 'r' points to a region structure.
  240. */
  241. void
  242. isc__buffer_availableregion(isc_buffer_t *b, isc_region_t *r);
  243. /*
  244. * Make 'r' refer to the available region of 'b'.
  245. *
  246. * Requires:
  247. *
  248. * 'b' is a valid buffer.
  249. *
  250. * 'r' points to a region structure.
  251. */
  252. void
  253. isc__buffer_add(isc_buffer_t *b, unsigned int n);
  254. /*
  255. * Increase the 'used' region of 'b' by 'n' bytes.
  256. *
  257. * Requires:
  258. *
  259. * 'b' is a valid buffer
  260. *
  261. * used + n <= length
  262. *
  263. */
  264. void
  265. isc__buffer_subtract(isc_buffer_t *b, unsigned int n);
  266. /*
  267. * Decrease the 'used' region of 'b' by 'n' bytes.
  268. *
  269. * Requires:
  270. *
  271. * 'b' is a valid buffer
  272. *
  273. * used >= n
  274. *
  275. */
  276. void
  277. isc__buffer_clear(isc_buffer_t *b);
  278. /*
  279. * Make the used region empty.
  280. *
  281. * Requires:
  282. *
  283. * 'b' is a valid buffer
  284. *
  285. * Ensures:
  286. *
  287. * used = 0
  288. *
  289. */
  290. void
  291. isc__buffer_consumedregion(isc_buffer_t *b, isc_region_t *r);
  292. /*
  293. * Make 'r' refer to the consumed region of 'b'.
  294. *
  295. * Requires:
  296. *
  297. * 'b' is a valid buffer.
  298. *
  299. * 'r' points to a region structure.
  300. */
  301. void
  302. isc__buffer_remainingregion(isc_buffer_t *b, isc_region_t *r);
  303. /*
  304. * Make 'r' refer to the remaining region of 'b'.
  305. *
  306. * Requires:
  307. *
  308. * 'b' is a valid buffer.
  309. *
  310. * 'r' points to a region structure.
  311. */
  312. void
  313. isc__buffer_activeregion(isc_buffer_t *b, isc_region_t *r);
  314. /*
  315. * Make 'r' refer to the active region of 'b'.
  316. *
  317. * Requires:
  318. *
  319. * 'b' is a valid buffer.
  320. *
  321. * 'r' points to a region structure.
  322. */
  323. void
  324. isc__buffer_setactive(isc_buffer_t *b, unsigned int n);
  325. /*
  326. * Sets the end of the active region 'n' bytes after current.
  327. *
  328. * Requires:
  329. *
  330. * 'b' is a valid buffer.
  331. *
  332. * current + n <= used
  333. */
  334. void
  335. isc__buffer_first(isc_buffer_t *b);
  336. /*
  337. * Make the consumed region empty.
  338. *
  339. * Requires:
  340. *
  341. * 'b' is a valid buffer
  342. *
  343. * Ensures:
  344. *
  345. * current == 0
  346. *
  347. */
  348. void
  349. isc__buffer_forward(isc_buffer_t *b, unsigned int n);
  350. /*
  351. * Increase the 'consumed' region of 'b' by 'n' bytes.
  352. *
  353. * Requires:
  354. *
  355. * 'b' is a valid buffer
  356. *
  357. * current + n <= used
  358. *
  359. */
  360. void
  361. isc__buffer_back(isc_buffer_t *b, unsigned int n);
  362. /*
  363. * Decrease the 'consumed' region of 'b' by 'n' bytes.
  364. *
  365. * Requires:
  366. *
  367. * 'b' is a valid buffer
  368. *
  369. * n <= current
  370. *
  371. */
  372. void
  373. isc_buffer_compact(isc_buffer_t *b);
  374. /*
  375. * Compact the used region by moving the remaining region so it occurs
  376. * at the start of the buffer. The used region is shrunk by the size of
  377. * the consumed region, and the consumed region is then made empty.
  378. *
  379. * Requires:
  380. *
  381. * 'b' is a valid buffer
  382. *
  383. * Ensures:
  384. *
  385. * current == 0
  386. *
  387. * The size of the used region is now equal to the size of the remaining
  388. * region (as it was before the call). The contents of the used region
  389. * are those of the remaining region (as it was before the call).
  390. */
  391. isc_uint8_t
  392. isc_buffer_getuint8(isc_buffer_t *b);
  393. /*
  394. * Read an unsigned 8-bit integer from 'b' and return it.
  395. *
  396. * Requires:
  397. *
  398. * 'b' is a valid buffer.
  399. *
  400. * The length of the available region of 'b' is at least 1.
  401. *
  402. * Ensures:
  403. *
  404. * The current pointer in 'b' is advanced by 1.
  405. *
  406. * Returns:
  407. *
  408. * A 8-bit unsigned integer.
  409. */
  410. void
  411. isc__buffer_putuint8(isc_buffer_t *b, isc_uint8_t val);
  412. /*
  413. * Store an unsigned 8-bit integer from 'val' into 'b'.
  414. *
  415. * Requires:
  416. * 'b' is a valid buffer.
  417. *
  418. * The length of the unused region of 'b' is at least 1.
  419. *
  420. * Ensures:
  421. * The used pointer in 'b' is advanced by 1.
  422. */
  423. isc_uint16_t
  424. isc_buffer_getuint16(isc_buffer_t *b);
  425. /*
  426. * Read an unsigned 16-bit integer in network byte order from 'b', convert
  427. * it to host byte order, and return it.
  428. *
  429. * Requires:
  430. *
  431. * 'b' is a valid buffer.
  432. *
  433. * The length of the available region of 'b' is at least 2.
  434. *
  435. * Ensures:
  436. *
  437. * The current pointer in 'b' is advanced by 2.
  438. *
  439. * Returns:
  440. *
  441. * A 16-bit unsigned integer.
  442. */
  443. void
  444. isc__buffer_putuint16(isc_buffer_t *b, isc_uint16_t val);
  445. /*
  446. * Store an unsigned 16-bit integer in host byte order from 'val'
  447. * into 'b' in network byte order.
  448. *
  449. * Requires:
  450. * 'b' is a valid buffer.
  451. *
  452. * The length of the unused region of 'b' is at least 2.
  453. *
  454. * Ensures:
  455. * The used pointer in 'b' is advanced by 2.
  456. */
  457. isc_uint32_t
  458. isc_buffer_getuint32(isc_buffer_t *b);
  459. /*
  460. * Read an unsigned 32-bit integer in network byte order from 'b', convert
  461. * it to host byte order, and return it.
  462. *
  463. * Requires:
  464. *
  465. * 'b' is a valid buffer.
  466. *
  467. * The length of the available region of 'b' is at least 4.
  468. *
  469. * Ensures:
  470. *
  471. * The current pointer in 'b' is advanced by 4.
  472. *
  473. * Returns:
  474. *
  475. * A 32-bit unsigned integer.
  476. */
  477. void
  478. isc__buffer_putuint32(isc_buffer_t *b, isc_uint32_t val);
  479. /*
  480. * Store an unsigned 32-bit integer in host byte order from 'val'
  481. * into 'b' in network byte order.
  482. *
  483. * Requires:
  484. * 'b' is a valid buffer.
  485. *
  486. * The length of the unused region of 'b' is at least 4.
  487. *
  488. * Ensures:
  489. * The used pointer in 'b' is advanced by 4.
  490. */
  491. void
  492. isc__buffer_putmem(isc_buffer_t *b, const unsigned char *base,
  493. unsigned int length);
  494. /*
  495. * Copy 'length' bytes of memory at 'base' into 'b'.
  496. *
  497. * Requires:
  498. * 'b' is a valid buffer.
  499. *
  500. * 'base' points to 'length' bytes of valid memory.
  501. *
  502. */
  503. void
  504. isc__buffer_putstr(isc_buffer_t *b, const char *source);
  505. /*
  506. * Copy 'source' into 'b', not including terminating NUL.
  507. *
  508. * Requires:
  509. * 'b' is a valid buffer.
  510. *
  511. * 'source' to be a valid NULL terminated string.
  512. *
  513. * strlen(source) <= isc_buffer_available(b)
  514. */
  515. isc_result_t
  516. isc_buffer_copyregion(isc_buffer_t *b, const isc_region_t *r);
  517. /*
  518. * Copy the contents of 'r' into 'b'.
  519. *
  520. * Requires:
  521. * 'b' is a valid buffer.
  522. *
  523. * 'r' is a valid region.
  524. *
  525. * Returns:
  526. *
  527. * ISC_R_SUCCESS
  528. * ISC_R_NOSPACE The available region of 'b' is not
  529. * big enough.
  530. */
  531. ISC_LANG_ENDDECLS
  532. /*
  533. * Inline macro versions of the functions. These should never be called
  534. * directly by an application, but will be used by the functions within
  535. * buffer.c. The callers should always use "isc_buffer_*()" names, never
  536. * ones beginning with "isc__"
  537. */
  538. /*
  539. * XXXDCL Something more could be done with initializing buffers that
  540. * point to const data. For example, a new function, isc_buffer_initconst,
  541. * could be used, and a new boolean flag in the buffer structure could
  542. * indicate whether the buffer was initialized with that function.
  543. * (isc_bufer_init itself would be reprototyped to *not* have its "base"
  544. * parameter be const.) Then if the boolean were true, the isc_buffer_put*
  545. * functions could assert a contractual requirement for a non-const buffer.
  546. * One drawback is that the isc_buffer_* functions (macros) that return
  547. * pointers would still need to return non-const pointers to avoid compiler
  548. * warnings, so it would be up to code that uses them to have to deal
  549. * with the possibility that the buffer was initialized as const --
  550. * a problem that they *already* have to deal with but have absolutely
  551. * no ability to. With a new isc_buffer_isconst() function returning
  552. * true/false, they could at least assert a contractual requirement for
  553. * non-const buffers when needed.
  554. */
  555. #define ISC__BUFFER_INIT(_b, _base, _length) \
  556. do { \
  557. union { \
  558. const void * konst; \
  559. void * var; \
  560. } _u; \
  561. _u.konst = (_base); \
  562. (_b)->base = _u.var; \
  563. (_b)->length = (_length); \
  564. (_b)->used = 0; \
  565. (_b)->current = 0; \
  566. (_b)->active = 0; \
  567. (_b)->mctx = NULL; \
  568. ISC_LINK_INIT(_b, link); \
  569. (_b)->magic = ISC_BUFFER_MAGIC; \
  570. } while (0)
  571. #define ISC__BUFFER_INVALIDATE(_b) \
  572. do { \
  573. (_b)->magic = 0; \
  574. (_b)->base = NULL; \
  575. (_b)->length = 0; \
  576. (_b)->used = 0; \
  577. (_b)->current = 0; \
  578. (_b)->active = 0; \
  579. } while (0)
  580. #define ISC__BUFFER_REGION(_b, _r) \
  581. do { \
  582. (_r)->base = (_b)->base; \
  583. (_r)->length = (_b)->length; \
  584. } while (0)
  585. #define ISC__BUFFER_USEDREGION(_b, _r) \
  586. do { \
  587. (_r)->base = (_b)->base; \
  588. (_r)->length = (_b)->used; \
  589. } while (0)
  590. #define ISC__BUFFER_AVAILABLEREGION(_b, _r) \
  591. do { \
  592. (_r)->base = isc_buffer_used(_b); \
  593. (_r)->length = isc_buffer_availablelength(_b); \
  594. } while (0)
  595. #define ISC__BUFFER_ADD(_b, _n) \
  596. do { \
  597. (_b)->used += (_n); \
  598. } while (0)
  599. #define ISC__BUFFER_SUBTRACT(_b, _n) \
  600. do { \
  601. (_b)->used -= (_n); \
  602. if ((_b)->current > (_b)->used) \
  603. (_b)->current = (_b)->used; \
  604. if ((_b)->active > (_b)->used) \
  605. (_b)->active = (_b)->used; \
  606. } while (0)
  607. #define ISC__BUFFER_CLEAR(_b) \
  608. do { \
  609. (_b)->used = 0; \
  610. (_b)->current = 0; \
  611. (_b)->active = 0; \
  612. } while (0)
  613. #define ISC__BUFFER_CONSUMEDREGION(_b, _r) \
  614. do { \
  615. (_r)->base = (_b)->base; \
  616. (_r)->length = (_b)->current; \
  617. } while (0)
  618. #define ISC__BUFFER_REMAININGREGION(_b, _r) \
  619. do { \
  620. (_r)->base = isc_buffer_current(_b); \
  621. (_r)->length = isc_buffer_remaininglength(_b); \
  622. } while (0)
  623. #define ISC__BUFFER_ACTIVEREGION(_b, _r) \
  624. do { \
  625. if ((_b)->current < (_b)->active) { \
  626. (_r)->base = isc_buffer_current(_b); \
  627. (_r)->length = isc_buffer_activelength(_b); \
  628. } else { \
  629. (_r)->base = NULL; \
  630. (_r)->length = 0; \
  631. } \
  632. } while (0)
  633. #define ISC__BUFFER_SETACTIVE(_b, _n) \
  634. do { \
  635. (_b)->active = (_b)->current + (_n); \
  636. } while (0)
  637. #define ISC__BUFFER_FIRST(_b) \
  638. do { \
  639. (_b)->current = 0; \
  640. } while (0)
  641. #define ISC__BUFFER_FORWARD(_b, _n) \
  642. do { \
  643. (_b)->current += (_n); \
  644. } while (0)
  645. #define ISC__BUFFER_BACK(_b, _n) \
  646. do { \
  647. (_b)->current -= (_n); \
  648. } while (0)
  649. #define ISC__BUFFER_PUTMEM(_b, _base, _length) \
  650. do { \
  651. memcpy(isc_buffer_used(_b), (_base), (_length)); \
  652. (_b)->used += (_length); \
  653. } while (0)
  654. #define ISC__BUFFER_PUTSTR(_b, _source) \
  655. do { \
  656. unsigned int _length; \
  657. unsigned char *_cp; \
  658. _length = strlen(_source); \
  659. _cp = isc_buffer_used(_b); \
  660. memcpy(_cp, (_source), _length); \
  661. (_b)->used += (_length); \
  662. } while (0)
  663. #define ISC__BUFFER_PUTUINT8(_b, _val) \
  664. do { \
  665. unsigned char *_cp; \
  666. isc_uint8_t _val2 = (_val); \
  667. _cp = isc_buffer_used(_b); \
  668. (_b)->used++; \
  669. _cp[0] = _val2 & 0x00ff; \
  670. } while (0)
  671. #define ISC__BUFFER_PUTUINT16(_b, _val) \
  672. do { \
  673. unsigned char *_cp; \
  674. isc_uint16_t _val2 = (_val); \
  675. _cp = isc_buffer_used(_b); \
  676. (_b)->used += 2; \
  677. _cp[0] = (unsigned char)((_val2 & 0xff00U) >> 8); \
  678. _cp[1] = (unsigned char)(_val2 & 0x00ffU); \
  679. } while (0)
  680. #define ISC__BUFFER_PUTUINT32(_b, _val) \
  681. do { \
  682. unsigned char *_cp; \
  683. isc_uint32_t _val2 = (_val); \
  684. _cp = isc_buffer_used(_b); \
  685. (_b)->used += 4; \
  686. _cp[0] = (unsigned char)((_val2 & 0xff000000) >> 24); \
  687. _cp[1] = (unsigned char)((_val2 & 0x00ff0000) >> 16); \
  688. _cp[2] = (unsigned char)((_val2 & 0x0000ff00) >> 8); \
  689. _cp[3] = (unsigned char)((_val2 & 0x000000ff)); \
  690. } while (0)
  691. #if defined(ISC_BUFFER_USEINLINE)
  692. #define isc_buffer_init ISC__BUFFER_INIT
  693. #define isc_buffer_invalidate ISC__BUFFER_INVALIDATE
  694. #define isc_buffer_region ISC__BUFFER_REGION
  695. #define isc_buffer_usedregion ISC__BUFFER_USEDREGION
  696. #define isc_buffer_availableregion ISC__BUFFER_AVAILABLEREGION
  697. #define isc_buffer_add ISC__BUFFER_ADD
  698. #define isc_buffer_subtract ISC__BUFFER_SUBTRACT
  699. #define isc_buffer_clear ISC__BUFFER_CLEAR
  700. #define isc_buffer_consumedregion ISC__BUFFER_CONSUMEDREGION
  701. #define isc_buffer_remainingregion ISC__BUFFER_REMAININGREGION
  702. #define isc_buffer_activeregion ISC__BUFFER_ACTIVEREGION
  703. #define isc_buffer_setactive ISC__BUFFER_SETACTIVE
  704. #define isc_buffer_first ISC__BUFFER_FIRST
  705. #define isc_buffer_forward ISC__BUFFER_FORWARD
  706. #define isc_buffer_back ISC__BUFFER_BACK
  707. #define isc_buffer_putmem ISC__BUFFER_PUTMEM
  708. #define isc_buffer_putstr ISC__BUFFER_PUTSTR
  709. #define isc_buffer_putuint8 ISC__BUFFER_PUTUINT8
  710. #define isc_buffer_putuint16 ISC__BUFFER_PUTUINT16
  711. #define isc_buffer_putuint32 ISC__BUFFER_PUTUINT32
  712. #else
  713. #define isc_buffer_init isc__buffer_init
  714. #define isc_buffer_invalidate isc__buffer_invalidate
  715. #define isc_buffer_region isc__buffer_region
  716. #define isc_buffer_usedregion isc__buffer_usedregion
  717. #define isc_buffer_availableregion isc__buffer_availableregion
  718. #define isc_buffer_add isc__buffer_add
  719. #define isc_buffer_subtract isc__buffer_subtract
  720. #define isc_buffer_clear isc__buffer_clear
  721. #define isc_buffer_consumedregion isc__buffer_consumedregion
  722. #define isc_buffer_remainingregion isc__buffer_remainingregion
  723. #define isc_buffer_activeregion isc__buffer_activeregion
  724. #define isc_buffer_setactive isc__buffer_setactive
  725. #define isc_buffer_first isc__buffer_first
  726. #define isc_buffer_forward isc__buffer_forward
  727. #define isc_buffer_back isc__buffer_back
  728. #define isc_buffer_putmem isc__buffer_putmem
  729. #define isc_buffer_putstr isc__buffer_putstr
  730. #define isc_buffer_putuint8 isc__buffer_putuint8
  731. #define isc_buffer_putuint16 isc__buffer_putuint16
  732. #define isc_buffer_putuint32 isc__buffer_putuint32
  733. #endif
  734. #endif /* ISC_BUFFER_H */