nsl_stdio_prv.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
#include "nsl_stdio_prv.h"
/*
* This is a limited implementation to allow libraries to use
* stdio and avoid the limitation of 256 open file descriptors.
* The newly implemented stdio functions are closely based on
* the implementation in C library.
* To simplify, certain assumptions are made:
* - a file may be opened for either readonly or write only
* - file descriptors should not be shared between threads
* - only seek to beginning of file
* - ungetc may only work for the last char. ie., ungetc will work
* once (but not necessarily more) after a read
*/
static int
{
int nfd;
static const int min_fd = 256;
return (fd);
/*
* If the shell limits [See limit(1)] the
* descriptors to 256, _fcntl will fail
* and errno will be set to EINVAL. Since
* the intention is to ignore _fcntl failures
* and continue working with 'fd', we should
* reset errno to _prevent_ apps relying on errno
* to treat this as an error.
*/
errno = 0;
return (fd);
}
return (nfd);
}
{
int flag;
int oflag;
int fd;
return (NULL);
}
switch (mode[0]) {
default:
return (NULL);
case 'r':
flag = 0;
break;
case 'w':
break;
}
return (NULL);
}
if (fd < 0)
return (NULL);
} else {
}
return (stream);
}
int
{
int res = 0;
return (EOF);
return (res);
}
/* fill buffer, return 0 or EOF */
static int
{
int res;
__NSL_FILE_BUF_SIZE)) > 0) {
return (0);
} else {
if (res == 0)
else
return (EOF);
}
}
char *
{
char *p;
int n;
return (NULL);
}
size--; /* room for '\0' */
while (size > 0) {
break; /* nothing left to read */
}
n = (int)(p - ptr);
ptr += n;
if (p != NULL)
break; /* newline found */
size -= n;
}
return (NULL);
*ptr = '\0';
return (buf);
}
int
{
}
int
{
off_t p;
return (-1);
} else {
}
}
void
{
}
long
{
else
if (tres >= 0)
return (EOF);
}
return ((long)tres);
}
{
ssize_t s;
/* is it a readable stream */
return (0);
}
return (0);
while (s > 0) {
}
/*
* filbuf clobbers _cnt & _ptr,
* so don't waste time setting them.
*/
break;
}
return (nitems);
}
}
}
int
{
/* is it a readable stream */
return (0);
}
return (EOF);
}
}
int
{
ssize_t n;
unsigned char *base;
return (0);
}
if (n > 0) {
while ((num_wrote =
if (num_wrote <= 0) {
return (EOF);
}
n -= num_wrote;
}
}
return (0);
}
int
{
return (EOF);
if (c == EOF)
return (EOF);
return (EOF);
return (c);
}
{
int flag;
return (NULL);
}
switch (mode[0]) {
default:
return (NULL);
case 'r':
flag = 0;
break;
case 'w':
break;
}
return (NULL);
}
}
return (stream);
}
{
ssize_t s;
return (0);
return (0);
while (s > 0) {
}
break;
}
return (nitems);
}
}
}
int
{
return (EOF);
return (EOF);
}
return ((unsigned char)c);
}