int setvbuf ( /* SYNOPSIS */ FILE *stream, char *buf, int mode, size_t size) /* FUNCTION INPUTS RESULT NOTES EXAMPLE BUGS SEE ALSO INTERNALS ******************************************************************************/ { fdesc *desc; if (!stream) { errno = EFAULT; return EOF; } switch (mode) { case _IOFBF: mode = BUF_FULL; break; case _IOLBF: mode = BUF_LINE; break; case _IONBF: mode = BUF_NONE; break; default: errno = EINVAL; return EOF; } desc = __getfdesc(stream->fd); if (!desc) { errno = EBADF; return EOF; } return SetVBuf(desc->fcb->fh, buf, mode, size ? size : -1); } /* setvbuf */
int fputs ( /* SYNOPSIS */ const char * str, FILE * stream) /* FUNCTION Write a string to the specified stream. INPUTS str - Output this string... fh - ...to this stream RESULT > 0 on success and EOF on error. NOTES EXAMPLE BUGS SEE ALSO puts(), fputc(), putc() INTERNALS ******************************************************************************/ { fdesc *fdesc = __getfdesc(stream->fd); if (!fdesc) { errno = EBADF; return EOF; } if (!str) str = "(null)"; if (FPuts(fdesc->fcb->handle, str) == -1) { errno = __stdc_ioerr2errno(IoErr()); return EOF; } return 0; } /* fputs */
int vfprintf ( /* SYNOPSIS */ FILE * stream, const char * format, va_list args) /* FUNCTION Format a list of arguments and print them on the specified stream. INPUTS stream - A stream on which one can write format - A printf() format string. args - A list of arguments for the format string. RESULT The number of characters written. NOTES EXAMPLE BUGS SEE ALSO INTERNALS ******************************************************************************/ { fdesc *fdesc = __getfdesc(stream->fd); if (!fdesc) { errno = EBADF; return 0; } return __vcformat (fdesc->fcb->fh, __putc, format, args); } /* vfprintf */
FILE *fdopen ( /* SYNOPSIS */ int filedes, const char *mode ) /* FUNCTION function associates a stream with an existing file descriptor. INPUTS filedes - The descriptor the stream has to be associated with mode - The mode of the stream (same as with fopen()) must be com patible with the mode of the file descriptor. The file position indicator of the new stream is set to that belonging to filedes, and the error and end-of-file indica tors are cleared. Modes "w" or "w+" do not cause trunca tion of the file. The file descriptor is not dup'ed, and will be closed when the stream created by fdopen is closed. RESULT NULL on error or the new stream associated with the descriptor. The new descriptor returned by the call is the lowest numbered descriptor currently not in use by the process. NOTES This function must not be used in a shared library or in a threaded application. EXAMPLE BUGS SEE ALSO open(), fclose(), fileno() INTERNALS ******************************************************************************/ { int oflags, wanted_accmode, current_accmode; fdesc *fdesc; FILENODE *fn; if (!(fdesc = __getfdesc(filedes))) { errno = EBADF; return NULL; } oflags = fdesc->fcb->flags; if (mode) { oflags = __smode2oflags(mode); wanted_accmode = oflags & O_ACCMODE; current_accmode = fdesc->fcb->flags & O_ACCMODE; /* Check if the requested access mode flags are a valid subset of the flags the already open file has. Thus, if the file's access mode is O_RDWR the requested mode can be anything (O_RDONLY, O_WRONLY or O_RDWR), else they must match exactly. */ if ((current_accmode != O_RDWR) && (wanted_accmode != current_accmode)) { errno = EINVAL; return NULL; } } fn = malloc(sizeof(FILENODE)); if (!fn) return NULL; AddTail ((struct List *)&__stdio_files, (struct Node *)fn); fn->File.flags = __oflags2sflags(oflags); fn->File.fd = filedes; return FILENODE2FILE(fn); }