xdr_rec.c 17 KB

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