xdr_rec.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  1. /*
  2. * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  3. * unrestricted use provided that this legend is included on all tape
  4. * media and as a part of the software program in whole or part. Users
  5. * may copy or modify Sun RPC without charge, but are not authorized
  6. * to license or distribute it to anyone else except as part of a product or
  7. * program developed by the user.
  8. *
  9. * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  10. * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  11. * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  12. *
  13. * Sun RPC is provided with no support and without any obligation on the
  14. * part of Sun Microsystems, Inc. to assist in its use, correction,
  15. * modification or enhancement.
  16. *
  17. * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  18. * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  19. * OR ANY PART THEREOF.
  20. *
  21. * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  22. * or profits or other special, indirect and consequential damages, even if
  23. * Sun has been advised of the possibility of such damages.
  24. *
  25. * Sun Microsystems, Inc.
  26. * 2550 Garcia Avenue
  27. * Mountain View, California 94043
  28. */
  29. /*
  30. * xdr_rec.c, Implements TCP/IP based XDR streams with a "record marking"
  31. * layer above tcp (for rpc's use).
  32. *
  33. * Copyright (C) 1984, Sun Microsystems, Inc.
  34. *
  35. * These routines interface XDRSTREAMS to a tcp/ip connection.
  36. * There is a record marking layer between the xdr stream
  37. * and the tcp transport level. A record is composed on one or more
  38. * record fragments. A record fragment is a thirty-two bit header followed
  39. * by n bytes of data, where n is contained in the header. The header
  40. * is represented as a htonl(u_long). The high order bit encodes
  41. * whether or not the fragment is the last fragment of the record
  42. * (1 => fragment is last, 0 => more fragments to follow.
  43. * The other 31 bits encode the byte length of the fragment.
  44. */
  45. #include <stdio.h>
  46. #include <string.h>
  47. #include <unistd.h>
  48. #include <rpc/rpc.h>
  49. #ifdef USE_IN_LIBIO
  50. # include <wchar.h>
  51. # include <libio/iolibio.h>
  52. # define fputs(s, f) _IO_fputs (s, f)
  53. #endif
  54. static bool_t xdrrec_getbytes (XDR *, caddr_t, u_int);
  55. static bool_t xdrrec_putbytes (XDR *, const char *, u_int);
  56. static bool_t xdrrec_getint32 (XDR *, int32_t *);
  57. static bool_t xdrrec_putint32 (XDR *, const int32_t *);
  58. #if ULONG_MAX != 0xffffffff
  59. static bool_t xdrrec_getlong (XDR *, long *);
  60. static bool_t xdrrec_putlong (XDR *, const long *);
  61. #endif
  62. static u_int xdrrec_getpos (const XDR *);
  63. static bool_t xdrrec_setpos (XDR *, u_int);
  64. static int32_t *xdrrec_inline (XDR *, u_int);
  65. static void xdrrec_destroy (XDR *);
  66. static const struct xdr_ops xdrrec_ops = {
  67. #if ULONG_MAX == 0xffffffff
  68. (bool_t (*)(XDR *, long *)) xdrrec_getint32,
  69. (bool_t (*)(XDR *, const long *)) xdrrec_putint32,
  70. #else
  71. xdrrec_getlong,
  72. xdrrec_putlong,
  73. #endif
  74. xdrrec_getbytes,
  75. xdrrec_putbytes,
  76. xdrrec_getpos,
  77. xdrrec_setpos,
  78. xdrrec_inline,
  79. xdrrec_destroy,
  80. xdrrec_getint32,
  81. xdrrec_putint32
  82. };
  83. /*
  84. * A record is composed of one or more record fragments.
  85. * A record fragment is a two-byte header followed by zero to
  86. * 2**32-1 bytes. The header is treated as a long unsigned and is
  87. * encode/decoded to the network via htonl/ntohl. The low order 31 bits
  88. * are a byte count of the fragment. The highest order bit is a boolean:
  89. * 1 => this fragment is the last fragment of the record,
  90. * 0 => this fragment is followed by more fragment(s).
  91. *
  92. * The fragment/record machinery is not general; it is constructed to
  93. * meet the needs of xdr and rpc based on tcp.
  94. */
  95. #define LAST_FRAG (1UL << 31)
  96. typedef struct rec_strm
  97. {
  98. caddr_t tcp_handle;
  99. caddr_t the_buffer;
  100. /*
  101. * out-going bits
  102. */
  103. int (*writeit) (char *, char *, int);
  104. caddr_t out_base; /* output buffer (points to frag header) */
  105. caddr_t out_finger; /* next output position */
  106. caddr_t out_boundry; /* data cannot up to this address */
  107. u_int32_t *frag_header; /* beginning of curren fragment */
  108. bool_t frag_sent; /* true if buffer sent in middle of record */
  109. /*
  110. * in-coming bits
  111. */
  112. int (*readit) (char *, char *, int);
  113. u_long in_size; /* fixed size of the input buffer */
  114. caddr_t in_base;
  115. caddr_t in_finger; /* location of next byte to be had */
  116. caddr_t in_boundry; /* can read up to this location */
  117. long fbtbc; /* fragment bytes to be consumed */
  118. bool_t last_frag;
  119. u_int sendsize;
  120. u_int recvsize;
  121. }
  122. RECSTREAM;
  123. static u_int fix_buf_size (u_int) internal_function;
  124. static bool_t skip_input_bytes (RECSTREAM *, long) internal_function;
  125. static bool_t flush_out (RECSTREAM *, bool_t) internal_function;
  126. static bool_t set_input_fragment (RECSTREAM *) internal_function;
  127. static bool_t get_input_bytes (RECSTREAM *, caddr_t, int) internal_function;
  128. /*
  129. * Create an xdr handle for xdrrec
  130. * xdrrec_create fills in xdrs. Sendsize and recvsize are
  131. * send and recv buffer sizes (0 => use default).
  132. * tcp_handle is an opaque handle that is passed as the first parameter to
  133. * the procedures readit and writeit. Readit and writeit are read and
  134. * write respectively. They are like the system
  135. * calls expect that they take an opaque handle rather than an fd.
  136. */
  137. void
  138. xdrrec_create (XDR *xdrs, u_int sendsize,
  139. u_int recvsize, caddr_t tcp_handle,
  140. int (*readit) (char *, char *, int),
  141. int (*writeit) (char *, char *, int))
  142. {
  143. RECSTREAM *rstrm = (RECSTREAM *) mem_alloc (sizeof (RECSTREAM));
  144. caddr_t tmp;
  145. char *buf;
  146. sendsize = fix_buf_size (sendsize);
  147. recvsize = fix_buf_size (recvsize);
  148. buf = mem_alloc (sendsize + recvsize + BYTES_PER_XDR_UNIT);
  149. if (rstrm == NULL || buf == NULL)
  150. {
  151. #ifdef USE_IN_LIBIO
  152. if (_IO_fwide (stderr, 0) > 0)
  153. (void) fwprintf (stderr, L"%s", _("xdrrec_create: out of memory\n"));
  154. else
  155. #endif
  156. (void) fputs (_("xdrrec_create: out of memory\n"), stderr);
  157. mem_free (rstrm, sizeof (RECSTREAM));
  158. mem_free (buf, sendsize + recvsize + BYTES_PER_XDR_UNIT);
  159. /*
  160. * This is bad. Should rework xdrrec_create to
  161. * return a handle, and in this case return NULL
  162. */
  163. return;
  164. }
  165. /*
  166. * adjust sizes and allocate buffer quad byte aligned
  167. */
  168. rstrm->sendsize = sendsize;
  169. rstrm->recvsize = recvsize;
  170. rstrm->the_buffer = buf;
  171. tmp = rstrm->the_buffer;
  172. if ((size_t)tmp % BYTES_PER_XDR_UNIT)
  173. tmp += BYTES_PER_XDR_UNIT - (size_t)tmp % BYTES_PER_XDR_UNIT;
  174. rstrm->out_base = tmp;
  175. rstrm->in_base = tmp + sendsize;
  176. /*
  177. * now the rest ...
  178. */
  179. /* We have to add the const since the `struct xdr_ops' in `struct XDR'
  180. is not `const'. */
  181. xdrs->x_ops = (struct xdr_ops *) &xdrrec_ops;
  182. xdrs->x_private = (caddr_t) rstrm;
  183. rstrm->tcp_handle = tcp_handle;
  184. rstrm->readit = readit;
  185. rstrm->writeit = writeit;
  186. rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
  187. rstrm->frag_header = (u_int32_t *) rstrm->out_base;
  188. rstrm->out_finger += 4;
  189. rstrm->out_boundry += sendsize;
  190. rstrm->frag_sent = FALSE;
  191. rstrm->in_size = recvsize;
  192. rstrm->in_boundry = rstrm->in_base;
  193. rstrm->in_finger = (rstrm->in_boundry += recvsize);
  194. rstrm->fbtbc = 0;
  195. rstrm->last_frag = TRUE;
  196. }
  197. libc_hidden_def(xdrrec_create)
  198. /*
  199. * The routines defined below are the xdr ops which will go into the
  200. * xdr handle filled in by xdrrec_create.
  201. */
  202. static bool_t
  203. xdrrec_getint32 (XDR *xdrs, int32_t *ip)
  204. {
  205. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  206. int32_t *bufip = (int32_t *) rstrm->in_finger;
  207. int32_t mylong;
  208. /* first try the inline, fast case */
  209. if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
  210. rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT)
  211. {
  212. *ip = ntohl (*bufip);
  213. rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
  214. rstrm->in_finger += BYTES_PER_XDR_UNIT;
  215. }
  216. else
  217. {
  218. if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong,
  219. BYTES_PER_XDR_UNIT))
  220. return FALSE;
  221. *ip = ntohl (mylong);
  222. }
  223. return TRUE;
  224. }
  225. #if ULONG_MAX != 0xffffffff
  226. static bool_t
  227. xdrrec_getlong (XDR *xdrs, long *lp)
  228. {
  229. int32_t v;
  230. bool_t r = xdrrec_getint32 (xdrs, &v);
  231. *lp = v;
  232. return r;
  233. }
  234. #endif
  235. static bool_t
  236. xdrrec_putint32 (XDR *xdrs, const int32_t *ip)
  237. {
  238. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  239. int32_t *dest_ip = (int32_t *) rstrm->out_finger;
  240. if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
  241. {
  242. /*
  243. * this case should almost never happen so the code is
  244. * inefficient
  245. */
  246. rstrm->out_finger -= BYTES_PER_XDR_UNIT;
  247. rstrm->frag_sent = TRUE;
  248. if (!flush_out (rstrm, FALSE))
  249. return FALSE;
  250. dest_ip = (int32_t *) rstrm->out_finger;
  251. rstrm->out_finger += BYTES_PER_XDR_UNIT;
  252. }
  253. *dest_ip = htonl (*ip);
  254. return TRUE;
  255. }
  256. #if ULONG_MAX != 0xffffffff
  257. static bool_t
  258. xdrrec_putlong (XDR *xdrs, const long *lp)
  259. {
  260. int32_t v = *lp;
  261. return xdrrec_putint32 (xdrs, &v);
  262. }
  263. #endif
  264. static bool_t /* must manage buffers, fragments, and records */
  265. xdrrec_getbytes (XDR *xdrs, caddr_t addr, u_int len)
  266. {
  267. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  268. u_int current;
  269. while (len > 0)
  270. {
  271. current = rstrm->fbtbc;
  272. if (current == 0)
  273. {
  274. if (rstrm->last_frag)
  275. return FALSE;
  276. if (!set_input_fragment (rstrm))
  277. return FALSE;
  278. continue;
  279. }
  280. current = (len < current) ? len : current;
  281. if (!get_input_bytes (rstrm, addr, current))
  282. return FALSE;
  283. addr += current;
  284. rstrm->fbtbc -= current;
  285. len -= current;
  286. }
  287. return TRUE;
  288. }
  289. static bool_t
  290. xdrrec_putbytes (XDR *xdrs, const char *addr, u_int len)
  291. {
  292. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  293. u_int current;
  294. while (len > 0)
  295. {
  296. current = rstrm->out_boundry - rstrm->out_finger;
  297. current = (len < current) ? len : current;
  298. memcpy (rstrm->out_finger, addr, current);
  299. rstrm->out_finger += current;
  300. addr += current;
  301. len -= current;
  302. if (rstrm->out_finger == rstrm->out_boundry && len > 0)
  303. {
  304. rstrm->frag_sent = TRUE;
  305. if (!flush_out (rstrm, FALSE))
  306. return FALSE;
  307. }
  308. }
  309. return TRUE;
  310. }
  311. static u_int
  312. xdrrec_getpos (const XDR *xdrs)
  313. {
  314. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  315. long pos;
  316. pos = lseek ((int) (long) rstrm->tcp_handle, (long) 0, 1);
  317. if (pos != -1)
  318. switch (xdrs->x_op)
  319. {
  320. case XDR_ENCODE:
  321. pos += rstrm->out_finger - rstrm->out_base;
  322. break;
  323. case XDR_DECODE:
  324. pos -= rstrm->in_boundry - rstrm->in_finger;
  325. break;
  326. default:
  327. pos = (u_int) - 1;
  328. break;
  329. }
  330. return (u_int) pos;
  331. }
  332. static bool_t
  333. xdrrec_setpos (XDR *xdrs, u_int pos)
  334. {
  335. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  336. u_int currpos = xdrrec_getpos (xdrs);
  337. int delta = currpos - pos;
  338. caddr_t newpos;
  339. if ((int) currpos != -1)
  340. switch (xdrs->x_op)
  341. {
  342. case XDR_ENCODE:
  343. newpos = rstrm->out_finger - delta;
  344. if (newpos > (caddr_t) rstrm->frag_header &&
  345. newpos < rstrm->out_boundry)
  346. {
  347. rstrm->out_finger = newpos;
  348. return TRUE;
  349. }
  350. break;
  351. case XDR_DECODE:
  352. newpos = rstrm->in_finger - delta;
  353. if ((delta < (int) (rstrm->fbtbc)) &&
  354. (newpos <= rstrm->in_boundry) &&
  355. (newpos >= rstrm->in_base))
  356. {
  357. rstrm->in_finger = newpos;
  358. rstrm->fbtbc -= delta;
  359. return TRUE;
  360. }
  361. break;
  362. default:
  363. break;
  364. }
  365. return FALSE;
  366. }
  367. static int32_t *
  368. xdrrec_inline (XDR *xdrs, u_int len)
  369. {
  370. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  371. int32_t *buf = NULL;
  372. switch (xdrs->x_op)
  373. {
  374. case XDR_ENCODE:
  375. if ((rstrm->out_finger + len) <= rstrm->out_boundry)
  376. {
  377. buf = (int32_t *) rstrm->out_finger;
  378. rstrm->out_finger += len;
  379. }
  380. break;
  381. case XDR_DECODE:
  382. if ((len <= rstrm->fbtbc) &&
  383. ((rstrm->in_finger + len) <= rstrm->in_boundry))
  384. {
  385. buf = (int32_t *) rstrm->in_finger;
  386. rstrm->fbtbc -= len;
  387. rstrm->in_finger += len;
  388. }
  389. break;
  390. default:
  391. break;
  392. }
  393. return buf;
  394. }
  395. static void
  396. xdrrec_destroy (XDR *xdrs)
  397. {
  398. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  399. mem_free (rstrm->the_buffer,
  400. rstrm->sendsize + rstrm->recvsize + BYTES_PER_XDR_UNIT);
  401. mem_free ((caddr_t) rstrm, sizeof (RECSTREAM));
  402. }
  403. /*
  404. * Exported routines to manage xdr records
  405. */
  406. /*
  407. * Before reading (deserializing from the stream, one should always call
  408. * this procedure to guarantee proper record alignment.
  409. */
  410. bool_t
  411. xdrrec_skiprecord (XDR *xdrs)
  412. {
  413. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  414. while (rstrm->fbtbc > 0 || (!rstrm->last_frag))
  415. {
  416. if (!skip_input_bytes (rstrm, rstrm->fbtbc))
  417. return FALSE;
  418. rstrm->fbtbc = 0;
  419. if ((!rstrm->last_frag) && (!set_input_fragment (rstrm)))
  420. return FALSE;
  421. }
  422. rstrm->last_frag = FALSE;
  423. return TRUE;
  424. }
  425. libc_hidden_def(xdrrec_skiprecord)
  426. /*
  427. * Lookahead function.
  428. * Returns TRUE iff there is no more input in the buffer
  429. * after consuming the rest of the current record.
  430. */
  431. bool_t
  432. xdrrec_eof (XDR *xdrs)
  433. {
  434. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  435. while (rstrm->fbtbc > 0 || (!rstrm->last_frag))
  436. {
  437. if (!skip_input_bytes (rstrm, rstrm->fbtbc))
  438. return TRUE;
  439. rstrm->fbtbc = 0;
  440. if ((!rstrm->last_frag) && (!set_input_fragment (rstrm)))
  441. return TRUE;
  442. }
  443. if (rstrm->in_finger == rstrm->in_boundry)
  444. return TRUE;
  445. return FALSE;
  446. }
  447. libc_hidden_def(xdrrec_eof)
  448. /*
  449. * The client must tell the package when an end-of-record has occurred.
  450. * The second parameter tells whether the record should be flushed to the
  451. * (output) tcp stream. (This lets the package support batched or
  452. * pipelined procedure calls.) TRUE => immediate flush to tcp connection.
  453. */
  454. bool_t
  455. xdrrec_endofrecord (XDR *xdrs, bool_t sendnow)
  456. {
  457. RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
  458. u_long len; /* fragment length */
  459. if (sendnow || rstrm->frag_sent
  460. || rstrm->out_finger + BYTES_PER_XDR_UNIT >= rstrm->out_boundry)
  461. {
  462. rstrm->frag_sent = FALSE;
  463. return flush_out (rstrm, TRUE);
  464. }
  465. len = (rstrm->out_finger - (char *) rstrm->frag_header
  466. - BYTES_PER_XDR_UNIT);
  467. *rstrm->frag_header = htonl ((u_long) len | LAST_FRAG);
  468. rstrm->frag_header = (u_int32_t *) rstrm->out_finger;
  469. rstrm->out_finger += BYTES_PER_XDR_UNIT;
  470. return TRUE;
  471. }
  472. libc_hidden_def(xdrrec_endofrecord)
  473. /*
  474. * Internal useful routines
  475. */
  476. static bool_t
  477. internal_function
  478. flush_out (RECSTREAM *rstrm, bool_t eor)
  479. {
  480. u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
  481. u_long len = (rstrm->out_finger - (char *) rstrm->frag_header
  482. - BYTES_PER_XDR_UNIT);
  483. *rstrm->frag_header = htonl (len | eormask);
  484. len = rstrm->out_finger - rstrm->out_base;
  485. if ((*(rstrm->writeit)) (rstrm->tcp_handle, rstrm->out_base, (int) len)
  486. != (int) len)
  487. return FALSE;
  488. rstrm->frag_header = (u_int32_t *) rstrm->out_base;
  489. rstrm->out_finger = (caddr_t) rstrm->out_base + BYTES_PER_XDR_UNIT;
  490. return TRUE;
  491. }
  492. static bool_t /* knows nothing about records! Only about input buffers */
  493. fill_input_buf (RECSTREAM *rstrm)
  494. {
  495. caddr_t where;
  496. size_t i;
  497. int len;
  498. where = rstrm->in_base;
  499. i = (size_t) rstrm->in_boundry % BYTES_PER_XDR_UNIT;
  500. where += i;
  501. len = rstrm->in_size - i;
  502. if ((len = (*(rstrm->readit)) (rstrm->tcp_handle, where, len)) == -1)
  503. return FALSE;
  504. rstrm->in_finger = where;
  505. where += len;
  506. rstrm->in_boundry = where;
  507. return TRUE;
  508. }
  509. static bool_t /* knows nothing about records! Only about input buffers */
  510. internal_function
  511. get_input_bytes (RECSTREAM *rstrm, caddr_t addr, int len)
  512. {
  513. int current;
  514. while (len > 0)
  515. {
  516. current = rstrm->in_boundry - rstrm->in_finger;
  517. if (current == 0)
  518. {
  519. if (!fill_input_buf (rstrm))
  520. return FALSE;
  521. continue;
  522. }
  523. current = (len < current) ? len : current;
  524. memcpy (addr, rstrm->in_finger, current);
  525. rstrm->in_finger += current;
  526. addr += current;
  527. len -= current;
  528. }
  529. return TRUE;
  530. }
  531. static bool_t /* next two bytes of the input stream are treated as a header */
  532. internal_function
  533. set_input_fragment (RECSTREAM *rstrm)
  534. {
  535. uint32_t header;
  536. if (! get_input_bytes (rstrm, (caddr_t)&header, BYTES_PER_XDR_UNIT))
  537. return FALSE;
  538. header = ntohl (header);
  539. rstrm->last_frag = ((header & LAST_FRAG) == 0) ? FALSE : TRUE;
  540. /*
  541. * Sanity check. Try not to accept wildly incorrect fragment
  542. * sizes. Unfortunately, only a size of zero can be identified as
  543. * 'wildely incorrect', and this only, if it is not the last
  544. * fragment of a message. Ridiculously large fragment sizes may look
  545. * wrong, but we don't have any way to be certain that they aren't
  546. * what the client actually intended to send us. Many existing RPC
  547. * implementations may sent a fragment of size zero as the last
  548. * fragment of a message.
  549. */
  550. if (header == 0)
  551. return FALSE;
  552. rstrm->fbtbc = header & ~LAST_FRAG;
  553. return TRUE;
  554. }
  555. static bool_t /* consumes input bytes; knows nothing about records! */
  556. internal_function
  557. skip_input_bytes (RECSTREAM *rstrm, long cnt)
  558. {
  559. int current;
  560. while (cnt > 0)
  561. {
  562. current = rstrm->in_boundry - rstrm->in_finger;
  563. if (current == 0)
  564. {
  565. if (!fill_input_buf (rstrm))
  566. return FALSE;
  567. continue;
  568. }
  569. current = (cnt < current) ? cnt : current;
  570. rstrm->in_finger += current;
  571. cnt -= current;
  572. }
  573. return TRUE;
  574. }
  575. static u_int
  576. internal_function
  577. fix_buf_size (u_int s)
  578. {
  579. if (s < 100)
  580. s = 4000;
  581. return RNDUP (s);
  582. }