Merge "Remove dlmalloc."
diff --git a/libc/stdio/local.h b/libc/stdio/local.h
index 7188c74..a4c0264 100644
--- a/libc/stdio/local.h
+++ b/libc/stdio/local.h
@@ -92,6 +92,15 @@
/* Unix stdio files get aligned to block boundaries on fseek() */
int _blksize; /* stat.st_blksize (may be != _bf._size) */
+
+ fpos_t _unused_0; // This was the `_offset` field (see below).
+
+ // Do not add new fields here. (Or remove or change the size of any above.)
+ // Although bionic currently exports `stdin`, `stdout`, and `stderr` symbols,
+ // that still hasn't made it to the NDK. All NDK-built apps index directly
+ // into an array of this struct (which was in <stdio.h> historically), so if
+ // you need to make any changes, they need to be in the `__sfileext` struct
+ // below, and accessed via `_EXT`.
};
/*
diff --git a/libc/stdio/stdio.cpp b/libc/stdio/stdio.cpp
index 1066d7f..7e9c439 100644
--- a/libc/stdio/stdio.cpp
+++ b/libc/stdio/stdio.cpp
@@ -52,7 +52,7 @@
#define std(flags, file) \
{0,0,0,flags,file,{0,0},0,__sF+file,__sclose,__sread,__sseek,__swrite, \
- {(unsigned char *)(__sFext+file), 0},NULL,0,{0},{0},{0,0},0}
+ {(unsigned char *)(__sFext+file), 0},NULL,0,{0},{0},{0,0},0,0}
_THREAD_PRIVATE_MUTEX(__sfp_mutex);
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 31acfec..a7df784 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -1093,3 +1093,31 @@
fclose(fp);
#endif
}
+
+TEST(STDIO_TEST, lots_of_concurrent_files) {
+ std::vector<TemporaryFile*> tfs;
+ std::vector<FILE*> fps;
+
+ for (size_t i = 0; i < 256; ++i) {
+ TemporaryFile* tf = new TemporaryFile;
+ tfs.push_back(tf);
+ FILE* fp = fopen(tf->filename, "w+");
+ fps.push_back(fp);
+ fprintf(fp, "hello %zu!\n", i);
+ fflush(fp);
+ }
+
+ for (size_t i = 0; i < 256; ++i) {
+ rewind(fps[i]);
+
+ char buf[BUFSIZ];
+ ASSERT_TRUE(fgets(buf, sizeof(buf), fps[i]) != nullptr);
+
+ char expected[BUFSIZ];
+ snprintf(expected, sizeof(expected), "hello %zu!\n", i);
+ ASSERT_STREQ(expected, buf);
+
+ fclose(fps[i]);
+ delete tfs[i];
+ }
+}