[444] | 1 | /* |
---|
| 2 | * Copyright (c) 1990 The Regents of the University of California. |
---|
| 3 | * All rights reserved. |
---|
| 4 | * |
---|
| 5 | * Redistribution and use in source and binary forms are permitted |
---|
| 6 | * provided that the above copyright notice and this paragraph are |
---|
| 7 | * duplicated in all such forms and that any documentation, |
---|
| 8 | * advertising materials, and other materials related to such |
---|
| 9 | * distribution and use acknowledge that the software was developed |
---|
| 10 | * by the University of California, Berkeley. The name of the |
---|
| 11 | * University may not be used to endorse or promote products derived |
---|
| 12 | * from this software without specific prior written permission. |
---|
| 13 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR |
---|
| 14 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
---|
| 15 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
---|
| 16 | */ |
---|
| 17 | |
---|
| 18 | /* |
---|
| 19 | FUNCTION |
---|
| 20 | <<fopen64>>---open a large file |
---|
| 21 | |
---|
| 22 | INDEX |
---|
| 23 | fopen64 |
---|
| 24 | INDEX |
---|
| 25 | _fopen64_r |
---|
| 26 | |
---|
| 27 | SYNOPSIS |
---|
| 28 | #include <stdio.h> |
---|
| 29 | FILE *fopen64(const char *<[file]>, const char *<[mode]>); |
---|
| 30 | FILE *_fopen64_r(void *<[reent]>, |
---|
| 31 | const char *<[file]>, const char *<[mode]>); |
---|
| 32 | |
---|
| 33 | DESCRIPTION |
---|
| 34 | <<fopen64>> is identical to <<fopen>> except it opens a large file that |
---|
| 35 | is potentially >2GB in size. See <<fopen>> for further details. |
---|
| 36 | |
---|
| 37 | RETURNS |
---|
| 38 | <<fopen64>> return a file pointer which you can use for other file |
---|
| 39 | operations, unless the file you requested could not be opened; in that |
---|
| 40 | situation, the result is <<NULL>>. If the reason for failure was an |
---|
| 41 | invalid string at <[mode]>, <<errno>> is set to <<EINVAL>>. |
---|
| 42 | |
---|
| 43 | PORTABILITY |
---|
| 44 | <<fopen64>> is a glibc extension. |
---|
| 45 | |
---|
| 46 | Supporting OS subroutines required: <<close>>, <<fstat64>>, <<isatty>>, |
---|
| 47 | <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>. |
---|
| 48 | */ |
---|
| 49 | |
---|
| 50 | /* Copied from fopen.c */ |
---|
| 51 | |
---|
| 52 | #if defined(LIBC_SCCS) && !defined(lint) |
---|
| 53 | static char sccsid[] = "%W% (Berkeley) %G%"; |
---|
| 54 | #endif /* LIBC_SCCS and not lint */ |
---|
| 55 | |
---|
| 56 | #include <stdio.h> |
---|
| 57 | #include <errno.h> |
---|
| 58 | #include "local.h" |
---|
| 59 | #ifdef __CYGWIN__ |
---|
| 60 | #include <fcntl.h> |
---|
| 61 | #endif |
---|
| 62 | #include <sys/lock.h> |
---|
| 63 | |
---|
| 64 | #ifdef __LARGE64_FILES |
---|
| 65 | |
---|
| 66 | FILE * |
---|
| 67 | _fopen64_r (struct _reent *ptr, |
---|
| 68 | const char *file, |
---|
| 69 | const char *mode) |
---|
| 70 | { |
---|
| 71 | register FILE *fp; |
---|
| 72 | register int f; |
---|
| 73 | int flags, oflags; |
---|
| 74 | |
---|
| 75 | if ((flags = __sflags (ptr, mode, &oflags)) == 0) |
---|
| 76 | return NULL; |
---|
| 77 | if ((fp = __sfp (ptr)) == NULL) |
---|
| 78 | return NULL; |
---|
| 79 | |
---|
| 80 | if ((f = _open64_r (ptr, file, oflags, 0666)) < 0) |
---|
| 81 | { |
---|
| 82 | _newlib_sfp_lock_start (); |
---|
| 83 | fp->_flags = 0; /* release */ |
---|
| 84 | #ifndef __SINGLE_THREAD__ |
---|
| 85 | __lock_close_recursive (fp->_lock); |
---|
| 86 | #endif |
---|
| 87 | _newlib_sfp_lock_end (); |
---|
| 88 | return NULL; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | _newlib_flockfile_start (fp); |
---|
| 92 | |
---|
| 93 | fp->_file = f; |
---|
| 94 | fp->_flags = flags; |
---|
| 95 | fp->_cookie = (void *) fp; |
---|
| 96 | fp->_read = __sread; |
---|
| 97 | fp->_write = __swrite64; |
---|
| 98 | fp->_seek = __sseek; |
---|
| 99 | fp->_seek64 = __sseek64; |
---|
| 100 | fp->_close = __sclose; |
---|
| 101 | |
---|
| 102 | if (fp->_flags & __SAPP) |
---|
| 103 | _fseeko64_r (ptr, fp, 0, SEEK_END); |
---|
| 104 | |
---|
| 105 | #ifdef __SCLE |
---|
| 106 | if (__stextmode (fp->_file)) |
---|
| 107 | fp->_flags |= __SCLE; |
---|
| 108 | #endif |
---|
| 109 | |
---|
| 110 | fp->_flags |= __SL64; |
---|
| 111 | |
---|
| 112 | _newlib_flockfile_end (fp); |
---|
| 113 | return fp; |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | #ifndef _REENT_ONLY |
---|
| 117 | |
---|
| 118 | FILE * |
---|
| 119 | fopen64 (const char *file, |
---|
| 120 | const char *mode) |
---|
| 121 | { |
---|
| 122 | return _fopen64_r (_REENT, file, mode); |
---|
| 123 | } |
---|
| 124 | |
---|
| 125 | #endif |
---|
| 126 | |
---|
| 127 | #endif /* __LARGE64_FILES */ |
---|