os/ossrv/genericopenlibs/cstdlib/LSTDIO/SETBUF.C
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
/* SETBUF.C
sl@0
     2
 * 
sl@0
     3
 * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     4
 * All rights reserved.
sl@0
     5
 */
sl@0
     6
sl@0
     7
/*
sl@0
     8
 * Copyright (c) 1990 The Regents of the University of California.
sl@0
     9
 * All rights reserved.
sl@0
    10
 *
sl@0
    11
 * Redistribution and use in source and binary forms are permitted
sl@0
    12
 * provided that the above copyright notice and this paragraph are
sl@0
    13
 * duplicated in all such forms and that any documentation,
sl@0
    14
 * advertising materials, and other materials related to such
sl@0
    15
 * distribution and use acknowledge that the software was developed
sl@0
    16
 * by the University of California, Berkeley.  The name of the
sl@0
    17
 * University may not be used to endorse or promote products derived
sl@0
    18
 * from this software without specific prior written permission.
sl@0
    19
 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
sl@0
    20
 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
sl@0
    21
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
sl@0
    22
 */
sl@0
    23
sl@0
    24
/*
sl@0
    25
FUNCTION
sl@0
    26
<<setbuf>>---specify full buffering for a file or stream
sl@0
    27
sl@0
    28
INDEX
sl@0
    29
	setbuf
sl@0
    30
sl@0
    31
ANSI_SYNOPSIS
sl@0
    32
	#include <stdio.h>
sl@0
    33
	void setbuf(FILE *<[fp]>, char *<[buf]>);
sl@0
    34
sl@0
    35
TRAD_SYNOPSIS
sl@0
    36
	#include <stdio.h>
sl@0
    37
	void setbuf(<[fp]>, <[buf]>)
sl@0
    38
	FILE *<[fp]>;
sl@0
    39
	char *<[buf]>;
sl@0
    40
sl@0
    41
DESCRIPTION
sl@0
    42
<<setbuf>> specifies that output to the file or stream identified by <[fp]>
sl@0
    43
should be fully buffered.  All output for this file will go to a
sl@0
    44
buffer (of size <<BUFSIZ>>, specified in `<<stdio.h>>').  Output will
sl@0
    45
be passed on to the host system only when the buffer is full, or when
sl@0
    46
an input operation intervenes.
sl@0
    47
sl@0
    48
You may, if you wish, supply your own buffer by passing a pointer to
sl@0
    49
it as the argument <[buf]>.  It must have size <<BUFSIZ>>.  You can
sl@0
    50
also use <<NULL>> as the value of <[buf]>, to signal that the
sl@0
    51
<<setbuf>> function is to allocate the buffer.
sl@0
    52
sl@0
    53
WARNINGS
sl@0
    54
You may only use <<setbuf>> before performing any file operation other
sl@0
    55
than opening the file.
sl@0
    56
sl@0
    57
If you supply a non-null <[buf]>, you must ensure that the associated
sl@0
    58
storage continues to be available until you close the stream
sl@0
    59
identified by <[fp]>.
sl@0
    60
sl@0
    61
RETURNS
sl@0
    62
<<setbuf>> does not return a result.
sl@0
    63
sl@0
    64
PORTABILITY
sl@0
    65
Both ANSI C and the System V Interface Definition (Issue 2) require
sl@0
    66
<<setbuf>>.  However, they differ on the meaning of a <<NULL>> buffer
sl@0
    67
pointer: the SVID issue 2 specification says that a <<NULL>> buffer
sl@0
    68
pointer requests unbuffered output.  For maximum portability, avoid
sl@0
    69
<<NULL>> buffer pointers.
sl@0
    70
sl@0
    71
Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>,
sl@0
    72
<<lseek>>, <<read>>, <<sbrk>>, <<write>>.
sl@0
    73
*/
sl@0
    74
sl@0
    75
#include <stdio.h>
sl@0
    76
#include "LOCAL.H"
sl@0
    77
sl@0
    78
/**
sl@0
    79
Change stream buffering.
sl@0
    80
Changes the buffer used for I/O operations with the specified stream, or,
sl@0
    81
if the specified buffer is NULL it disables buffering with the stream.
sl@0
    82
This function should be called once the file associated with the stream 
sl@0
    83
has been opened but before any input or output operation has been done.
sl@0
    84
With buffered streams writing operations do not write directly 
sl@0
    85
to the device associated with them; the data is accumulated in the buffer 
sl@0
    86
and written to the device as a block.
sl@0
    87
All buffers are also flushed when program terminates.
sl@0
    88
@param fp pointer to an open file.
sl@0
    89
@param buf User allocated buffer. Must have a length of BUFSIZ bytes.
sl@0
    90
*/
sl@0
    91
EXPORT_C void setbuf (FILE * fp, char *buf)
sl@0
    92
{
sl@0
    93
  (void) setvbuf (fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ);
sl@0
    94
}