shithub: riscv

ref: 2aec1f8a09ae0bc9fb269d84ef53defebc47eede
dir: /sys/src/libstdio/fopen.c/

View raw version
/*
 * pANS stdio -- fopen
 */
#include "iolib.h"
FILE *fopen(const char *name, const char *mode){
	FILE *f;
	qlock(&_stdiolk);
	for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) {
		if(f->state==CLOSED) {
			qunlock(&_stdiolk);
			return freopen(name, mode, f);
		}
	}
	qunlock(&_stdiolk);
	return NULL;
}