Add fopen64/freopen64/tmpfile64 aliases.

Our fopen/freopen/tmpfile are already always O_LARGEFILE, but let's add
the aliases for _LARGEFILE_SOURCE compatibility.

Bug: http://b/24807045
Change-Id: I5d99b3ef3c9f27ce70f13313f6a92e96c7f21f80
This commit is contained in:
Elliott Hughes 2016-02-03 11:24:28 -08:00
parent a279324094
commit f226ee59e0
15 changed files with 55 additions and 4 deletions

View file

@ -112,3 +112,4 @@ FILE* tmpfile() {
}
return fp;
}
__strong_alias(tmpfile64, tmpfile);

View file

@ -109,14 +109,11 @@ int ferror(FILE *);
int fflush(FILE *);
int fgetc(FILE *);
char *fgets(char * __restrict, int, FILE * __restrict);
FILE *fopen(const char * __restrict , const char * __restrict);
int fprintf(FILE * __restrict , const char * __restrict, ...)
__printflike(2, 3);
int fputc(int, FILE *);
int fputs(const char * __restrict, FILE * __restrict);
size_t fread(void * __restrict, size_t, size_t, FILE * __restrict);
FILE *freopen(const char * __restrict, const char * __restrict,
FILE * __restrict);
int fscanf(FILE * __restrict, const char * __restrict, ...)
__scanflike(2, 3);
size_t fwrite(const void * __restrict, size_t, size_t, FILE * __restrict);
@ -140,7 +137,6 @@ void setbuf(FILE * __restrict, char * __restrict);
int setvbuf(FILE * __restrict, char * __restrict, int, size_t);
int sscanf(const char * __restrict, const char * __restrict, ...)
__scanflike(2, 3);
FILE *tmpfile(void);
int ungetc(int, FILE *);
int vfprintf(FILE * __restrict, const char * __restrict, __va_list)
__printflike(2, 0);
@ -208,6 +204,13 @@ FILE* funopen64(const void*,
int (*)(void*));
#endif
FILE* fopen(const char* __restrict, const char* __restrict);
FILE* fopen64(const char* __restrict, const char* __restrict);
FILE* freopen(const char* __restrict, const char* __restrict, FILE* __restrict);
FILE* freopen64(const char* __restrict, const char* __restrict, FILE* __restrict);
FILE* tmpfile(void);
FILE* tmpfile64(void);
#if __ISO_C_VISIBLE >= 1999 || __BSD_VISIBLE
int snprintf(char * __restrict, size_t, const char * __restrict, ...)
__printflike(3, 4);

View file

@ -1226,7 +1226,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1258,6 +1260,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1226,7 +1226,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1258,6 +1260,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1149,7 +1149,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1180,6 +1182,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1252,7 +1252,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1284,6 +1286,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1210,7 +1210,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1242,6 +1244,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1210,7 +1210,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1242,6 +1244,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1149,7 +1149,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1180,6 +1182,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1209,7 +1209,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1241,6 +1243,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1209,7 +1209,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1241,6 +1243,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -1149,7 +1149,9 @@ LIBC_N {
__write_chk;
fgetpos64;
fileno_unlocked;
fopen64;
freeifaddrs;
freopen64;
fseeko64;
fsetpos64;
ftello64;
@ -1180,6 +1182,7 @@ LIBC_N {
scandirat;
scandirat64;
strchrnul;
tmpfile64;
} LIBC;
LIBC_PRIVATE {

View file

@ -222,6 +222,7 @@ FILE* fopen(const char* file, const char* mode) {
return fp;
}
__strong_alias(fopen64, fopen);
FILE* fdopen(int fd, const char* mode) {
int oflags;
@ -358,6 +359,7 @@ FILE* freopen(const char* file, const char* mode, FILE* fp) {
if (oflags & O_APPEND) __sseek64(fp, 0, SEEK_END);
return fp;
}
__strong_alias(freopen64, freopen);
int fclose(FILE* fp) {
if (fp->_flags == 0) {

View file

@ -79,6 +79,7 @@ bsd_stuff = set([
'fgetln',
'fpurge',
'funopen',
'funopen64',
'gamma_r',
'gammaf_r',
'getprogname',

View file

@ -79,6 +79,12 @@ TEST(STDIO_TEST, tmpfile_fileno_fprintf_rewind_fgets) {
fclose(fp);
}
TEST(STDIO_TEST, tmpfile64) {
FILE* fp = tmpfile64();
ASSERT_TRUE(fp != nullptr);
fclose(fp);
}
TEST(STDIO_TEST, dprintf) {
TemporaryFile tf;
@ -875,6 +881,14 @@ TEST(STDIO_TEST, freopen_CLOEXEC) {
fclose(fp);
}
TEST(STDIO_TEST, fopen64_freopen64) {
FILE* fp = fopen64("/proc/version", "r");
ASSERT_TRUE(fp != nullptr);
fp = freopen64("/proc/version", "re", fp);
ASSERT_TRUE(fp != nullptr);
fclose(fp);
}
// https://code.google.com/p/android/issues/detail?id=81155
// http://b/18556607
TEST(STDIO_TEST, fread_unbuffered_pathological_performance) {