1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/genericopenlibs/cstdlib/LSTDIO/STDIO.C Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,89 @@
1.4 +/* STDIO.C
1.5 + *
1.6 + * Portions Copyright (c) 1990-1999 Nokia Corporation and/or its subsidiary(-ies).
1.7 + * All rights reserved.
1.8 + * All rights reserved.
1.9 + */
1.10 +
1.11 +/* No user fns here. Pesch 15apr92. */
1.12 +
1.13 +/*
1.14 + * Copyright (c) 1990 The Regents of the University of California.
1.15 + * All rights reserved.
1.16 + *
1.17 + * Redistribution and use in source and binary forms are permitted
1.18 + * provided that the above copyright notice and this paragraph are
1.19 + * duplicated in all such forms and that any documentation,
1.20 + * advertising materials, and other materials related to such
1.21 + * distribution and use acknowledge that the software was developed
1.22 + * by the University of California, Berkeley. The name of the
1.23 + * University may not be used to endorse or promote products derived
1.24 + * from this software without specific prior written permission.
1.25 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1.26 + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1.27 + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1.28 + */
1.29 +
1.30 +#include <stdio.h>
1.31 +#include <sys/types.h>
1.32 +#include <fcntl.h>
1.33 +#include <sys/unistd.h>
1.34 +#include "LOCAL.H"
1.35 +
1.36 +/*
1.37 + * Small standard I/O/seek/close functions.
1.38 + * These maintain the `known seek offset' for seek optimisation.
1.39 + */
1.40 +
1.41 +int
1.42 +__sread (void* cookie,char *buf,int n)
1.43 +{
1.44 + register FILE *fp = (FILE *) cookie;
1.45 + register int ret;
1.46 +
1.47 + ret = _read_r(fp->_data, fp->_file, buf, n);
1.48 +
1.49 + /* If the read succeeded, update the current offset. */
1.50 +
1.51 + if (ret >= 0)
1.52 + fp->_offset += ret;
1.53 + else
1.54 + fp->_flags &= ~__SOFF; /* paranoia */
1.55 + return ret;
1.56 +}
1.57 +
1.58 +int
1.59 +__swrite (void* cookie,char const *buf,int n)
1.60 +{
1.61 + register FILE *fp = (FILE *) cookie;
1.62 +
1.63 + if (fp->_flags & __SAPP)
1.64 + (void) _lseek_r (fp->_data, fp->_file, (off_t) 0, SEEK_END);
1.65 + fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */
1.66 + return _write_r (fp->_data, fp->_file, buf, n);
1.67 +}
1.68 +
1.69 +fpos_t
1.70 +__sseek (void* cookie,fpos_t offset,int whence)
1.71 +{
1.72 + register FILE *fp = (FILE *) cookie;
1.73 + register off_t ret;
1.74 +
1.75 + ret = _lseek_r (fp->_data, fp->_file, (off_t) offset, whence);
1.76 + if (ret == -1L)
1.77 + fp->_flags &= ~__SOFF;
1.78 + else
1.79 + {
1.80 + fp->_flags |= __SOFF;
1.81 + fp->_offset = ret;
1.82 + }
1.83 + return ret;
1.84 +}
1.85 +
1.86 +int
1.87 +__sclose (void* cookie)
1.88 +{
1.89 + FILE *fp = (FILE *) cookie;
1.90 +
1.91 + return _close_r (fp->_data, fp->_file);
1.92 +}