set	prototyped
iff	SFSTDIO
cat{
	#define __FILE_typedef	1

	#define stdin		sfstdin
	#define stdout		sfstdout
	#define stderr		sfstderr
	#define BUFSIZ		SF_BUFSIZE
	#ifndef FILE
	#ifndef _SFIO_H
	struct _sfio_s;
	#endif
	#define FILE		struct _sfio_s
	#endif
	#undef	fpos_t
	#define fpos_t		Sfoff_t
	#undef	fpos64_t
	#ifdef _ast_int8_t
	#define fpos64_t	Sfoff_t
	#endif

	#include <getopt.h>	/* to be dropped by Xopen -- we can't wait */

	#ifndef _SFIO_H
	#define _SFIO_H		1
	#if _WIN32
	#include <ast/sfio_t.h>
	#undef	_SFIO_H
	#include <ast/sfio.h>
	#else
	#include <sfio_t.h>
	#undef	_SFIO_H
	#include <sfio.h>
	#endif
	#endif

	#define _base		data
	#define _ptr		next
	#define _file		file
	#define _IOFBF		0
	#define _IONBF		1
	#define _IOLBF		2
}end
output{
	#include "limits.h"
	#ifndef FILENAME_MAX
	#define FILENAME_MAX	PATH_MAX
	#endif
	#ifndef FOPEN_MAX
	#define FOPEN_MAX	OPEN_MAX
	#endif
	#ifndef TMP_MAX
	#define TMP_MAX		33520641
	#endif
	main()
	{
		printf("#ifndef FILENAME_MAX\n");
		printf("#define FILENAME_MAX	%d\n", FILENAME_MAX);
		printf("#endif\n");
		printf("#ifndef FOPEN_MAX\n");
		printf("#define FOPEN_MAX	%d\n", FOPEN_MAX);
		printf("#endif\n");
		printf("#ifndef TMP_MAX\n");
		printf("#define TMP_MAX		%d\n", TMP_MAX);
		printf("#endif\n");
		return 0;
	}
}end
macro{
	#include "iffeio.h"
	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
	<<"__STDPP__directive pragma pp:initial">>
	<<"#endif">>
	<<"#ifndef P_tmpdir">>
	#ifndef P_tmpdir
	#define P_tmpdir "/usr/tmp/"
	#endif
	<<"#define P_tmpdir">> P_tmpdir <<"/*NOCATLITERAL*/">>
	<<"#endif">>
	<<"#ifndef L_ctermid">>
	#ifndef L_ctermid
	#define L_ctermid 9
	#endif
	<<"#define L_ctermid">> L_ctermid
	<<"#endif">>
	<<"#ifndef L_cuserid">>
	#ifndef L_cuserid
	#define L_cuserid 9
	#endif
	<<"#define L_cuserid">> L_cuserid
	<<"#endif">>
	<<"#ifndef L_tmpnam">>
	#ifndef L_tmpnam
	#define L_tmpnam (sizeof(P_tmpdir)+15)
	#endif
	<<"#define L_tmpnam">> L_tmpnam
	<<"#endif">>
	<<"#if defined(__STDPP__directive) && defined(__STDPP__initial)">>
	<<"__STDPP__directive pragma pp:noinitial">>
	<<"#endif">>
}end
cat{
	extern char*	ctermid(char*);
	extern char*	cuserid(char*);
	extern char*	tmpnam(char*);
	extern char*	tempnam(const char*, const char*);
	extern void	perror(const char*);
	#ifndef _AST_STD_H
	#ifndef remove
	extern int	remove(const char*);
	#endif
	#ifndef rename
	extern int	rename(const char*, const char*);
	#endif
	#endif

	#undef	extern

	#if _BLD_sfio && defined(__EXPORT__)
	#define extern		__EXPORT__
	#endif

	extern Sfio_t*	_stdopen(int, const char*);
	extern char*	_stdgets(Sfio_t*, char*, int n, int isgets);
	extern int	_stdprintf(const char*, ...);
	extern int	_stdsprintf(char*, const char*, ...);
	extern int	_stdscanf(const char*, ...);
	extern int	_stdsetvbuf(Sfio_t*, char*, int, size_t);

	#undef	extern

	#define _SFSIZEOF(s)	(sizeof(s) != sizeof(char*) ? sizeof(s) : BUFSIZ)

	#define	printf		_stdprintf
	#define sprintf		_stdsprintf
	#define fprintf		sfprintf
	#define snprintf	sfsprintf
	#define vfprintf	sfvprintf
	#define vsnprintf	sfvsprintf

	#define scanf		_stdscanf
	#define _doscan		sfvscanf
	#define sscanf		sfsscanf
	#define fscanf		sfscanf
	#define vfscanf		sfvscanf
	#define vsscanf		sfvsscanf

	#define fdopen		_stdopen
	#define setvbuf		_stdsetvbuf

	#define __sf_freopen(fl,m,f)	sfopen(f,fl,m)
	#define __sf_fopen(fl,m)	sfopen((Sfio_t*)0,fl,m)
	#define __sf_popen(cmd,m)	sfpopen((Sfio_t*)(-1),cmd,m)
	#define __sf_tmpfile()		sftmp(0)
	#define __sf_fclose(f)		sfclose(f)
	#define __sf_pclose(f)		sfclose(f)

	#define __sf_fwrite(p,s,n,f)	((_SF_(f)->val = sfwrite(f,p,(s)*(n))) <= 0 ? 0 : _SF_(f)->val/(s))
	#define __sf_putw(w,f)		(_SF_(f)->val = (int)(w), sfwrite(f,&_SF_(f)->val,sizeof(int)) <= 0 ? 1 : 0)
	#define __sf_fputc(c,f)		sfputc(f,c)
	#define __sf_putchar(c)		sfputc(sfstdout,c)
	#define __sf_fputs(s,f)		sfputr(f,s,-1)
	#define __sf_puts(s)		sfputr(sfstdout,s,'\n')
	#define __sf_vprintf(fmt,a)	sfvprintf(sfstdout,fmt,a)
	#define __sf_doprnt(fmt,a,f)	sfvprintf(f,fmt,a)
	#define __sf_vsprintf(s,fmt,a)	sfvsprintf(s,_SFSIZEOF(s),fmt,a)

	#define __sf_fread(p,s,n,f)	((_SF_(f)->val = sfread(f,p,(s)*(n))) <= 0 ? 0 : _SF_(f)->val/(s))
	#define __sf_getw(f)		(sfread(f,&_SF_(f)->val,sizeof(int)) == sizeof(int) ? _SF_(f)->val : -1)
	#define __sf_fgetc(f)		sfgetc(f)
	#define __sf_getchar()		sfgetc(sfstdin)
	#define __sf_ungetc(c,f)	sfungetc(f,c)
	#define __sf_fgets(s,n,f)	_stdgets(f,s,n,0)
	#define __sf_gets(s)		_stdgets(sfstdin,s,_SFSIZEOF(s),1)
	#define __sf_vscanf(fmt,a)	sfvscanf(sfstdin,fmt,a)

	#define __sf_fflush(f)		(sfseek(f,(Sfoff_t)0,SEEK_CUR|SF_PUBLIC),((sfsync(f)||sfpurge(f)) ? -1 : 0))
	#define __sf_fpurge(f)		sfpurge(f)
	#define __sf_fseek(f,o,t)	(sfseek(f,(Sfoff_t)(o),(t)|SF_SHARE) < 0 ? -1 : 0)
	#define __sf_rewind(f)		(__sf_clearerr(f),__sf_fseek(f,(Sfoff_t)0,SEEK_SET))
	#define __sf_ftell(f)		(long)sfseek(f,(Sfoff_t)0,SEEK_CUR)
	#define __sf_fgetpos(f,p)	((*(p) = (fpos_t)sfseek(f,(Sfoff_t)0,SEEK_CUR)) >= 0 ? 0 : -1)
	#define __sf_fsetpos(f,p)	(*(p) == (fpos_t)sfseek(f,(Sfoff_t)(*(p)),SEEK_SET|SF_SHARE) ? 0 : -1)
	#define __sf_setbuf(f,b)	(void)sfsetbuf(f,b,(b)?BUFSIZ:0)
	#define __sf_setbuffer(f,b,n)	(sfsetbuf(f,b,n) ? 0 : -1)
	#define __sf_setlinebuf(f)	sfset(f,SF_LINE,1)

	#define __sf_feof(f)		sfeof(f)
	#define __sf_ferror(f)		sferror(f)
	#define __sf_clearerr(f)	(void)(sfclrerr(f),sfclrlock(f))

	#ifdef fpos64_t

	#define __sf_fseek64(f,o,t)	(sfseek(f,(Sfoff_t)(o),(t)|SF_SHARE) < 0 ? -1 : 0)
	#define __sf_ftell64(f)		(fpos64_t)sfseek(f,(Sfoff_t)0,SEEK_CUR)
	#define __sf_fgetpos64(f,p)	((*(p) = (fpos64_t)sfseek(f,(Sfoff_t)0,SEEK_CUR)) >= 0 ? 0 : -1)
	#define __sf_fsetpos64(f,p)	(*(p) == (fpos64_t)sfseek(f,(Sfoff_t)*(p),SEEK_SET|SF_SHARE) ? 0 : -1)

	#endif

	#if defined(__INLINE__) && !defined(_SFHDR_H)

	__INLINE__ FILE* fopen(const char* f, const char* m)
		{ return __sf_fopen(f,m); }
	__INLINE__ FILE* freopen(const char* f, const char* m, FILE* p)
		{ return __sf_freopen(f,m,p); }
	__INLINE__ FILE* popen(const char* cmd, const char* m)
		{ return __sf_popen(cmd,m); }
	__INLINE__ FILE* tmpfile(void)
		{ return __sf_tmpfile(); }
	__INLINE__ int fclose(FILE* f)
		{ return __sf_fclose(f); }
	__INLINE__ int pclose(FILE* f)
		{ return __sf_pclose(f); }

	__INLINE__ size_t fwrite(const void* p, size_t s, size_t n, FILE* f)
		{ return __sf_fwrite(p,s,n,f); }
	__INLINE__ int putw(int w, FILE* f)
		{ return __sf_putw(w,f); }
	__INLINE__ int fputc(int c, FILE* f)
		{ return __sf_fputc(c,f); }
	__INLINE__ int putc(int c, FILE* f)
		{ return __sf_fputc(c,f); }
	__INLINE__ int putchar(int c)
		{ return __sf_putchar(c); }
	__INLINE__ int fputs(const char* s, FILE* f)
		{ return __sf_fputs(s,f); }
	__INLINE__ int puts(const char* s)
		{ return __sf_puts(s); }
	__INLINE__ int vprintf(const char* fmt, _ast_va_list a)
		{ return __sf_vprintf(fmt,a); }
	__INLINE__ int _doprnt(const char* fmt, _ast_va_list a, FILE* f)
		{ return __sf_doprnt(fmt,a,f); }
	__INLINE__ int vsprintf(char* s, const char* fmt, _ast_va_list a)
		{ return __sf_vsprintf(s,fmt,a); }

	__INLINE__ size_t fread(void* p, size_t s, size_t n, FILE* f)
		{ return __sf_fread(p,s,n,f); }
	__INLINE__ int getw(FILE* f)
		{ return __sf_getw(f); }
	__INLINE__ int fgetc(FILE* f)
		{ return __sf_fgetc(f); }
	__INLINE__ int getc(FILE* f)
		{ return __sf_fgetc(f); }
	__INLINE__ int getchar()
		{ return __sf_getchar(); }
	__INLINE__ int ungetc(int c, FILE* f)
		{ return __sf_ungetc(c,f); }
	__INLINE__ char* fgets(char* s, int n, FILE* f)
		{ return __sf_fgets(s,n,f); }
	__INLINE__ char* gets(char* s)
		{ return __sf_gets(s); }
	__INLINE__ int vscanf(const char* fmt, _ast_va_list a)
		{ return __sf_vscanf(fmt,a); }

	__INLINE__ int fflush(FILE* f)
		{ return __sf_fflush(f); }
	__INLINE__ int fpurge(FILE* f)
		{ return __sf_fpurge(f); }
	__INLINE__ int fseek(FILE* f, long o, int t)
		{ return __sf_fseek(f,o,t); }
	__INLINE__ void rewind(FILE* f)
		{ (void) __sf_rewind(f); }
	__INLINE__ long ftell(FILE* f)
		{ return __sf_ftell(f); }
	__INLINE__ int fgetpos(FILE* f, fpos_t* p)
		{ return __sf_fgetpos(f,p); }
	__INLINE__ int fsetpos(FILE* f, fpos_t* p)
		{ return __sf_fsetpos(f,p); }
	__INLINE__ void setbuf(FILE* f, char* b)
		{ (void) __sf_setbuf(f,b); }
	__INLINE__ int setbuffer(FILE* f, char* b, int n)
		{ return __sf_setbuffer(f,b,n); }
	__INLINE__ int setlinebuf(FILE* f)
		{ return __sf_setlinebuf(f); }

	__INLINE__ int fileno(FILE* f)
		{ return __sf_fileno(f); }
	__INLINE__ int feof(FILE* f)
		{ return __sf_eof(f); }
	__INLINE__ int ferror(FILE* f)
		{ return __sf_error(f); }
	__INLINE__ void clearerr(FILE* f)
		{ (void) __sf_clearerr(f); }


	#ifdef fpos64_t

	__INLINE__ int fseek64(FILE* f, fpos64_t o, int t)
		{ return __sf_fseek64(f,o,t); }
	__INLINE__ fpos64_t ftell64(FILE* f)
		{ return (fpos64_t)__sf_ftell64(f); }
	__INLINE__ int fgetpos64(FILE* f, fpos64_t* p)
		{ return __sf_fgetpos64(f,p); }
	__INLINE__ int fsetpos64(FILE* f, fpos64_t* p)
		{ return __sf_fsetpos64(f,p); }

	#endif

	#else

	#define freopen(f,m,p)	( __sf_freopen(f,m,p) )
	#define fopen(f,m)	( __sf_fopen(f,m) )
	#define popen(cmd,m)	( __sf_popen(cmd,m) )
	#define tmpfile()	( __sf_tmpfile() )
	#define fclose(f)	( __sf_fclose(f) )
	#define pclose(f)	( __sf_pclose(f) )

	#define fwrite(p,s,n,f)	( __sf_fwrite(p,s,n,f) )
	#define putw(w,f)	( __sf_putw(w,f) )
	#define fputc(c,f)	( __sf_fputc(c,f) )
	#define putc(c,f)	( __sf_fputc(c,f) )
	#define putchar(c)	( __sf_putchar(c) )
	#define fputs(s,f)	( __sf_fputs(s,f) )
	#define puts(s)		( __sf_puts(s) )
	#define vprintf(fmt,a)	( __sf_vprintf(fmt,a) )
	#define vsprintf(s,f,a)	( __sf_vsprintf(s,f,a) )
	#define _doprnt(fmt,a,f) ( __sf_doprnt(fmt,a,f) )

	#define fread(p,s,n,f)	( __sf_fread(p,s,n,f) )
	#define fgetc(f)	( __sf_fgetc(f) )
	#define getw(f)		( __sf_fgetw(f) )
	#define getc(f)		( __sf_fgetc(f) )
	#define getchar()	( __sf_getchar() )
	#define ungetc(c,f)	( __sf_ungetc(c,f) )
	#define fgets(s,n,f)	( __sf_fgets(s,n,f) )
	#define gets(s)		( __sf_gets(s) )
	#define vscanf(fmt,a)	( __sf_vscanf(fmt,a) )

	#define fflush(f)	( __sf_fflush(f) )
	#define fpurge(f)	( __sf_fpurge(f) )
	#define fseek(f,o,t)	( __sf_fseek(f,o,t) )
	#define rewind(f)	( __sf_rewind(f) )
	#define ftell(f)	( __sf_ftell(f) )
	#define fgetpos(f,p)	( __sf_fgetpos(f,p) )
	#define fsetpos(f,p)	( __sf_fsetpos(f,p) )
	#define setbuf(f,b)	( __sf_setbuf(f,b) )
	#define setbuffer(f,b,n) ( __sf_setbuffer(f,b,n) )
	#define setlinebuf(f)	( __sf_setlinebuf(f) )

	#define fileno(f)	( __sf_fileno(f) )
	#define feof(f)		( __sf_feof(f) )
	#define ferror(f)	( __sf_ferror(f) )
	#define clearerr(f)	( __sf_clearerr(f) )

	#ifdef fpos64_t

	#define fseek64(f,o,t)	( __sf_fseek64(f,o,t) )
	#define ftell64(f)	( __sf_ftell64(f) )
	#define fgetpos64(f,p)	( __sf_fgetpos64(f,p) )
	#define fsetpos64(f,p)	( __sf_fsetpos64(f,p) )

	#endif

	#endif
}end
