Exemplo n.º 1
0
int _putc (int c, FILE * fp) 

{
	if ((fp != NULL) && ((fp->_flag & (_IOWRITE | _IOERR | _IOEOF)) == _IOWRITE)) 
	{
		if ((fp->_cnt > 0) || (_fflush (fp) == 0)) 
		{
			*fp->_ptr++ = (char)(c);
			fp->_cnt--;
			if (((fp->_flag & (_IOTEXT)) != 0) && (c == '\n')) 
			{
				return ((_fflush (fp) == EOF)? (EOF): (c));
			}
			else 
			{
				return (c);
			}
		}
		else 
		{
			return (EOF);
		}
	}
	else 
	{
		return (EOF);
	}
}
Exemplo n.º 2
0
Arquivo: fflush.c Projeto: 8l/subc
int fflush(FILE *f) {
	int	i, rc = 0;

	if (f != NULL) return _fflush(f);
	for (i = 0; i < FOPEN_MAX; i++)
		if (!_fflush(_files[i])) rc = -1;
	return rc;
}
Exemplo n.º 3
0
/*
 * Set one of the three kinds of buffering, optionally including
 * a buffer.
 */
int
setvbuf( FILE *stream, char *buf, int mode, size_t size )
{
	/*
	 * Verify arguments.  The `int' limit on `size' is due to this
	 * particular implementation.
	 */
	if ((mode != _IOFBF && mode != _IOLBF && mode != _IONBF) ||
	    (int)size < 0)
		return EOF;

	/*
	 * Write current buffer, if any; drop read count, if any.
	 * Make sure putc() will not think stream is line buffered.
	 * Free old buffer if it was from malloc().  Clear line and
	 * non buffer flags, and clear malloc flag.
	 */
        EXCL_START(&stream->_file_lock);
	(void) _fflush(stream);
	stream->_r = 0;
	stream->_lbfsize = 0;
	if (stream->_flags & __SMBF)
		free((void *)stream->_bf._base);
	stream->_flags &= ~(__SLBF|__SNBF|__SMBF);

	/*
	 * Now put back whichever flag is needed, and fix _lbfsize
	 * if line buffered.  Ensure output flush on exit if the
	 * stream will be buffered at all.
	 */
	switch (mode) {

	case _IONBF:
		stream->_flags |= __SNBF;
		stream->_bf._base = stream->_p = stream->_nbuf;
		stream->_bf._size = 1;
		break;

	case _IOLBF:
		stream->_flags |= __SLBF;
		stream->_lbfsize = -size;
		/* FALLTHROUGH */

	case _IOFBF:
		/* no flag */
		__cleanup = _cleanup;
		stream->_bf._base = stream->_p = (unsigned char *)buf;
		stream->_bf._size = size;
		break;
	}

	/*
	 * Patch up write count if necessary.
	 */
	if (stream->_flags & __SWR)
		stream->_w = stream->_flags & (__SLBF|__SNBF) ? 0 : size;

        EXCL_END(&stream->_file_lock);
	return 0;
}
Exemplo n.º 4
0
int
printf(const char *fmt, ...)
{
    int outsize;
    va_list ap;

    /* return failure if format is NULL pointer */ 
    if (!fmt)
        return -1;

    _LOCK_FILE(stdout);

    va_start(ap,fmt);
    outsize=_doprnt (fmt, ap, _theputchar, stdout);
    va_end(ap);

#if defined(__ADSP21000__)
    // Always flush output on SHARC, where streams aren't flushed at exit.
    _fflush(stdout);
#endif

    _UNLOCK_FILE(stdout);

    return outsize;
}
Exemplo n.º 5
0
Arquivo: rpmio.c Projeto: akozumpl/rpm
int Fflush(FD_t fd)
{
    int rc = -1;
    if (fd != NULL) {
	fdio_fflush_function_t _fflush = FDIOVEC(fd, _fflush);

	rc = (_fflush ? _fflush(fd) : -2);
    }
    return rc;
}
Exemplo n.º 6
0
int _flsbuf (int c, FILE *fp) 

{
	if (_fflush (fp) == 0) 
	{
		*fp->_ptr++ = (unsigned char)(c);
		fp->_cnt--;
		return (c);
	}
	else 
	{
		return (EOF);
	}
}
Exemplo n.º 7
0
term_destination (j_compress_ptr cinfo)
{
  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;

  /* Write any data remaining in the buffer */
  if (datacount > 0) {
    if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
      ERREXIT(cinfo, JERR_FILE_WRITE);
  }
  _fflush(dest->outfile);
  /* Make sure we wrote the output file OK */
  if (_ferror(dest->outfile))
    ERREXIT(cinfo, JERR_FILE_WRITE);
}
Exemplo n.º 8
0
FILE *freopen( const char *filename, const char *mode, FILE *stream )
{
	register int f;
	int wantfd, isopen, flags, oflags, e;

	if (filename == NULL || filename[0] == '\0')
		return NULL;
        EXCL_START(&stream->_file_lock);
	if ((flags = __sflags(mode, &oflags)) == 0) {
		EXCL_END(&stream->_file_lock);
		(void) fclose(stream);
		return NULL;
	}
	if (!__sdidinit)
		__sinit();

	/*
	 * Remember whether the stream was open to begin with, and
	 * which file descriptor (if any) was associated with it.
	 * If it was attached to a descriptor, defer closing it,
	 * so that, e.g., freopen("/dev/stdin", "r", stdin) works.
	 * This is unnecessary if it was not a Unix file.
	 */
	if (stream->_flags == 0) {
		stream->_flags = __SEOF;	/* hold on to it */
		isopen = 0;
		wantfd = -1;
	} else {
		if (stream->_flags & __SWR)
			(void) _fflush(stream);
		/* if close is NULL, closing is a no-op, hence pointless */
		isopen = stream->_close != NULL;
		if ((wantfd = stream->_file) < 0 && isopen) {
			(void) (*stream->_close)(stream->_cookie);
			isopen = 0;
		}
	}

	/*
	 * Now get a new descriptor to refer to the new file.
	 */
	f = _open(filename, oflags, 0666);
	if (f < 0 && isopen) {
		/*
		 * May have used up all descriptors, so close the old
		 * and try again.
		 */
		(void) (*stream->_close)(stream->_cookie);
		isopen = 0;
		f = _open(filename, oflags, 0666);
	}
	e = errno;

	/*
	 * Finish closing stream.  Even if the open succeeded above,
	 * we cannot keep stream->_base: it may be the wrong size.
	 * This loses the effect of any setbuffer calls,
	 * but stdio has always done this before.
	 */
	if (isopen)
		(void) (*stream->_close)(stream->_cookie);
	if (stream->_flags & __SMBF)
		free((char *)stream->_bf._base);
	stream->_w = 0;
	stream->_r = 0;
	stream->_p = NULL;
	stream->_bf._base = NULL;
	stream->_bf._size = 0;
	stream->_lbfsize = 0;
	if (HASUB(stream))
		FREEUB(stream);
	stream->_ub._size = 0;
	if (HASLB(stream))
		FREELB(stream);
	stream->_lb._size = 0;

	if (f < 0) {			/* did not get it after all */
		stream->_flags = 0;		/* set it free */
		errno = e;		/* restore in case _close clobbered */
		EXCL_END(&stream->_file_lock);
		return NULL;
	}

#ifdef NOTDEF
	/*
	 * If reopening something that was open before on a real file,
	 * try to maintain the descriptor.  Various routines (e.g.,
	 * perror) assume that after `freopen(name, mode, stderr)',
	 * fileno(stderr)==2.
	 */
	if (wantfd >= 0 && f != wantfd) {
		if (_dup2(f, wantfd) >= 0) {
			(void) _close(f);
			f = wantfd;
		}
	}
#endif /* NOTDEF */

	stream->_flags = flags;
	stream->_file = f;
	stream->_cookie = stream;
	stream->_read = __sread;
	stream->_write = __swrite;
	stream->_seek = __sseek;
	stream->_close = __sclose;
	EXCL_END(&stream->_file_lock);
	return stream;
}
Exemplo n.º 9
0
void dofflush() {
	if (_fflush()) {
		fflush(out);
	}
}