OSDN Git Service

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