################################################################
## Need to hide certain names such as _doprnt, _doscan
################################################################

#pragma weak note{ compile system supports symbol transform }end link{
#	main() { return _xyz(); }
#	#pragma weak   _xyz =  __xyz
#	#define                _xyz    __xyz
#	_xyz() { return 0; }
#}end

################################################################
## To emulate old-style stdio at binary level
################################################################

tst - output{
	#include	<stdio.h>
	main() { printf("#define _siz_fpos_t	%d\\n", sizeof(fpos_t)); exit(0); }
}end

FILE _cnt note{ field FILE.__cnt exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->__cnt == 0) ? 0 : -1; }
}end
FILE _ptr note{ field FILE.__ptr exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->__ptr == 0) ? 0 : -1; }
}end
FILE _file note{ field FILE.__file exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->__file == 0) ? 0 : -1; }
}end
FILE _flag note{ field FILE.__flag exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->__flag == 0) ? 0 : -1; }
}end

FILE cnt note{ field FILE._cnt exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->_cnt == 0) ? 0 : -1; }
}end
FILE ptr note{ field FILE._ptr exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->_ptr == 0) ? 0 : -1; }
}end
FILE file note{ field FILE._file exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->_file == 0) ? 0 : -1; }
}end
FILE flag note{ field FILE._flag exists }end compile{
	#include	<stdio.h>
	main() { return (stdin->_flag == 0) ? 0 : -1; }
}end

cat{
	#if _FILE__cnt && ! _FILE_cnt
	#define _FILE_cnt	1
	#define _cnt		__cnt
	#endif
	#if _FILE__ptr && ! _FILE_ptr
	#define _FILE_ptr	1
	#define _ptr		__ptr
	#endif
	#if _FILE__flag && ! _FILE_flag
	#define _FILE_flag	1
	#define _flag		__flag
	#endif
	#if _FILE__file && ! _FILE_file
	#define _FILE_file	1
	#define _file		__file
	#endif
}end

############################################################################
# To emulate Linux-stdio at binary level
############################################################################
FILE readptr note{ fields FILE._IO_read_ptr/end exist }end execute{
	#include	<stdio.h>
	main()
	{ if(sizeof(stdin->_IO_read_ptr) != sizeof(char*) ) return 1;
	  if(sizeof(stdin->_IO_read_end) != sizeof(char*) ) return 1;
	  return 0;
	}
}end
FILE writeptr note{ fields FILE._IO_write_ptr/end exist }end execute{
	#include	<stdio.h>
	main()
	{ if(sizeof(stdin->_IO_write_ptr) != sizeof(char*) ) return 1;
	  if(sizeof(stdin->_IO_write_end) != sizeof(char*) ) return 1;
	  return 0;
	}
}end
FILE flags note{ field FILE._flags exists }end compile{
	#include	<stdio.h>
	main()
	{ return stdin->_flags == 0 ? 1 : 0;
	}
}end
FILE fileno note{ field FILE._fileno exists }end compile{
	#include	<stdio.h>
	main()
	{ return stdin->_fileno == 0 ? 1 : 0;
	}
}end
u flow note{ uflow() does bump buffer }end excute{
	#include	<stdio.h>
        #if _STD_
        main(int argc, char** argv)
        #else
        main(argc,argv)
        int     argc;
        char**  argv;
        #endif
	{ FILE*	f;
	  char	file[BUFSIZ];
	  sprintf(file,"%s.D",argv[0]);
	  if(!(f = fopen(file,"w+")) )
		exit(1);
	  unlink(file);
	  setbuf(f,file);
	  fputs("123456789",f);
	  fseek(f,0L,0);
	  if(__uflow(f) == EOF)
		exit(1);
	  if(*f->_IO_read_ptr == '1')
		exit(1);
	  else	exit(0);
	}
}end
under flow note{ underflow() does not bump buffer }end excute{
	#include	<stdio.h>
        #if _STD_
        main(int argc, char** argv)
        #else
        main(argc,argv)
        int     argc;
        char**  argv;
        #endif
	{ FILE*	f;
	  char	file[BUFSIZ];
	  sprintf(file,"%s.D",argv[0]);
	  if(!(f = fopen(file,"w+")) )
		exit(1);
	  unlink(file);
	  setbuf(f,file);
	  fputs("123456789",f);
	  fseek(f,0L,0);
	  if(__underflow(f) == EOF)
		exit(1);
	  if(*f->_IO_read_ptr == '1')
		exit(0);
	  else	exit(1);
	}
}end

######################################################################
# To emulate BSD-style stdio
######################################################################
FILE p	note{ FILE._p field }end compile{
	#include <stdio.h>
	main() { return stdin->_p == 0 ? 0 : 1; }
}end
FILE r	note{ FILE._r field }end compile{
	#include <stdio.h>
	main() { return stdin->_r == 0 ? 0 : 1; }
}end
FILE w	note{ FILE._w field }end compile{
	#include <stdio.h>
	main() { return stdout->_w == 0 ? 0 : 1; }
}end

lib __swbuf
lib __srget

lib __uflow
lib __underflow
lib __overflow

lib _IO_getc
lib _IO_putc
