Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / stdio64 / fopen64.c
blob75d2c2c415f52d052ca0d1aae07f11ef4926573d
1 /*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
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 * and/or 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.
19 FUNCTION
20 <<fopen64>>---open a large file
22 INDEX
23 fopen64
24 INDEX
25 _fopen64_r
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]>);
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.
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>>.
43 PORTABILITY
44 <<fopen64>> is a glibc extension.
46 Supporting OS subroutines required: <<close>>, <<fstat64>>, <<isatty>>,
47 <<lseek64>>, <<open64>>, <<read>>, <<sbrk>>, <<write>>.
50 /* Copied from fopen.c */
52 #if defined(LIBC_SCCS) && !defined(lint)
53 static char sccsid[] = "%W% (Berkeley) %G%";
54 #endif /* LIBC_SCCS and not lint */
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>
64 #ifdef __LARGE64_FILES
66 FILE *
67 _fopen64_r (struct _reent *ptr,
68 const char *file,
69 const char *mode)
71 register FILE *fp;
72 register int f;
73 int flags, oflags;
75 if ((flags = __sflags (ptr, mode, &oflags)) == 0)
76 return NULL;
77 if ((fp = __sfp (ptr)) == NULL)
78 return NULL;
80 if ((f = _open64_r (ptr, file, oflags, 0666)) < 0)
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;
91 _newlib_flockfile_start (fp);
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;
102 if (fp->_flags & __SAPP)
103 _fseeko64_r (ptr, fp, 0, SEEK_END);
105 #ifdef __SCLE
106 if (__stextmode (fp->_file))
107 fp->_flags |= __SCLE;
108 #endif
110 fp->_flags |= __SL64;
112 _newlib_flockfile_end (fp);
113 return fp;
116 #ifndef _REENT_ONLY
118 FILE *
119 fopen64 (const char *file,
120 const char *mode)
122 return _fopen64_r (_REENT, file, mode);
125 #endif
127 #endif /* __LARGE64_FILES */