home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2002 November / SGI IRIX Base Documentation 2002 November.iso / usr / share / catman / p_man / cat3s / setbuf.z / setbuf
Encoding:
Text File  |  2002-10-03  |  8.4 KB  |  199 lines

  1.  
  2.  
  3.  
  4. SSSSEEEETTTTBBBBUUUUFFFF((((3333FFFF))))                                                          SSSSEEEETTTTBBBBUUUUFFFF((((3333FFFF))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      setbuf, setvbuf, setbuffer, setlinebuf - assign buffering to a stream
  10.      logical unit
  11.  
  12. FFFFOOOORRRRTTTTRRRRAAAANNNN SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  13.      ####iiiinnnncccclllluuuuddddeeee <<<<ssssttttddddiiiioooo....hhhh>>>>
  14.  
  15.      cccchhhhaaaarrrraaaacccctttteeeerrrr ****((((BBBBUUUUFFFFSSSSIIIIZZZZ++++8888)))) bbbbuuuuffff
  16.      iiiinnnntttteeeeggggeeeerrrr ttttyyyyppppeeee,,,, ssssiiiizzzzeeee,,,, sssseeeettttbbbbuuuuffff,,,, sssseeeettttvvvvbbbbuuuuffff,,,, sssseeeettttbbbbuuuuffffffffeeeerrrr,,,,
  17.  
  18.      sssseeeettttbbbbuuuuffff ((((lllluuuunnnn,,,, bbbbuuuuffff))))
  19.  
  20.      sssseeeettttvvvvbbbbuuuuffff ((((lllluuuunnnn,,,, bbbbuuuuffff,,,, ssssiiiizzzzeeee))))
  21.  
  22.      sssseeeettttbbbbuuuuffffffffeeeerrrr ((((lllluuuunnnn,,,, bbbbuuuuffff,,,, ssssiiiizzzzeeee))))
  23.  
  24.      sssseeeettttlllliiiinnnneeeebbbbuuuuffff ((((lllluuuunnnn))))
  25.  
  26. CCCC SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  27.      ####iiiinnnncccclllluuuuddddeeee <<<<ssssttttddddiiiioooo....hhhh>>>>
  28.  
  29.      vvvvooooiiiidddd sssseeeettttbbbbuuuuffff ((((FFFFIIIILLLLEEEE ****ssssttttrrrreeeeaaaammmm,,,, cccchhhhaaaarrrr ****bbbbuuuuffff))));;;;
  30.  
  31.      iiiinnnntttt sssseeeettttvvvvbbbbuuuuffff ((((FFFFIIIILLLLEEEE ****ssssttttrrrreeeeaaaammmm,,,, cccchhhhaaaarrrr ****bbbbuuuuffff,,,, iiiinnnntttt ttttyyyyppppeeee,,,, ssssiiiizzzzeeee____tttt ssssiiiizzzzeeee))));;;;
  32.  
  33.      iiiinnnntttt sssseeeettttbbbbuuuuffffffffeeeerrrr ((((FFFFIIIILLLLEEEE ****ssssttttrrrreeeeaaaammmm,,,, cccchhhhaaaarrrr ****bbbbuuuuffff,,,, iiiinnnntttt ssssiiiizzzzeeee))));;;;
  34.  
  35.      iiiinnnntttt sssseeeettttlllliiiinnnneeeebbbbuuuuffff ((((FFFFIIIILLLLEEEE ****ssssttttrrrreeeeaaaammmm))));;;;
  36.  
  37. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  38.      The three types of buffering available are unbuffered, fully buffered,
  39.      and line buffered.  When an output stream unit is unbuffered, information
  40.      appears on the destination file or terminal as soon as written; when it
  41.      is fully buffered many characters are saved up and written as a block;
  42.      when it is line buffered characters are saved up until a newline is
  43.      encountered or input is read from stdin.  _F_f_l_u_s_h(3S) _f_l_u_s_h(3F) may be
  44.      used to force the block out early.  By default, output to a terminal is
  45.      line buffered and all other input/output is fully buffered.
  46.  
  47.      _S_e_t_b_u_f may be used after a stream unit has been opened but before it is
  48.      read or written.  It causes the array pointed to by _b_u_f to be used
  49.      instead of an automatically allocated buffer.  If _b_u_f is the NULL pointer
  50.      input/output will be completely unbuffered.  If _b_u_f is not the NULL
  51.      pointer and the indicated _s_t_r_e_a_m _l_u_n is open to a terminal, output will
  52.      be line buffered.
  53.  
  54.      A constant BBBBUUUUFFFFSSSSIIIIZZZZ,,,, defined in the <<<<ssssttttddddiiiioooo....hhhh>>>> header file, indicates the
  55.      assumed minimum length of _b_u_f.  It is wise to allocate a few words of
  56.      extra space for _b_u_f, to allow for any synchronization problems resulting
  57.      from signals occurring at inopportune times.  A good choice (and the one
  58.      used by default in _s_t_d_i_o(3s)) is
  59.  
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. SSSSEEEETTTTBBBBUUUUFFFF((((3333FFFF))))                                                          SSSSEEEETTTTBBBBUUUUFFFF((((3333FFFF))))
  71.  
  72.  
  73.  
  74.           char buf[BUFSIZ + 8]; character *(BUFSIZ + 8) buf
  75.  
  76.      _S_e_t_v_b_u_f may be used after a stream unit has been opened but before it is
  77.      read or written.  _T_y_p_e determines how _s_t_r_e_a_m _l_u_n will be buffered.  Legal
  78.      values for _t_y_p_e (defined in <<<<ssssttttddddiiiioooo....hhhh>>>>) are:
  79.  
  80.      _IOFBF  causes input/output to be fully buffered.
  81.  
  82.      _IOLBF  causes output to be line buffered; the buffer will be flushed
  83.              when a newline is written, the buffer is full, or input is
  84.              requested.
  85.  
  86.      _IONBF  causes input/output to be completely unbuffered.
  87.  
  88.      If input/output is unbuffered, _b_u_f and _s_i_z_e are ignored.  For buffered
  89.      input/output, if _b_u_f is not the NULL pointer and _s_i_z_e is greater than
  90.      eight, the array it points to will be used for buffering.  In this case,
  91.      _s_i_z_e specifies the length of this array. The actual buffer will consist
  92.      of the first _s_i_z_e-8 bytes of _b_u_f (see the discussion of BBBBUUUUFFFFSSSSIIIIZZZZ above).
  93.      If _b_u_f is the NULL pointer, or _s_i_z_e is less than eight, space will be
  94.      allocated to accommodate a buffer.  This buffer will be of length BBBBUUUUFFFFSSSSIIIIZZZZ....
  95.      (The actual space allocated will be eight bytes longer.)
  96.  
  97.      _S_e_t_b_u_f_f_e_r and _s_e_t_l_i_n_e_b_u_f are provided for compatibility with 4.3BSD.
  98.      _S_e_t_b_u_f_f_e_r, an alternate form of _s_e_t_b_u_f, is used after a stream unit has
  99.      been opened but before it is read or written.  The character array _b_u_f
  100.      whose size is determined by the _s_i_z_e argument is used instead of an
  101.      automatically allocated buffer.  If _b_u_f is the constant pointer NNNNUUUULLLLLLLL,
  102.      input/output will be completely unbuffered.
  103.  
  104.      _S_e_t_l_i_n_e_b_u_f is used to change _s_t_d_o_u_t or _s_t_d_e_r_r from fully buffered or
  105.      unbuffered to line buffered.  Unlike the other routines, it can be used
  106.      at any time that the file descriptor is active.
  107.  
  108. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  109.      fopen(3S), fflush(3S), getc(3S), malloc(3C), putc(3S), stdio(3S).
  110.      flush(3F), perror(3F).
  111.  
  112. DDDDIIIIAAAAGGGGNNNNOOOOSSSSTTTTIIIICCCCSSSS
  113.      Success is indicated by _s_e_t_v_b_u_f and _s_e_t_b_u_f_f_e_r returning zero.  a zero
  114.      return value.  A non-zero return value indicates an error.  The value of
  115.      _e_r_r_n_o can be examined to determine the cause of the error.  If it is
  116.      necessary to allocate a buffer and the attempt is unsuccessful, _s_e_t_v_b_u_f
  117.      and _s_e_t_b_u_f_f_e_r return a non-zero value. _S_e_t_v_b_u_f will also return non-zero
  118.      if the value of _t_y_p_e is not one of _IONBF, _IOLBF, or _IOFBF.
  119.  
  120. NNNNOOOOTTTTEEEESSSS
  121.      A common source of error is allocating buffer space as an ``automatic''
  122.      variable in a code block, and then failing to close the stream unit in
  123.      the same block.
  124.  
  125.      These functions cannot be used on direct unformatted units.
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. SSSSEEEETTTTBBBBUUUUFFFF((((3333FFFF))))                                                          SSSSEEEETTTTBBBBUUUUFFFF((((3333FFFF))))
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.                                                                         PPPPaaaaggggeeee 3333
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.