diff options
Diffstat (limited to 'newlib/libc/stdio64')
-rw-r--r-- | newlib/libc/stdio64/Makefile.am | 64 | ||||
-rw-r--r-- | newlib/libc/stdio64/Makefile.in | 412 | ||||
-rw-r--r-- | newlib/libc/stdio64/fgetpos64.c | 66 | ||||
-rw-r--r-- | newlib/libc/stdio64/fopen64.c | 131 | ||||
-rw-r--r-- | newlib/libc/stdio64/freopen64.c | 169 | ||||
-rw-r--r-- | newlib/libc/stdio64/fseeko64.c | 330 | ||||
-rw-r--r-- | newlib/libc/stdio64/fsetpos64.c | 57 | ||||
-rw-r--r-- | newlib/libc/stdio64/ftello64.c | 138 | ||||
-rw-r--r-- | newlib/libc/stdio64/local64.h | 13 | ||||
-rw-r--r-- | newlib/libc/stdio64/stdio64.c | 79 | ||||
-rw-r--r-- | newlib/libc/stdio64/stdio64.tex | 42 | ||||
-rw-r--r-- | newlib/libc/stdio64/tmpfile64.c | 84 |
12 files changed, 1585 insertions, 0 deletions
diff --git a/newlib/libc/stdio64/Makefile.am b/newlib/libc/stdio64/Makefile.am new file mode 100644 index 000000000..eca225ac8 --- /dev/null +++ b/newlib/libc/stdio64/Makefile.am @@ -0,0 +1,64 @@ +## Process this file with automake to generate Makefile.in + +AUTOMAKE_OPTIONS = cygnus + +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) + +LIB_SOURCES = \ + fgetpos64.c \ + fopen64.c \ + freopen64.c \ + fseeko64.c \ + fsetpos64.c \ + fstat64r.c \ + ftello64.c \ + lseek64r.c \ + open64r.c \ + stdio64.c \ + tmpfile64.c + +libstdio64_la_LDFLAGS = -Xcompiler -nostdlib + +if USE_LIBTOOL +noinst_LTLIBRARIES = libstdio64.la +libstdio64_la_SOURCES = $(LIB_SOURCES) +LIB_COMPILE = $(LTCOMPILE) +noinst_DATA = objectlist.awk.in +else +noinst_LIBRARIES = lib.a +lib_a_SOURCES = $(LIB_SOURCES) +LIB_COMPILE = $(COMPILE) +noinst_DATA = +endif # USE_LIBTOOL + +include $(srcdir)/../../Makefile.shared + +AM_CFLAGS = -I $(srcdir)/../stdio + +CHEWOUT_FILES = \ + fgetpos64.def \ + fopen64.def \ + freopen64.def \ + fseeko64.def \ + fsetpos64.def \ + fstat64r.def \ + ftello64.def \ + lseek64r.def \ + open64r.def \ + tmpfile64.def + +SUFFIXES = .def + +CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str + +.c.def: + $(CHEW) < $< > $*.def 2> $*.ref + touch stmp-def + +TARGETDOC = ../tmp.texi + +doc: $(CHEWOUT_FILES) + cat $(srcdir)/stdio64.tex >> $(TARGETDOC) + +CLEANFILES = $(CHEWOUT_FILES) *.ref + diff --git a/newlib/libc/stdio64/Makefile.in b/newlib/libc/stdio64/Makefile.in new file mode 100644 index 000000000..7d57f4d0d --- /dev/null +++ b/newlib/libc/stdio64/Makefile.in @@ -0,0 +1,412 @@ +# Makefile.in generated automatically by automake 1.4 from Makefile.am + +# Copyright (C) 1994, 1995-8, 1999 Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include + +DESTDIR = + +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ + +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ $(AM_INSTALL_PROGRAM_FLAGS) +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +transform = @program_transform_name@ + +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_alias = @build_alias@ +build_triplet = @build@ +host_alias = @host_alias@ +host_triplet = @host@ +target_alias = @target_alias@ +target_triplet = @target@ +AR = @AR@ +AS = @AS@ +CC = @CC@ +CPP = @CPP@ +CRT0 = @CRT0@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +DLLTOOL = @DLLTOOL@ +EXEEXT = @EXEEXT@ +GCJ = @GCJ@ +GCJFLAGS = @GCJFLAGS@ +LDFLAGS = @LDFLAGS@ +LIBC_EXTRA_DEF = @LIBC_EXTRA_DEF@ +LIBC_EXTRA_LIB = @LIBC_EXTRA_LIB@ +LIBC_MACHINE_LIB = @LIBC_MACHINE_LIB@ +LIBC_POSIX_LIB = @LIBC_POSIX_LIB@ +LIBC_SIGNAL_DEF = @LIBC_SIGNAL_DEF@ +LIBC_SIGNAL_LIB = @LIBC_SIGNAL_LIB@ +LIBC_SYSCALL_LIB = @LIBC_SYSCALL_LIB@ +LIBC_SYS_LIB = @LIBC_SYS_LIB@ +LIBC_UNIX_LIB = @LIBC_UNIX_LIB@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MAKEINFO = @MAKEINFO@ +NEWLIB_CFLAGS = @NEWLIB_CFLAGS@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +VERSION = @VERSION@ +aext = @aext@ +extra_dir = @extra_dir@ +libm_machine_dir = @libm_machine_dir@ +machine_dir = @machine_dir@ +newlib_basedir = @newlib_basedir@ +oext = @oext@ +sys_dir = @sys_dir@ + +AUTOMAKE_OPTIONS = cygnus + +INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) + +LIB_SOURCES = \ + fgetpos64.c \ + fopen64.c \ + freopen64.c \ + fseeko64.c \ + fsetpos64.c \ + ftello64.c \ + stdio64.c \ + tmpfile64.c + + +libstdio64_la_LDFLAGS = -Xcompiler -nostdlib + +@USE_LIBTOOL_TRUE@noinst_LTLIBRARIES = @USE_LIBTOOL_TRUE@libstdio64.la +@USE_LIBTOOL_TRUE@libstdio64_la_SOURCES = @USE_LIBTOOL_TRUE@$(LIB_SOURCES) +@USE_LIBTOOL_TRUE@LIB_COMPILE = @USE_LIBTOOL_TRUE@$(LTCOMPILE) +@USE_LIBTOOL_FALSE@LIB_COMPILE = @USE_LIBTOOL_FALSE@$(COMPILE) +@USE_LIBTOOL_TRUE@noinst_DATA = @USE_LIBTOOL_TRUE@objectlist.awk.in +@USE_LIBTOOL_FALSE@noinst_DATA = +@USE_LIBTOOL_FALSE@noinst_LIBRARIES = @USE_LIBTOOL_FALSE@lib.a +@USE_LIBTOOL_FALSE@lib_a_SOURCES = @USE_LIBTOOL_FALSE@$(LIB_SOURCES) + +AM_CFLAGS = -I $(srcdir)/../stdio + +CHEWOUT_FILES = \ + fgetpos64.def \ + fopen64.def \ + freopen64.def \ + fseeko64.def \ + fsetpos64.def \ + ftello64.def \ + tmpfile64.def + + +SUFFIXES = .def + +CHEW = ../../doc/makedoc -f $(srcdir)/../../doc/doc.str + +TARGETDOC = ../tmp.texi + +CLEANFILES = $(CHEWOUT_FILES) *.ref +mkinstalldirs = $(SHELL) $(top_srcdir)/../../mkinstalldirs +CONFIG_CLEAN_FILES = +LIBRARIES = $(noinst_LIBRARIES) + + +DEFS = @DEFS@ -I. -I$(srcdir) +CPPFLAGS = @CPPFLAGS@ +LIBS = @LIBS@ +lib_a_LIBADD = +@USE_LIBTOOL_FALSE@lib_a_OBJECTS = fgetpos64.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@fopen64.$(OBJEXT) freopen64.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@fseeko64.$(OBJEXT) fsetpos64.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@ftello64.$(OBJEXT) stdio64.$(OBJEXT) \ +@USE_LIBTOOL_FALSE@tmpfile64.$(OBJEXT) +LTLIBRARIES = $(noinst_LTLIBRARIES) + +libstdio64_la_LIBADD = +@USE_LIBTOOL_TRUE@libstdio64_la_OBJECTS = fgetpos64.lo fopen64.lo \ +@USE_LIBTOOL_TRUE@freopen64.lo fseeko64.lo fsetpos64.lo ftello64.lo \ +@USE_LIBTOOL_TRUE@stdio64.lo tmpfile64.lo +CFLAGS = @CFLAGS@ +COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +CCLD = $(CC) +LINK = $(LIBTOOL) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(LDFLAGS) -o $@ +DATA = $(noinst_DATA) + +DIST_COMMON = Makefile.am Makefile.in + + +DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST) + +TAR = gtar +GZIP_ENV = --best +SOURCES = $(lib_a_SOURCES) $(libstdio64_la_SOURCES) +OBJECTS = $(lib_a_OBJECTS) $(libstdio64_la_OBJECTS) + +all: all-redirect +.SUFFIXES: +.SUFFIXES: .S .c .def .lo .o .obj .s +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) $(srcdir)/../../Makefile.shared + cd $(top_srcdir) && $(AUTOMAKE) --cygnus stdio64/Makefile + +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) \ + && CONFIG_FILES=$(subdir)/$@ CONFIG_HEADERS= $(SHELL) ./config.status + + +mostlyclean-noinstLIBRARIES: + +clean-noinstLIBRARIES: + -test -z "$(noinst_LIBRARIES)" || rm -f $(noinst_LIBRARIES) + +distclean-noinstLIBRARIES: + +maintainer-clean-noinstLIBRARIES: + +.c.o: + $(COMPILE) -c $< + +# FIXME: We should only use cygpath when building on Windows, +# and only if it is available. +.c.obj: + $(COMPILE) -c `cygpath -w $<` + +.s.o: + $(COMPILE) -c $< + +.S.o: + $(COMPILE) -c $< + +mostlyclean-compile: + -rm -f *.o core *.core + -rm -f *.$(OBJEXT) + +clean-compile: + +distclean-compile: + -rm -f *.tab.c + +maintainer-clean-compile: + +.c.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.s.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +.S.lo: + $(LIBTOOL) --mode=compile $(COMPILE) -c $< + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + +maintainer-clean-libtool: + +lib.a: $(lib_a_OBJECTS) $(lib_a_DEPENDENCIES) + -rm -f lib.a + $(AR) cru lib.a $(lib_a_OBJECTS) $(lib_a_LIBADD) + $(RANLIB) lib.a + +mostlyclean-noinstLTLIBRARIES: + +clean-noinstLTLIBRARIES: + -test -z "$(noinst_LTLIBRARIES)" || rm -f $(noinst_LTLIBRARIES) + +distclean-noinstLTLIBRARIES: + +maintainer-clean-noinstLTLIBRARIES: + +libstdio64.la: $(libstdio64_la_OBJECTS) $(libstdio64_la_DEPENDENCIES) + $(LINK) $(libstdio64_la_LDFLAGS) $(libstdio64_la_OBJECTS) $(libstdio64_la_LIBADD) $(LIBS) + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + here=`pwd` && cd $(srcdir) \ + && mkid -f$$here/ID $$unique $(LISP) + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS)'; \ + unique=`for i in $$list; do echo $$i; done | \ + awk ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$unique$(LISP)$$tags" \ + || (cd $(srcdir) && etags $(ETAGS_ARGS) $$tags $$unique $(LISP) -o $$here/TAGS) + +mostlyclean-tags: + +clean-tags: + +distclean-tags: + -rm -f TAGS ID + +maintainer-clean-tags: + +distdir = $(top_builddir)/$(PACKAGE)-$(VERSION)/$(subdir) + +subdir = stdio64 + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + if test -f $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + cp -pr $$d/$$file $(distdir)/$$file; \ + else \ + test -f $(distdir)/$$file \ + || ln $$d/$$file $(distdir)/$$file 2> /dev/null \ + || cp -p $$d/$$file $(distdir)/$$file || :; \ + fi; \ + done +info-am: +info: info-am +dvi-am: +dvi: dvi-am +check-am: +check: check-am +installcheck-am: +installcheck: installcheck-am +install-info-am: +install-info: install-info-am +install-exec-am: +install-exec: install-exec-am + +install-data-am: +install-data: install-data-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am +install: install-am +uninstall-am: +uninstall: uninstall-am +all-am: Makefile $(LIBRARIES) $(LTLIBRARIES) $(DATA) +all-redirect: all-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) AM_INSTALL_PROGRAM_FLAGS=-s install +installdirs: + + +mostlyclean-generic: + +clean-generic: + -test -z "$(CLEANFILES)" || rm -f $(CLEANFILES) + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + -rm -f config.cache config.log stamp-h stamp-h[0-9]* + +maintainer-clean-generic: +mostlyclean-am: mostlyclean-noinstLIBRARIES mostlyclean-compile \ + mostlyclean-libtool mostlyclean-noinstLTLIBRARIES \ + mostlyclean-tags mostlyclean-generic + +mostlyclean: mostlyclean-am + +clean-am: clean-noinstLIBRARIES clean-compile clean-libtool \ + clean-noinstLTLIBRARIES clean-tags clean-generic \ + mostlyclean-am + +clean: clean-am + +distclean-am: distclean-noinstLIBRARIES distclean-compile \ + distclean-libtool distclean-noinstLTLIBRARIES \ + distclean-tags distclean-generic clean-am + -rm -f libtool + +distclean: distclean-am + +maintainer-clean-am: maintainer-clean-noinstLIBRARIES \ + maintainer-clean-compile maintainer-clean-libtool \ + maintainer-clean-noinstLTLIBRARIES \ + maintainer-clean-tags maintainer-clean-generic \ + distclean-am + @echo "This command is intended for maintainers to use;" + @echo "it deletes files that may require special tools to rebuild." + +maintainer-clean: maintainer-clean-am + +.PHONY: mostlyclean-noinstLIBRARIES distclean-noinstLIBRARIES \ +clean-noinstLIBRARIES maintainer-clean-noinstLIBRARIES \ +mostlyclean-compile distclean-compile clean-compile \ +maintainer-clean-compile mostlyclean-libtool distclean-libtool \ +clean-libtool maintainer-clean-libtool mostlyclean-noinstLTLIBRARIES \ +distclean-noinstLTLIBRARIES clean-noinstLTLIBRARIES \ +maintainer-clean-noinstLTLIBRARIES tags mostlyclean-tags distclean-tags \ +clean-tags maintainer-clean-tags distdir info-am info dvi-am dvi check \ +check-am installcheck-am installcheck install-info-am install-info \ +install-exec-am install-exec install-data-am install-data install-am \ +install uninstall-am uninstall all-redirect all-am all installdirs \ +mostlyclean-generic distclean-generic clean-generic \ +maintainer-clean-generic clean mostlyclean distclean maintainer-clean + + +objectlist.awk.in: $(noinst_LTLIBRARIES) + -rm -f objectlist.awk.in + for i in `ls *.lo` ; \ + do \ + echo $$i `pwd`/$$i >> objectlist.awk.in ; \ + done + +.c.def: + $(CHEW) < $< > $*.def 2> $*.ref + touch stmp-def + +doc: $(CHEWOUT_FILES) + cat $(srcdir)/stdio64.tex >> $(TARGETDOC) + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/newlib/libc/stdio64/fgetpos64.c b/newlib/libc/stdio64/fgetpos64.c new file mode 100644 index 000000000..055d53655 --- /dev/null +++ b/newlib/libc/stdio64/fgetpos64.c @@ -0,0 +1,66 @@ +#ifdef __LARGE64_FILES + +/* +FUNCTION +<<fgetpos64>>---record position in a large stream or file + +INDEX + fgetpos64 + +ANSI_SYNOPSIS + #include <stdio.h> + int fgetpos64(FILE *<[fp]>, _fpos64_t *<[pos]>); + +TRAD_SYNOPSIS + #include <stdio.h> + int fgetpos64(<[fp]>, <[pos]>) + FILE *<[fp]>; + _fpos64_t *<[pos]>; + +DESCRIPTION +Objects of type <<FILE>> can have a ``position'' that records how much +of the file your program has already read. Many of the <<stdio>> functions +depend on this position, and many change it as a side effect. + +You can use <<fgetpos64>> to report on the current position for a file +identified by <[fp]> that was opened by <<fopen64>>; <<fgetpos>> will write +a value representing that position at <<*<[pos]>>>. Later, you can +use this value with <<fsetpos64>> to return the file to this +position. + +In the current implementation, <<fgetpos64>> simply uses a character +count to represent the file position; this is the same number that +would be returned by <<ftello64>>. + +RETURNS +<<fgetpos64>> returns <<0>> when successful. If <<fgetpos64>> fails, the +result is <<1>>. Failure occurs on streams that do not support +positioning or streams not opened via <<fopen64>>; the global <<errno>> +indicates these conditions with the value <<ESPIPE>>. + +PORTABILITY +<<fgetpos64>> is a glibc extension. + +No supporting OS subroutines are required. +*/ + +#include <stdio.h> + +int +_DEFUN (fgetpos64, (fp, pos), + FILE * fp _AND + _fpos64_t * pos) +{ + _flockfile(fp); + *pos = (_fpos64_t)ftello64 (fp); + + if (*pos != -1) + { + _funlockfile(fp); + return 0; + } + _funlockfile(fp); + return 1; +} + +#endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/fopen64.c b/newlib/libc/stdio64/fopen64.c new file mode 100644 index 000000000..58ea1459c --- /dev/null +++ b/newlib/libc/stdio64/fopen64.c @@ -0,0 +1,131 @@ +#ifdef __LARGE64_FILES + +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* +FUNCTION +<<fopen64>>---open a large file + +INDEX + fopen64 +INDEX + _fopen64_r + +ANSI_SYNOPSIS + #include <stdio.h> + FILE *fopen64(const char *<[file]>, const char *<[mode]>); + FILE *_fopen64_r(void *<[reent]>, + const char *<[file]>, const char *<[mode]>); + +TRAD_SYNOPSIS + #include <stdio.h> + FILE *fopen64(<[file]>, <[mode]>) + char *<[file]>; + char *<[mode]>; + + FILE *_fopen64_r(<[reent]>, <[file]>, <[mode]>) + char *<[reent]>; + char *<[file]>; + char *<[mode]>; + +DESCRIPTION +<<fopen64>> is identical to <<fopen>> except it opens a large file that +is potentially >2GB in size. See <<fopen>> for further details. + +RETURNS +<<fopen64>> return a file pointer which you can use for other file +operations, unless the file you requested could not be opened; in that +situation, the result is <<NULL>>. If the reason for failure was an +invalid string at <[mode]>, <<errno>> is set to <<EINVAL>>. + +PORTABILITY +<<fopen64>> is a glibc extension. + +Supporting OS subroutines required: <<close>>, <<fstat64>>, <<isatty>>, +<<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>. +*/ + +/* Copied from fopen.c */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "%W% (Berkeley) %G%"; +#endif /* LIBC_SCCS and not lint */ + +#include <stdio.h> +#include <errno.h> +#include "local64.h" +#ifdef __CYGWIN__ +#include <fcntl.h> +#endif + +FILE * +_DEFUN (_fopen64_r, (ptr, file, mode), + struct _reent *ptr _AND + _CONST char *file _AND + _CONST char *mode) +{ + register FILE *fp; + register int f; + int flags, oflags; + + if ((flags = __sflags (ptr, mode, &oflags)) == 0) + return NULL; + if ((fp = __sfp (ptr)) == NULL) + return NULL; + + if ((f = _open64_r (fp->_data, file, oflags, 0666)) < 0) + { + fp->_flags = 0; /* release */ + return NULL; + } + + fp->_file = f; + fp->_flags = flags; + fp->_cookie = (_PTR) fp; + fp->_read = __sread; + fp->_write = __swrite64; + fp->_seek = __sseek; + fp->_seek64 = __sseek64; + fp->_close = __sclose; + + if (fp->_flags & __SAPP) + fseeko64 (fp, 0, SEEK_END); + +#ifdef __SCLE + if (__stextmode (fp->_file)) + fp->_flags |= __SCLE; +#endif + + fp->_flags |= __SL64; + + return fp; +} + +#ifndef _REENT_ONLY + +FILE * +_DEFUN (fopen64, (file, mode), + _CONST char *file _AND + _CONST char *mode) +{ + return _fopen64_r (_REENT, file, mode); +} + +#endif + +#endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/freopen64.c b/newlib/libc/stdio64/freopen64.c new file mode 100644 index 000000000..53b8e3ee8 --- /dev/null +++ b/newlib/libc/stdio64/freopen64.c @@ -0,0 +1,169 @@ +#ifdef __LARGE64_FILES + +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* +FUNCTION +<<freopen64>>---open a large file using an existing file descriptor + +INDEX + freopen64 + +ANSI_SYNOPSIS + #include <stdio.h> + FILE *freopen64(const char *<[file]>, const char *<[mode]>, + FILE *<[fp]>); + +TRAD_SYNOPSIS + #include <stdio.h> + FILE *freopen64(<[file]>, <[mode]>, <[fp]>) + char *<[file]>; + char *<[mode]>; + FILE *<[fp]>; + +DESCRIPTION +Use this variant of <<fopen64>> if you wish to specify a particular file +descriptor <[fp]> (notably <<stdin>>, <<stdout>>, or <<stderr>>) for +the file. + +If <[fp]> was associated with another file or stream, <<freopen64>> +closes that other file or stream (but ignores any errors while closing +it). + +<[file]> and <[mode]> are used just as in <<fopen>>. + +RETURNS +If successful, the result is the same as the argument <[fp]>. If the +file cannot be opened as specified, the result is <<NULL>>. + +PORTABILITY +<<freopen>> is a glibc extension. + +Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, +<<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>. +*/ + +#include <time.h> +#include <stdio.h> +#include <fcntl.h> +#include <stdlib.h> +#include "local64.h" + +/* + * Re-direct an existing, open (probably) file to some other file. + */ + +FILE * +_DEFUN (freopen64, (file, mode, fp), + _CONST char *file _AND + _CONST char *mode _AND + register FILE *fp) +{ + register int f; + int flags, oflags, e; + struct _reent *ptr; + + _flockfile(fp); + + CHECK_INIT (fp); + ptr = fp->_data; + + if ((flags = __sflags (ptr, mode, &oflags)) == 0) + { + (void) fclose (fp); + _funlockfile(fp); + return NULL; + } + + /* + * 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 (fp->_flags == 0) + fp->_flags = __SEOF; /* hold on to it */ + else + { + if (fp->_flags & __SWR) + (void) fflush (fp); + /* if close is NULL, closing is a no-op, hence pointless */ + if (fp->_close != NULL) + (void) (*fp->_close) (fp->_cookie); + } + + /* + * Now get a new descriptor to refer to the new file. + */ + + f = _open64_r (ptr, (char *) file, oflags, 0666); + e = ptr->_errno; + + /* + * Finish closing fp. Even if the open succeeded above, + * we cannot keep fp->_base: it may be the wrong size. + * This loses the effect of any setbuffer calls, + * but stdio has always done this before. + */ + + if (fp->_flags & __SMBF) + _free_r (ptr, (char *) fp->_bf._base); + fp->_w = 0; + fp->_r = 0; + fp->_p = NULL; + fp->_bf._base = NULL; + fp->_bf._size = 0; + fp->_lbfsize = 0; + if (HASUB (fp)) + FREEUB (fp); + fp->_ub._size = 0; + if (HASLB (fp)) + FREELB (fp); + fp->_lb._size = 0; + + if (f < 0) + { /* did not get it after all */ + fp->_flags = 0; /* set it free */ + ptr->_errno = e; /* restore in case _close clobbered */ + _funlockfile(fp); + return NULL; + } + + fp->_flags = flags; + fp->_file = f; + fp->_cookie = (_PTR) fp; + fp->_read = __sread; + fp->_write = __swrite64; + fp->_seek = __sseek; + fp->_seek64 = __sseek64; + fp->_close = __sclose; + +#ifdef __SCLE + if (__stextmode(fp->_file)) + fp->_flags |= __SCLE; +#endif + + fp->flags |= __SL64; + + _funlockfile(fp); + return fp; +} + +#endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/fseeko64.c b/newlib/libc/stdio64/fseeko64.c new file mode 100644 index 000000000..2c312cfbe --- /dev/null +++ b/newlib/libc/stdio64/fseeko64.c @@ -0,0 +1,330 @@ +#ifdef __LARGE64_FILES + +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* +FUNCTION +<<fseeko64>>---set file position for large file + +INDEX + fseeko64 + +ANSI_SYNOPSIS + #include <stdio.h> + int fseeko64(FILE *<[fp]>, _off64_t <[offset]>, int <[whence]>) + +TRAD_SYNOPSIS + #include <stdio.h> + + int fseeko64(<[fp]>, <[offset]>, <[whence]>) + FILE *<[fp]>; + _off64_t <[offset]>; + int <[whence]>; + +DESCRIPTION +Objects of type <<FILE>> can have a ``position'' that records how much +of the file your program has already read. Many of the <<stdio>> functions +depend on this position, and many change it as a side effect. + +You can use <<fseeko64>> to set the position for the file identified by +<[fp]> that was opened via <<fopen64>>. The value of <[offset]> determines +the new position, in one of three ways selected by the value of <[whence]> +(defined as macros in `<<stdio.h>>'): + +<<SEEK_SET>>---<[offset]> is the absolute file position (an offset +from the beginning of the file) desired. <[offset]> must be positive. + +<<SEEK_CUR>>---<[offset]> is relative to the current file position. +<[offset]> can meaningfully be either positive or negative. + +<<SEEK_END>>---<[offset]> is relative to the current end of file. +<[offset]> can meaningfully be either positive (to increase the size +of the file) or negative. + +See <<ftello64>> to determine the current file position. + +RETURNS +<<fseeko64>> returns <<0>> when successful. On failure, the +result is <<EOF>>. The reason for failure is indicated in <<errno>>: +either <<ESPIPE>> (the stream identified by <[fp]> doesn't support +repositioning or wasn't opened via <<fopen64>>) or <<EINVAL>> +(invalid file position). + +PORTABILITY +<<fseeko64>> is a glibc extension. + +Supporting OS subroutines required: <<close>>, <<fstat64>>, <<isatty>>, +<<lseek64>>, <<read>>, <<sbrk>>, <<write>>. +*/ + +#include <stdio.h> +#include <time.h> +#include <fcntl.h> +#include <stdlib.h> +#include <errno.h> +#include <sys/stat.h> +#include "local64.h" + +#define POS_ERR (-(_fpos64_t)1) + +/* + * Seek the given file to the given offset. + * `Whence' must be one of the three SEEK_* macros. + */ + +int +fseeko64 (fp, offset, whence) + register FILE *fp; + _off64_t offset; + int whence; +{ + struct _reent *ptr; + _fpos64_t _EXFUN ((*seekfn), (void *, _fpos64_t, int)); + _fpos64_t target, curoff; + size_t n; + struct stat st; + int havepos; + + _flockfile(fp); + + /* Make sure stdio is set up. */ + + CHECK_INIT (fp); + ptr = fp->_data; + + /* If we've been doing some writing, and we're in append mode + then we don't really know where the filepos is. */ + + if (fp->_flags & __SAPP && fp->_flags & __SWR) + { + /* So flush the buffer and seek to the end. */ + fflush (fp); + } + + /* Have to be able to seek. */ + + if ((seekfn = fp->_seek64) == NULL || !(fp->_flags & __SL64)) + { + ptr->_errno = ESPIPE; /* ??? */ + _funlockfile(fp); + return EOF; + } + + /* + * Change any SEEK_CUR to SEEK_SET, and check `whence' argument. + * After this, whence is either SEEK_SET or SEEK_END. + */ + + switch (whence) + { + case SEEK_CUR: + /* + * In order to seek relative to the current stream offset, + * we have to first find the current stream offset a la + * ftell (see ftell for details). + */ + fflush(fp); /* may adjust seek offset on append stream */ + if (fp->_flags & __SOFF) + curoff = fp->_offset; + else + { + curoff = (*seekfn) (fp->_cookie, (_fpos64_t) 0, SEEK_CUR); + if (curoff == -1L) + { + _funlockfile(fp); + return EOF; + } + } + if (fp->_flags & __SRD) + { + curoff -= fp->_r; + if (HASUB (fp)) + curoff -= fp->_ur; + } + else if (fp->_flags & __SWR && fp->_p != NULL) + curoff += fp->_p - fp->_bf._base; + + offset += curoff; + whence = SEEK_SET; + havepos = 1; + break; + + case SEEK_SET: + case SEEK_END: + havepos = 0; + break; + + default: + ptr->_errno = EINVAL; + _funlockfile(fp); + return (EOF); + } + + /* + * Can only optimise if: + * reading (and not reading-and-writing); + * not unbuffered; and + * this is a `regular' Unix file (and hence seekfn==__sseek). + * We must check __NBF first, because it is possible to have __NBF + * and __SOPT both set. + */ + + if (fp->_bf._base == NULL) + __smakebuf (fp); + if (fp->_flags & (__SWR | __SRW | __SNBF | __SNPT)) + goto dumb; + if ((fp->_flags & __SOPT) == 0) + { + if (seekfn != __sseek64 + || fp->_file < 0 + || _fstat64_r (ptr, fp->_file, &st) + || (st.st_mode & S_IFMT) != S_IFREG) + { + fp->_flags |= __SNPT; + goto dumb; + } +#ifdef HAVE_BLKSIZE + fp->_blksize = st.st_blksize; +#else + fp->_blksize = 1024; +#endif + fp->_flags |= __SOPT; + } + + /* + * We are reading; we can try to optimise. + * Figure out where we are going and where we are now. + */ + + if (whence == SEEK_SET) + target = offset; + else + { + if (_fstat64_r (ptr, fp->_file, &st)) + goto dumb; + target = st.st_size + offset; + } + + if (!havepos) + { + if (fp->_flags & __SOFF) + curoff = fp->_offset; + else + { + curoff = (*seekfn) (fp->_cookie, (_fpos64_t)0, SEEK_CUR); + if (curoff == POS_ERR) + goto dumb; + } + curoff -= fp->_r; + if (HASUB (fp)) + curoff -= fp->_ur; + } + + /* + * Compute the number of bytes in the input buffer (pretending + * that any ungetc() input has been discarded). Adjust current + * offset backwards by this count so that it represents the + * file offset for the first byte in the current input buffer. + */ + + if (HASUB (fp)) + { + curoff += fp->_r; /* kill off ungetc */ + n = fp->_up - fp->_bf._base; + curoff -= n; + n += fp->_ur; + } + else + { + n = fp->_p - fp->_bf._base; + curoff -= n; + n += fp->_r; + } + + /* + * If the target offset is within the current buffer, + * simply adjust the pointers, clear EOF, undo ungetc(), + * and return. (If the buffer was modified, we have to + * skip this; see fgetline.c.) + */ + + if ((fp->_flags & __SMOD) == 0 && + target >= curoff && target < curoff + n) + { + register int o = target - curoff; + + fp->_p = fp->_bf._base + o; + fp->_r = n - o; + if (HASUB (fp)) + FREEUB (fp); + fp->_flags &= ~__SEOF; + _funlockfile(fp); + return 0; + } + + /* + * The place we want to get to is not within the current buffer, + * but we can still be kind to the kernel copyout mechanism. + * By aligning the file offset to a block boundary, we can let + * the kernel use the VM hardware to map pages instead of + * copying bytes laboriously. Using a block boundary also + * ensures that we only read one block, rather than two. + */ + + curoff = target & ~((_fpos64_t)(fp->_blksize - 1)); + if ((*seekfn) (fp->_cookie, curoff, SEEK_SET) == POS_ERR) + goto dumb; + fp->_r = 0; + fp->_p = fp->_bf._base; + if (HASUB (fp)) + FREEUB (fp); + fp->_flags &= ~__SEOF; + n = target - curoff; + if (n) + { + if (__srefill (fp) || fp->_r < n) + goto dumb; + fp->_p += n; + fp->_r -= n; + } + _funlockfile(fp); + return 0; + + /* + * We get here if we cannot optimise the seek ... just + * do it. Allow the seek function to change fp->_bf._base. + */ + +dumb: + if (fflush (fp) || (*seekfn) (fp->_cookie, offset, whence) == POS_ERR) + { + _funlockfile(fp); + return EOF; + } + /* success: clear EOF indicator and discard ungetc() data */ + if (HASUB (fp)) + FREEUB (fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + /* fp->_w = 0; *//* unnecessary (I think...) */ + fp->_flags &= ~__SEOF; + _funlockfile(fp); + return 0; +} + +#endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/fsetpos64.c b/newlib/libc/stdio64/fsetpos64.c new file mode 100644 index 000000000..0cc552d47 --- /dev/null +++ b/newlib/libc/stdio64/fsetpos64.c @@ -0,0 +1,57 @@ +#ifdef __LARGE64_FILES + +/* +FUNCTION +<<fsetpos64>>---restore position of a large stream or file + +INDEX + fsetpos64 + +ANSI_SYNOPSIS + #include <stdio.h> + int fsetpos64(FILE *<[fp]>, const _fpos64_t *<[pos]>); + +TRAD_SYNOPSIS + #include <stdio.h> + int fsetpos64(<[fp]>, <[pos]>) + FILE *<[fp]>; + _fpos64_t *<[pos]>; + +DESCRIPTION +Objects of type <<FILE>> can have a ``position'' that records how much +of the file your program has already read. Many of the <<stdio>> functions +depend on this position, and many change it as a side effect. + +You can use <<fsetpos64>> to return the large file identified by <[fp]> to a +previous position <<*<[pos]>>> (after first recording it with <<fgetpos64>>). + +See <<fseeko64>> for a similar facility. + +RETURNS +<<fgetpos64>> returns <<0>> when successful. If <<fgetpos64>> fails, the +result is <<1>>. The reason for failure is indicated in <<errno>>: +either <<ESPIPE>> (the stream identified by <[fp]> doesn't support +64-bit repositioning) or <<EINVAL>> (invalid file position). + +PORTABILITY +<<fsetpos64>> is a glibc extension. + +Supporting OS subroutines required: <<close>>, <<fstat>>, <<isatty>>, +<<lseek64>>, <<read>>, <<sbrk>>, <<write>>. +*/ + +#include <stdio.h> + +int +_DEFUN (fsetpos64, (iop, pos), + FILE * iop _AND + _CONST _fpos64_t * pos) +{ + int x = fseeko64 (iop, (_off64_t)(*pos), SEEK_SET); + + if (x != 0) + return 1; + return 0; +} + +#endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/ftello64.c b/newlib/libc/stdio64/ftello64.c new file mode 100644 index 000000000..c6b888cf4 --- /dev/null +++ b/newlib/libc/stdio64/ftello64.c @@ -0,0 +1,138 @@ +#ifdef __LARGE64_FILES + +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* +FUNCTION +<<ftello64>>---return position in a stream or file + +INDEX + ftello64 + +ANSI_SYNOPSIS + #include <stdio.h> + _off64_t ftello64(FILE *<[fp]>); + +TRAD_SYNOPSIS + #include <stdio.h> + _off64_t ftello64(<[fp]>) + FILE *<[fp]>; + +DESCRIPTION +Objects of type <<FILE>> can have a ``position'' that records how much +of the file your program has already read. Many of the <<stdio>> functions +depend on this position, and many change it as a side effect. + +The result of <<ftello64>> is the current position for a large file +identified by <[fp]>. If you record this result, you can later +use it with <<fseeko64>> to return the file to this +position. The difference between <<ftello>> and <<ftello64>> is that +<<ftello>> returns <<off_t>> and <<ftello64>> is designed to work +for large files (>2GB) and returns <<_off64_t>>. + +In the current implementation, <<ftello64>> simply uses a character +count to represent the file position; this is the same number that +would be recorded by <<fgetpos64>>. + +The function exists only if the __LARGE64_FILES flag is defined. +An error occurs if the <[fp]> was not opened via <<fopen64>>. + +RETURNS +<<ftello64>> returns the file position, if possible. If it cannot do +this, it returns <<-1>>. Failure occurs on streams that do not support +positioning or not opened via <<fopen64>>; the global <<errno>> indicates +this condition with the value <<ESPIPE>>. + +PORTABILITY +<<ftello64>> is a glibc extension. + +No supporting OS subroutines are required. +*/ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "%W% (Berkeley) %G%"; +#endif /* LIBC_SCCS and not lint */ + +/* + * ftello64: return current offset. + */ + +#include <stdio.h> +#include <errno.h> + +#include "local64.h" + +_off64_t +_DEFUN (ftello64, (fp), + register FILE * fp) +{ + _fpos64_t pos; + + _flockfile(fp); + + /* Ensure stdio is set up. */ + + CHECK_INIT (fp); + + if (fp->_seek64 == NULL) + { + fp->_data->_errno = ESPIPE; + _funlockfile(fp); + return -1L; + } + + /* Find offset of underlying I/O object, then + adjust for buffered bytes. */ + fflush(fp); /* may adjust seek offset on append stream */ + if (fp->_flags & __SOFF) + pos = fp->_offset; + else + { + pos = (*fp->_seek64) (fp->_cookie, (_fpos64_t) 0, SEEK_CUR); + if (pos == -1L) + { + _funlockfile(fp); + return pos; + } + } + if (fp->_flags & __SRD) + { + /* + * Reading. Any unread characters (including + * those from ungetc) cause the position to be + * smaller than that in the underlying object. + */ + pos -= fp->_r; + if (HASUB (fp)) + pos -= fp->_ur; + } + else if (fp->_flags & __SWR && fp->_p != NULL) + { + /* + * Writing. Any buffered characters cause the + * position to be greater than that in the + * underlying object. + */ + pos += fp->_p - fp->_bf._base; + } + + _funlockfile(fp); + return pos; +} + +#endif /* __LARGE64_FILES */ diff --git a/newlib/libc/stdio64/local64.h b/newlib/libc/stdio64/local64.h new file mode 100644 index 000000000..b1ed1dcbb --- /dev/null +++ b/newlib/libc/stdio64/local64.h @@ -0,0 +1,13 @@ +/* + * Information local to this implementation of stdio64, + * in particular, macros and private variables. + */ + +#include "local.h" + +#ifdef __LARGE64_FILES +extern fpos64_t _EXFUN(__sseek64,(void *, fpos64_t, int)); +extern fpos64_t _EXFUN(__sseek64_error,(void *, fpos64_t, int)); +extern _READ_WRITE_RETURN_TYPE _EXFUN(__swrite64,(void *, char const *, int)); +#endif + diff --git a/newlib/libc/stdio64/stdio64.c b/newlib/libc/stdio64/stdio64.c new file mode 100644 index 000000000..7b9e16480 --- /dev/null +++ b/newlib/libc/stdio64/stdio64.c @@ -0,0 +1,79 @@ +/* No user fns here. Pesch 15apr92. */ + +/* + * Copyright (c) 1990 The Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#include <stdio.h> +#include <sys/types.h> +#include <fcntl.h> +#include <sys/unistd.h> +#include <errno.h> +#include "local.h" + +#ifdef __LARGE64_FILES +_fpos64_t +__sseek64 (cookie, offset, whence) + _PTR cookie; + _fpos64_t offset; + int whence; +{ + register FILE *fp = (FILE *) cookie; + register _off64_t ret; + + ret = _lseek64_r (fp->_data, fp->_file, (_off64_t) offset, whence); + if (ret == (_fpos64_t)-1L) + fp->_flags &= ~__SOFF; + else + { + fp->_flags |= __SOFF; + fp->_offset = ret; + } + return ret; +} + +_READ_WRITE_RETURN_TYPE +__swrite64 (cookie, buf, n) + _PTR cookie; + char _CONST *buf; + int n; +{ + register FILE *fp = (FILE *) cookie; + int w; +#ifdef __SCLE + int oldmode=0; +#endif + + if (fp->_flags & __SAPP) + (void) _lseek64_r (fp->_data, fp->_file, (_off64_t)0, SEEK_END); + fp->_flags &= ~__SOFF; /* in case O_APPEND mode is set */ + +#ifdef __SCLE + if (fp->_flags & __SCLE) + oldmode = setmode(fp->_file, O_BINARY); +#endif + + w = _write_r (fp->_data, fp->_file, buf, n); + +#ifdef __SCLE + if (oldmode) + setmode(fp->_file, oldmode); +#endif + + return w; +} +#endif /* __LARGE64_FILES */ + diff --git a/newlib/libc/stdio64/stdio64.tex b/newlib/libc/stdio64/stdio64.tex new file mode 100644 index 000000000..55818c354 --- /dev/null +++ b/newlib/libc/stdio64/stdio64.tex @@ -0,0 +1,42 @@ +@node Stdio64 +@chapter Large File Input and Output (@file{stdio.h}) + +This chapter comprises additional functions to manage large files which +are potentially larger than 2GB. + +The underlying facilities for input and output depend on the host +system, but these functions provide a uniform interface. + +The corresponding declarations are in @file{stdio.h}. + +@menu +* fopen64:: Open a large file +* freopen64:: Open a large file using an existing file descriptor +* fsetpos64:: Restore position of a large stream or file +* fgetpos64:: Get position of a large stream or file +* ftello64:: Return position in a large stream or file +* fseeko64:: Set large file position +* tmpfile64:: Create a temporary large file +@end menu + +@page +@include stdio64/fopen64.def + +@page +@include stdio64/freopen64.def + +@page +@include stdio64/ftello64.def + +@page +@include stdio64/fseeko64.def + +@page +@include stdio64/fgetpos64.def + +@page +@include stdio64/fsetpos64.def + +@page +@include stdio64/tmpfile64.def + diff --git a/newlib/libc/stdio64/tmpfile64.c b/newlib/libc/stdio64/tmpfile64.c new file mode 100644 index 000000000..c26a6204b --- /dev/null +++ b/newlib/libc/stdio64/tmpfile64.c @@ -0,0 +1,84 @@ +#ifdef __LARGE64_FILES + +/* +FUNCTION +<<tmpfile64>>---create a large temporary file + +INDEX + tmpfile64 +INDEX + _tmpfile64_r + +ANSI_SYNOPSIS + #include <stdio.h> + FILE *tmpfile64(void); + + FILE *_tmpfile64_r(void *<[reent]>); + +TRAD_SYNOPSIS + #include <stdio.h> + FILE *tmpfile64(); + + FILE *_tmpfile64_r(<[reent]>) + char *<[reent]>; + +DESCRIPTION +Create a large temporary file (a file which will be deleted automatically), +using a name generated by <<tmpnam>>. The temporary file is opened with +the mode <<"wb+">>, permitting you to read and write anywhere in it +as a binary file (without any data transformations the host system may +perform for text files). The file may be larger than 2GB. + +The alternate function <<_tmpfile64_r>> is a reentrant version. The +argument <[reent]> is a pointer to a reentrancy structure. + +Both <<tmpfile64>> and <<_tmpfile64_r>> are only defined if __LARGE64_FILES +is defined. + +RETURNS +<<tmpfile64>> normally returns a pointer to the temporary file. If no +temporary file could be created, the result is NULL, and <<errno>> +records the reason for failure. + +PORTABILITY +<<tmpfile64>> is a glibc extension. + +Supporting OS subroutines required: <<close>>, <<fstat>>, <<getpid>>, +<<isatty>>, <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>. + +<<tmpfile64>> also requires the global pointer <<environ>>. +*/ + +#include <stdio.h> +#include <errno.h> + +FILE * +_DEFUN (_tmpfile64_r, (ptr), + struct _reent *ptr) +{ + FILE *fp; + int e; + char *f; + char buf[L_tmpnam]; + + if ((f = _tmpnam_r (ptr, buf)) == NULL) + return NULL; + fp = fopen64 (f, "wb+"); + e = ptr->_errno; + _CAST_VOID remove (f); + ptr->_errno = e; + return fp; +} + +#ifndef _REENT_ONLY + +FILE * +_DEFUN_VOID (tmpfile64) +{ + return _tmpfile64_r (_REENT); +} + +#endif + +#endif /* __LARGE64_FILES */ + |