#define FILELIST_UNLOCK() do { pthread_mutex_unlock(&filelist_lock); } while(0)
static struct glue *
-moreglue(n)
- int n;
+moreglue(int n)
{
struct glue *g;
FILE *p;
struct __sFILEX *fx;
+ size_t align;
- g = (struct glue *)malloc(sizeof(*g) + ALIGNBYTES + n * sizeof(FILE) +
+ align = __alignof__( (struct { FILE f; struct __sFILEX s; }){} );
+ g = (struct glue *)malloc(sizeof(*g) + align + n * sizeof(FILE) +
n * sizeof(struct __sFILEX));
if (g == NULL)
return (NULL);
- p = (FILE *)ALIGN(g + 1);
+ p = (FILE *)roundup((uintptr_t)(g + 1), align);
fx = (struct __sFILEX *)&p[n];
g->next = NULL;
g->niobs = n;
pthread_once(&__sdidinit, __sinit);
if (count) {
- if (__scounted >= __stream_max) {
- errno = EMFILE;
- return NULL;
+ int32_t new = OSAtomicIncrement32(&__scounted);
+ if (new > __stream_max) {
+ if (new > (__stream_max = sysconf(_SC_STREAM_MAX))){
+ OSAtomicDecrement32(&__scounted);
+ errno = EMFILE;
+ return NULL;
+ }
}
- OSAtomicIncrement32(&__scounted);
}
/*
* The list must be locked because a FILE may be updated.
* The name `_cleanup' is, alas, fairly well known outside stdio.
*/
void
-_cleanup()
+_cleanup(void)
{
/* (void) _fwalk(fclose); */
(void) _fwalk(__sflush); /* `cheating' */
* __sinit() is called whenever stdio's internal variables must be set up.
*/
void
-__sinit()
+__sinit(void)
{
#if !TARGET_OS_EMBEDDED
int i;