+/* PL_perlio_fd_refcnt[] is in intrpvar.h */
+
+/* Must be called with PL_perlio_mutex locked. */
+static void
+S_more_refcounted_fds(pTHX_ const int new_fd) {
+ dVAR;
+ const int old_max = PL_perlio_fd_refcnt_size;
+ const int new_max = 16 + (new_fd & ~15);
+ int *new_array;
+
+ PerlIO_debug("More fds - old=%d, need %d, new=%d\n",
+ old_max, new_fd, new_max);
+
+ if (new_fd < old_max) {
+ return;
+ }
+
+ assert (new_max > new_fd);
+
+ /* Use plain realloc() since we need this memory to be really
+ * global and visible to all the interpreters and/or threads. */
+ new_array = (int*) realloc(PL_perlio_fd_refcnt, new_max * sizeof(int));
+
+ if (!new_array) {
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&PL_perlio_mutex);