shithub: scc

ref: 27b4662757e3d9a500b69a96057cef8fdeacca99
dir: /lib/c/fopen.c/

View raw version

#include <errno.h>
#include <stdio.h>

#include "syscall.h"
#undef fopen


FILE *
fopen(const char * restrict name, const char * restrict mode)
{
	FILE *fp;

	for (fp = __iob; fp < &__iob[FOPEN_MAX]; ++fp) {
		if ((fp->flags & (_IOREAD | _IOWRITE | _IORW)) == 0)
			break;
	}
	if (fp == &__iob[FOPEN_MAX]) {
		errno = ENOMEM;
		return NULL;
	}
	return _fpopen(name, mode, fp);
}