Plan 9 from Bell Labs’s /usr/web/sources/patch/ape-erik/_IO_newfile.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


/*
 * pANS stdio -- fopen
 */
#include "iolib.h"

#define _PLAN9_SOURCE
#include <lock.h>

FILE *_IO_newfile(void)
{
	static FILE *fx=0;
	static Lock fl;
	FILE *f;
	int i;

	lock(&fl);
	for(i=0; i<FOPEN_MAX; i++){
		if(fx==0 || ++fx >= &_IO_stream[FOPEN_MAX]) fx=_IO_stream;
		if(fx->state==CLOSED)
			break;
	}
	f = fx;
	unlock(&fl);
	if(f->state!=CLOSED)
		return NULL;
	return f;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.