Plan 9 from Bell Labs’s /usr/web/sources/contrib/yk/dist/9legacy/applied/stdio-fixes.diff

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


--- /n/sources/plan9/sys/include/stdio.h	Thu Jul 21 20:19:15 2005
+++ /sys/include/stdio.h	Fri Aug 26 00:00:00 2016
@@ -2,117 +2,123 @@
 #pragma	lib	"libstdio.a"
 
 /*
- * pANS astdio.h
+ * pANS stdio.h
  */
 /*
  * According to X3J11, there is only one i/o buffer
  * and it must not be occupied by both input and output data.
- *	If rp<wp, we must have state==RD and
- *	if wp<rp, we must have state==WR, so that getc and putc work correctly.
- *	On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
- *	or _IO_putc, which will allocate the buffer.
- *	If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
- *	buf, rp and wp are pointed at unbuf.
- *	If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
- *	end of the buffer so that it can be called on each putc to check whether it's got
- *	a newline.  This nonsense is in order to avoid impacting performance of the other
- *	buffering modes more than necessary -- putting the test in putc adds many
- *	instructions that are wasted in non-_IOLBF mode:
- *	#define putc(c, f)	(_IO_ctmp=(c),\
- *				(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
- *					?_IO_putc(_IO_ctmp, f)\
- *					:*(f)->wp++=_IO_ctmp)
- *				
+ *
+ * If rp<wp, we must have state==RD and
+ * if wp<rp, we must have state==WR, so that getc and putc work correctly.
+ * On open, rp, wp and buf are set to 0, so first getc or putc will call
+ * _IO_getc or _IO_putc, which will allocate the buffer.
+ * If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
+ * buf, rp and wp are pointed at unbuf.
+ * If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at
+ * the end of the buffer so that it can be called on each putc to check whether
+ * it's got a newline.  This nonsense is in order to avoid impacting performance
+ * of the other buffering modes more than necessary -- putting the test in putc
+ * adds many instructions that are wasted in non-_IOLBF mode:
+ * #define putc(c, f) (_IO_ctmp=(c),\
+ * 		(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'?\
+ * 		_IO_putc(_IO_ctmp, f): *(f)->wp++=_IO_ctmp)
  */
 typedef struct{
 	int fd;		/* UNIX file pointer */
 	char flags;	/* bits for must free buffer on close, line-buffered */
 	char state;	/* last operation was read, write, position, error, eof */
-	char *buf;	/* pointer to i/o buffer */
-	char *rp;	/* read pointer (or write end-of-buffer) */
-	char *wp;	/* write pointer (or read end-of-buffer) */
-	char *lp;	/* actual write pointer used when line-buffering */
+	unsigned char *buf;	/* pointer to i/o buffer */
+	unsigned char *rp;	/* read pointer (or write end-of-buffer) */
+	unsigned char *wp;	/* write pointer (or read end-of-buffer) */
+	unsigned char *lp;	/* actual write pointer used when line-buffering */
 	long bufl;	/* actual length of buffer */
-	char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
+	unsigned char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
+	int	junk;
 }FILE;
-typedef long fpos_t;
+
+typedef long long fpos_t;
+
 #ifndef NULL
 #define	NULL	((void*)0)
 #endif
+
 /*
  * Third arg of setvbuf
  */
 #define	_IOFBF	1			/* block-buffered */
 #define	_IOLBF	2			/* line-buffered */
 #define	_IONBF	3			/* unbuffered */
-#define	BUFSIZ	4096			/* size of setbuf buffer */
+
+#define	BUFSIZ	8192			/* size of setbuf buffer */
 #define	EOF	(-1)			/* returned on end of file */
-#define	FOPEN_MAX	100		/* max files open */
+#define	FOPEN_MAX	128		/* max files open */
 #define	FILENAME_MAX	BUFSIZ		/* silly filename length */
 #define	L_tmpnam	20		/* sizeof "/tmp/abcdefghij9999 */
-#ifndef SEEK_SET			/* also defined in unistd.h */
 #define	SEEK_CUR	1
 #define	SEEK_END	2
 #define	SEEK_SET	0
-#endif
 #define	TMP_MAX		64		/* very hard to set correctly */
+
 #define	stderr	(&_IO_stream[2])
 #define	stdin	(&_IO_stream[0])
 #define	stdout	(&_IO_stream[1])
-#define	_IO_CHMASK	0377		/* mask for 8 bit characters */
-FILE *tmpfile(void);
-char *tmpnam(char *);
-int fclose(FILE *);
-int fflush(FILE *);
-FILE *fopen(const char *, const char *);
-FILE *fdopen(const int, const char *);
-FILE *freopen(const char *, const char *, FILE *);
-void setbuf(FILE *, char *);
-int setvbuf(FILE *, char *, int, long);
-int fprintf(FILE *, const char *, ...);
-int fscanf(FILE *, const char *, ...);
-int printf(const char *, ...);
-int scanf(const char *, ...);
-int sprintf(char *, const char *, ...);
-int snprintf(char *, int, const char *, ...);
-int sscanf(const char *, const char *, ...);
-int vfprintf(FILE *, const char *, va_list);
-int vprintf(const char *, va_list);
-int vsprintf(char *, const char *, va_list);
-int vsnprintf(char *, int, const char *, va_list);
-int vfscanf(FILE *, const char *, va_list);
-int fgetc(FILE *);
-char *fgets(char *, int, FILE *);
-int fputc(int, FILE *);
-int fputs(const char *, FILE *);
-int getc(FILE *);
-#define	getc(f)	((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
-int _IO_getc(FILE *f);
-int getchar(void);
+
+extern FILE _IO_stream[FOPEN_MAX];
+
+int	_IO_getc(FILE *f);
+int	_IO_putc(int, FILE *);
+void	clearerr(FILE *);
+int	fclose(FILE *);
+FILE	*fdopen(const int, const char *);
+int	feof(FILE *);
+int	ferror(FILE *);
+int	fflush(FILE *);
+int	fgetc(FILE *);
+int	fgetpos(FILE *, fpos_t *);
+char	*fgets(char *, int, FILE *);
+int	fileno(FILE *);
+FILE	*fopen(const char *, const char *);
+int	fprintf(FILE *, const char *, ...);
+int	fputc(int, FILE *);
+int	fputs(const char *, FILE *);
+long	fread(void *, long, long, FILE *);
+FILE	*freopen(const char *, const char *, FILE *);
+int	fscanf(FILE *, const char *, ...);
+int	fseek(FILE *, long, int);
+int	fseeko(FILE *, long long, int);
+int	fsetpos(FILE *, const fpos_t *);
+long	ftell(FILE *);
+long long ftello(FILE *);
+long	fwrite(const void *, long, long, FILE *);
+int	getc(FILE *);
+#define	getc(f)	((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++)
+int	getchar(void);
 #define	getchar()	getc(stdin)
-char *gets(char *);
-int putc(int, FILE *);
-#define	putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
-int _IO_putc(int, FILE *);
-int putchar(int);
+char	*gets(char *);
+void	perror(const char *);
+int	printf(const char *, ...);
+int	putc(int, FILE *);
+/*	assignment to f->junk eliminates warnings about unused result of operation */
+#define	putc(c, f) ((f)->junk = ((f)->wp>=(f)->rp? \
+	_IO_putc(c, f): (*(f)->wp++ = (c))))
+int	putchar(int);
 #define	putchar(c)	putc(c, stdout)
-int puts(const char *);
-int ungetc(int, FILE *);
-long fread(void *, long, long, FILE *);
-long fwrite(const void *, long, long, FILE *);
-int fgetpos(FILE *, fpos_t *);
-int fseek(FILE *, long, int);
-int fseeko(FILE *, long long, int);
-int fsetpos(FILE *, const fpos_t *);
-long ftell(FILE *);
-long long ftello(FILE *);
-void rewind(FILE *);
-void clearerr(FILE *);
-int feof(FILE *);
-int ferror(FILE *);
-void perror(const char *);
-extern FILE _IO_stream[FOPEN_MAX];
-FILE *sopenr(const char *);
-FILE *sopenw(void);
-char *sclose(FILE *);
-int fileno(FILE *);
+int	puts(const char *);
+void	rewind(FILE *);
+int	scanf(const char *, ...);
+char	*sclose(FILE *);
+void	setbuf(FILE *, void *);
+int	setvbuf(FILE *, void *, int, long);
+int	snprintf(char *, int, const char *, ...);
+FILE	*sopenr(const char *);
+FILE	*sopenw(void);
+int	sprintf(char *, const char *, ...);
+int	sscanf(const char *, const char *, ...);
+FILE	*tmpfile(void);
+char	*tmpnam(char *);
+int	ungetc(int, FILE *);
+int	vfprintf(FILE *, const char *, va_list);
+int	vfscanf(FILE *, const char *, va_list);
+int	vprintf(const char *, va_list);
+int 	vsnprintf(char *, int, const char *, va_list);
+int	vsprintf(char *, const char *, va_list);
--- /n/sources/plan9/sys/include/ape/stdio.h	Wed May 29 02:38:29 2013
+++ /sys/include/ape/stdio.h	Sun Aug 28 00:00:00 2016
@@ -11,35 +11,37 @@
 /*
  * According to X3J11, there is only one i/o buffer
  * and it must not be occupied by both input and output data.
- *	If rp<wp, we must have state==RD and
- *	if wp<rp, we must have state==WR, so that getc and putc work correctly.
- *	On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
- *	or _IO_putc, which will allocate the buffer.
- *	If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
- *	buf, rp and wp are pointed at unbuf.
- *	If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
- *	end of the buffer so that it can be called on each putc to check whether it's got
- *	a newline.  This nonsense is in order to avoid impacting performance of the other
- *	buffering modes more than necessary -- putting the test in putc adds many
- *	instructions that are wasted in non-_IOLBF mode:
- *	#define putc(c, f)	(_IO_ctmp=(c),\
- *				(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
- *					?_IO_putc(_IO_ctmp, f)\
- *					:*(f)->wp++=_IO_ctmp)
- *				
+ *
+ * If rp<wp, we must have state==RD and
+ * if wp<rp, we must have state==WR, so that getc and putc work correctly.
+ * On open, rp, wp and buf are set to 0, so first getc or putc will call
+ * _IO_getc or _IO_putc, which will allocate the buffer.
+ * If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
+ * buf, rp and wp are pointed at unbuf.
+ * If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at
+ * the end of the buffer so that it can be called on each putc to check whether
+ * it's got a newline.  This nonsense is in order to avoid impacting performance
+ * of the other buffering modes more than necessary -- putting the test in putc
+ * adds many instructions that are wasted in non-_IOLBF mode:
+ * #define putc(c, f) (_IO_ctmp=(c),\
+ * 		(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'?\
+ * 		_IO_putc(_IO_ctmp, f): *(f)->wp++=_IO_ctmp)
  */
 typedef struct{
 	int fd;		/* UNIX file pointer */
 	char flags;	/* bits for must free buffer on close, line-buffered */
 	char state;	/* last operation was read, write, position, error, eof */
-	char *buf;	/* pointer to i/o buffer */
-	char *rp;	/* read pointer (or write end-of-buffer) */
-	char *wp;	/* write pointer (or read end-of-buffer) */
-	char *lp;	/* actual write pointer used when line-buffering */
+	unsigned char *buf;	/* pointer to i/o buffer */
+	unsigned char *rp;	/* read pointer (or write end-of-buffer) */
+	unsigned char *wp;	/* write pointer (or read end-of-buffer) */
+	unsigned char *lp;	/* actual write pointer used when line-buffering */
 	size_t bufl;	/* actual length of buffer */
-	char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
+	unsigned char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
+	int	junk;
 }FILE;
-typedef long long fpos_t;
+
+typedef off_t fpos_t;
+
 #ifndef NULL
 #ifdef __cplusplus
 #define NULL 0
@@ -47,107 +49,115 @@
 #define NULL ((void*)0)
 #endif
 #endif
+
 /*
  * Third arg of setvbuf
  */
 #define	_IOFBF	1			/* block-buffered */
 #define	_IOLBF	2			/* line-buffered */
 #define	_IONBF	3			/* unbuffered */
-#define	BUFSIZ	4096			/* size of setbuf buffer */
+
+#define	BUFSIZ	8192			/* size of setbuf buffer */
 #define	EOF	(-1)			/* returned on end of file */
-#define	FOPEN_MAX	90		/* max files open */
+#define	FOPEN_MAX	128		/* max files open */
 #define	FILENAME_MAX	BUFSIZ		/* silly filename length */
 #define	L_tmpnam	20		/* sizeof "/tmp/abcdefghij9999 */
 #define	L_cuserid	32		/* maximum size user name */
 #define	L_ctermid	32		/* size of name of controlling tty */
+
+#ifndef SEEK_SET			/* also defined in unistd.h */
 #define	SEEK_CUR	1
 #define	SEEK_END	2
 #define	SEEK_SET	0
+#endif
 #define	TMP_MAX		64		/* very hard to set correctly */
+
 #define	stderr	(&_IO_stream[2])
 #define	stdin	(&_IO_stream[0])
 #define	stdout	(&_IO_stream[1])
-#define	_IO_CHMASK	0377		/* mask for 8 bit characters */
+
+extern FILE _IO_stream[FOPEN_MAX];
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-extern int remove(const char *);
-extern int rename(const char *, const char *);
-extern FILE *tmpfile(void);
-extern char *tmpnam(char *);
-extern int fclose(FILE *);
-extern int fflush(FILE *);
-extern FILE *fopen(const char *, const char *);
-extern FILE *freopen(const char *, const char *, FILE *);
-extern void setbuf(FILE *, char *);
-extern int setvbuf(FILE *, char *, int, size_t);
-extern int fprintf(FILE *, const char *, ...);
-extern int fscanf(FILE *, const char *, ...);
-extern int printf(const char *, ...);
-extern int scanf(const char *, ...);
-extern int sprintf(char *, const char *, ...);
-
+int	_IO_getc(FILE *f);
+int	_IO_putc(int, FILE *);
+void	clearerr(FILE *);
+int	fclose(FILE *);
+FILE	*fdopen(const int, const char *);
+int	feof(FILE *);
+int	ferror(FILE *);
+int	fflush(FILE *);
+int	fgetc(FILE *);
+int	fgetpos(FILE *, fpos_t *);
+char	*fgets(char *, int, FILE *);
+int	fileno(FILE *);
+FILE	*fopen(const char *, const char *);
+int	fprintf(FILE *, const char *, ...);
+int	fputc(int, FILE *);
+int	fputs(const char *, FILE *);
+size_t	fread(void *, size_t, size_t, FILE *);
+FILE	*freopen(const char *, const char *, FILE *);
+int	fscanf(FILE *, const char *, ...);
+int	fseek(FILE *, long, int);
+int	fseeko(FILE *, off_t, int);
+int	fsetpos(FILE *, const fpos_t *);
+long	ftell(FILE *);
+off_t	ftello(FILE *);
+size_t	fwrite(const void *, size_t, size_t, FILE *);
+int	getc(FILE *);
+#define	getc(f)	((f)->rp>=(f)->wp? _IO_getc(f): *(f)->rp++)
+int	getchar(void);
+#define	getchar()	getc(stdin)
+char	*gets(char *);
+void	perror(const char *);
+int	printf(const char *, ...);
+int	putc(int, FILE *);
+/* assignment to f->junk eliminates warnings about unused result of operation */
+#define	putc(c, f) ((f)->junk = ((f)->wp>=(f)->rp? \
+	_IO_putc(c, f): (*(f)->wp++ = (c))))
+int	putchar(int);
+#define	putchar(c)	putc(c, stdout)
+int	puts(const char *);
+int	remove(const char *);
+int	rename(const char *, const char *);
+void	rewind(FILE *);
+int	scanf(const char *, ...);
+void	setbuf(FILE *, char *);
+int	setvbuf(FILE *, char *, int, size_t);
 /*
- * NB: C99 now *requires *snprintf to return the number of characters
+ * NB: C99 now requires *snprintf to return the number of characters
  * that would have been written, had there been room.
  */
-extern int snprintf(char *, size_t, const char *, ...);
-extern int vsnprintf(char *, size_t, const char *, va_list);
-
-extern int sscanf(const char *, const char *, ...);
-extern int vfprintf(FILE *, const char *, va_list);
-extern int vprintf(const char *, va_list);
-extern int vsprintf(char *, const char *, va_list);
-extern int vfscanf(FILE *, const char *, va_list);
-extern int fgetc(FILE *);
-extern char *fgets(char *, int, FILE *);
-extern int fputc(int, FILE *);
-extern int fputs(const char *, FILE *);
-extern int getc(FILE *);
-#define	getc(f)	((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
-extern int _IO_getc(FILE *f);
-extern int getchar(void);
-#define	getchar()	getc(stdin)
-extern char *gets(char *);
-extern int putc(int, FILE *);
-#define	putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
-extern int _IO_putc(int, FILE *);
-extern int putchar(int);
-#define	putchar(c)	putc(c, stdout)
-extern int puts(const char *);
-extern int ungetc(int, FILE *);
-extern size_t fread(void *, size_t, size_t, FILE *);
-extern size_t fwrite(const void *, size_t, size_t, FILE *);
-extern int fgetpos(FILE *, fpos_t *);
-extern int fseek(FILE *, long, int);
-extern int fseeko(FILE *, off_t, int);
-extern int fsetpos(FILE *, const fpos_t *);
-extern long ftell(FILE *);
-extern off_t ftello(FILE *);
-extern void rewind(FILE *);
-extern void clearerr(FILE *);
-extern int feof(FILE *);
-extern int ferror(FILE *);
-extern void perror(const char *);
-extern FILE _IO_stream[FOPEN_MAX];
+int	snprintf(char *, size_t, const char *, ...);
+int	sprintf(char *, const char *, ...);
+int	sscanf(const char *, const char *, ...);
+FILE	*tmpfile(void);
+char	*tmpnam(char *);
+int	ungetc(int, FILE *);
+int	vfprintf(FILE *, const char *, va_list);
+int	vfscanf(FILE *, const char *, va_list);
+int	vprintf(const char *, va_list);
+int	vsnprintf(char *, size_t, const char *, va_list);
+int	vsprintf(char *, const char *, va_list);
 
 #ifdef _POSIX_SOURCE
-extern int fileno(FILE *);
-extern FILE* fdopen(int, const char*);
-extern char *ctermid(char *);
+int	fileno(FILE *);
+FILE*	fdopen(int, const char*);
+char	*ctermid(char *);
 #endif
 
 #ifdef _REENTRANT_SOURCE
-extern char *tmpnam_r(char *);
-extern char *ctermid_r(char *);
+char	*tmpnam_r(char *);
+char	*ctermid_r(char *);
 #endif
 
 #ifdef _BSD_EXTENSION
 #pragma lib "/$M/lib/ape/libbsd.a"
-extern FILE *popen(char *, char *);
-extern int	pclose(FILE *);
+FILE	*popen(char *, char *);
+int	pclose(FILE	*);
 #endif
 
 #ifdef __cplusplus
diff -Nru /n/sources/plan9/sys/src/libstdio/Stdio.h /sys/src/libstdio/Stdio.h
--- /n/sources/plan9/sys/src/libstdio/Stdio.h	Thu Feb 28 21:06:53 2002
+++ /sys/src/libstdio/Stdio.h	Thu Jan  1 00:00:00 1970
@@ -1,109 +0,0 @@
-/*
- * pANS stdio.h
- */
-/*
- * According to X3J11, there is only one i/o buffer
- * and it must not be occupied by both input and output data.
- *	If rp<wp, we must have state==RD and
- *	if wp<rp, we must have state==WR, so that getc and putc work correctly.
- *	On open, rp, wp and buf are set to 0, so first getc or putc will call _IO_getc
- *	or _IO_putc, which will allocate the buffer.
- *	If setvbuf(., ., _IONBF, .) is called, bufl is set to 0 and
- *	buf, rp and wp are pointed at unbuf.
- *	If setvbuf(., ., _IOLBF, .) is called, _IO_putc leaves wp and rp pointed at the
- *	end of the buffer so that it can be called on each putc to check whether it's got
- *	a newline.  This nonsense is in order to avoid impacting performance of the other
- *	buffering modes more than necessary -- putting the test in putc adds many
- *	instructions that are wasted in non-_IOLBF mode:
- *	#define putc(c, f)	(_IO_ctmp=(c),\
- *				(f)->wp>=(f)->rp || (f)->flags&LINEBUF && _IO_ctmp=='\n'\
- *					?_IO_putc(_IO_ctmp, f)\
- *					:*(f)->wp++=_IO_ctmp)
- *				
- */
-typedef struct{
-	int fd;		/* UNIX file pointer */
-	char flags;	/* bits for must free buffer on close, line-buffered */
-	char state;	/* last operation was read, write, position, error, eof */
-	char *buf;	/* pointer to i/o buffer */
-	char *rp;	/* read pointer (or write end-of-buffer) */
-	char *wp;	/* write pointer (or read end-of-buffer) */
-	char *lp;	/* actual write pointer used when line-buffering */
-	long bufl;	/* actual length of buffer */
-	char unbuf[1];	/* tiny buffer for unbuffered io (used for ungetc?) */
-}FILE;
-typedef long fpos_t;
-#ifndef NULL
-#define	NULL	0
-#endif
-/*
- * Third arg of setvbuf
- */
-#define	_IOFBF	1			/* block-buffered */
-#define	_IOLBF	2			/* line-buffered */
-#define	_IONBF	3			/* unbuffered */
-#define	BUFSIZ	4096			/* size of setbuf buffer */
-#define	EOF	(-1)			/* returned on end of file */
-#define	FOPEN_MAX	128		/* max files open */
-#define	FILENAME_MAX	BUFSIZ		/* silly filename length */
-#define	L_tmpnam	20		/* sizeof "/tmp/abcdefghij9999 */
-#define	SEEK_CUR	1
-#define	SEEK_END	2
-#define	SEEK_SET	0
-#define	TMP_MAX		64		/* very hard to set correctly */
-#define	stderr	(&_IO_stream[2])
-#define	stdin	(&_IO_stream[0])
-#define	stdout	(&_IO_stream[1])
-#define	_IO_CHMASK	0377		/* mask for 8 bit characters */
-FILE *tmpfile(void);
-char *tmpnam(char *);
-int fclose(FILE *);
-int fflush(FILE *);
-FILE *fopen(const char *, const char *);
-FILE *freopen(const char *, const char *, FILE *);
-void setbuf(FILE *, char *);
-int setvbuf(FILE *, char *, int, long);
-int fprintf(FILE *, const char *, ...);
-int fscanf(FILE *, const char *, ...);
-int printf(const char *, ...);
-int scanf(const char *, ...);
-int sprintf(char *, const char *, ...);
-int sscanf(const char *, const char *, ...);
-int vfprintf(FILE *, const char *, va_list);
-int vprintf(const char *, va_list);
-int vsprintf(char *, const char *, va_list);
-int vfscanf(FILE *, const char *, va_list);
-int fgetc(FILE *);
-char *fgets(char *, int, FILE *);
-int fputc(int, FILE *);
-int fputs(const char *, FILE *);
-int getc(FILE *);
-#define	getc(f)	((f)->rp>=(f)->wp?_IO_getc(f):*(f)->rp++&_IO_CHMASK)
-int _IO_getc(FILE *f);
-int getchar(void);
-#define	getchar()	getc(stdin)
-char *gets(char *);
-int putc(int, FILE *);
-#define	putc(c, f) ((f)->wp>=(f)->rp?_IO_putc(c, f):(*(f)->wp++=c)&_IO_CHMASK)
-int _IO_putc(int, FILE *);
-int putchar(int);
-#define	putchar(c)	putc(c, stdout)
-int puts(const char *);
-int ungetc(int, FILE *);
-long fread(void *, long, long, FILE *);
-long fwrite(const void *, long, long, FILE *);
-int fgetpos(FILE *, fpos_t *);
-int fseek(FILE *, long int, int);
-int fsetpos(FILE *, const fpos_t *);
-long int ftell(FILE *);
-void rewind(FILE *);
-void clearerr(FILE *);
-int feof(FILE *);
-int ferror(FILE *);
-void perror(const char *);
-extern FILE _IO_stream[FOPEN_MAX];
-FILE *sopenr(const char *);
-FILE *sopenw(void);
-char *sclose(FILE *);
-char	*dtoa(double, int, int, int*, int*, char**);
-void	freedtoa(char*);
diff -Nru /n/sources/plan9/sys/src/libstdio/_IO_getc.c /sys/src/libstdio/_IO_getc.c
--- /n/sources/plan9/sys/src/libstdio/_IO_getc.c	Sun Dec 12 01:22:33 1999
+++ /sys/src/libstdio/_IO_getc.c	Tue Aug 23 00:00:00 2016
@@ -20,7 +20,7 @@
 			f->state=RD;
 			f->rp=f->buf;
 			f->wp=f->buf+cnt;
-			return (*f->rp++)&_IO_CHMASK;
+			return *f->rp++;
 		}
 	}
 }
diff -Nru /n/sources/plan9/sys/src/libstdio/_IO_putc.c /sys/src/libstdio/_IO_putc.c
--- /n/sources/plan9/sys/src/libstdio/_IO_putc.c	Sun Dec 12 01:22:33 1999
+++ /sys/src/libstdio/_IO_putc.c	Thu Aug 25 00:00:00 2016
@@ -56,7 +56,7 @@
 	else if(f->flags&LINEBUF){
 		if(f->lp==f->rp){
 			cnt=f->lp-f->buf;
-			if(f->flags&APPEND) seek(f->fd, 0L, 2);
+			if(f->flags&APPEND) seek(f->fd, 0, SEEK_END);
 			if(cnt!=0 && write(f->fd, f->buf, cnt)!=cnt){
 				f->state=ERR;
 				return EOF;
@@ -66,7 +66,7 @@
 		*f->lp++=c;
 		if(c=='\n'){
 			cnt=f->lp-f->buf;
-			if(f->flags&APPEND) seek(f->fd, 0L, 2);
+			if(f->flags&APPEND) seek(f->fd, 0, SEEK_END);
 			if(cnt!=0 && write(f->fd, f->buf, cnt)!=cnt){
 				f->state=ERR;
 				return EOF;
@@ -76,7 +76,7 @@
 	}
 	else if(f->buf==f->unbuf){
 		f->unbuf[0]=c;
-		if(f->flags&APPEND) seek(f->fd, 0L, 2);
+		if(f->flags&APPEND) seek(f->fd, 0, SEEK_END);
 		if(write(f->fd, f->buf, 1)!=1){
 			f->state=ERR;
 			return EOF;
@@ -85,7 +85,7 @@
 	else{
 		if(f->wp==f->rp){
 			cnt=f->wp-f->buf;
-			if(f->flags&APPEND) seek(f->fd, 0L, 2);
+			if(f->flags&APPEND) seek(f->fd, 0, SEEK_END);
 			if(cnt!=0 && write(f->fd, f->buf, cnt)!=cnt){
 				f->state=ERR;
 				return EOF;
diff -Nru /n/sources/plan9/sys/src/libstdio/dtoa.c /sys/src/libstdio/dtoa.c
--- /n/sources/plan9/sys/src/libstdio/dtoa.c	Fri May 31 21:45:07 2013
+++ /sys/src/libstdio/dtoa.c	Thu Aug 25 00:00:00 2016
@@ -130,7 +130,7 @@
 	return rv;
 }
 
-static void	
+static void
 Bfree(Bigint *v)
 {
 	if (v) {
@@ -184,7 +184,7 @@
 	int x, y;
 
 	x = (nd + 8) / 9;
-	for (k = 0, y = 1; x > y; y <<= 1, k++) 
+	for (k = 0, y = 1; x > y; y <<= 1, k++)
 		;
 	b = Balloc(k);
 	b->x[0] = y9;
@@ -193,7 +193,7 @@
 	i = 9;
 	if (9 < nd0) {
 		s += 9;
-		do 
+		do
 			b = multadd(b, 10, *s++ - '0');
 		while (++i < nd0);
 		s++;
@@ -204,7 +204,7 @@
 	return b;
 }
 
-static int	
+static int
 hi0bits(register unsigned int x)
 {
 	register int	k = 0;
@@ -233,7 +233,7 @@
 	return k;
 }
 
-static int	
+static int
 lo0bits(unsigned int *y)
 {
 	register int	k;
@@ -345,7 +345,7 @@
 			*xc = z2;
 		}
 	}
-	for (xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc) 
+	for (xc0 = c->x, xc = xc0 + wc; wc > 0 && !*--xc; --wc)
 		;
 	c->wds = wc;
 	return c;
@@ -358,7 +358,7 @@
 {
 	Bigint * b1, *p5, *p51;
 	int	i;
-	static int	p05[3] = { 
+	static int	p05[3] = {
 		5, 25, 125 	};
 
 	if (i = k & 3)
@@ -423,7 +423,7 @@
 		} while (x < xe);
 		if (*x1 = z)
 			++n1;
-	} else 
+	} else
 		do
 			*x1++ = *x++;
 		while (x < xe);
@@ -432,7 +432,7 @@
 	return b1;
 }
 
-static int	
+static int
 cmp(Bigint *a, Bigint *b)
 {
 	unsigned int * xa, *xa0, *xb, *xb0;
@@ -508,7 +508,7 @@
 	return c;
 }
 
-static double	
+static double
 ulp(double x)
 {
 	ulong L;
@@ -519,7 +519,7 @@
 	return ulongs2double((Ulongs){L, 0});
 }
 
-static double	
+static double
 b2d(Bigint *a, int *e)
 {
 	unsigned *xa, *xa0, w, y, z;
@@ -583,7 +583,7 @@
 	return b;
 }
 
-static double	
+static double
 ratio(Bigint *a, Bigint *b)
 {
 	double	da, db;
@@ -614,10 +614,10 @@
 };
 
 static const double
-bigtens[] = { 
+bigtens[] = {
 	1e16, 1e32, 1e64, 1e128, 1e256 };
 
-static const double tinytens[] = { 
+static const double tinytens[] = {
 	1e-16, 1e-32, 1e-64, 1e-128,
 	9007199254740992.e-256
 };
@@ -631,7 +631,7 @@
 
 #define NAN_WORD1 0
 
-static int	
+static int
 match(const char **sp, char *t)
 {
 	int	c, d;
@@ -647,7 +647,7 @@
 	return 1;
 }
 
-static void	
+static void
 gethex(double *rvp, const char **sp)
 {
 	unsigned int c, x[2];
@@ -690,7 +690,7 @@
 		*rvp = ulongs2double((Ulongs){Exp_mask | x[0], x[1]});
 }
 
-static int	
+static int
 quorem(Bigint *b, Bigint *S)
 {
 	int	n;
@@ -761,8 +761,8 @@
 	int	j, k, *r;
 
 	j = sizeof(unsigned int);
-	for (k = 0; 
-	    sizeof(Bigint) - sizeof(unsigned int) - sizeof(int) + j <= i; 
+	for (k = 0;
+	    sizeof(Bigint) - sizeof(unsigned int) - sizeof(int) + j <= i;
 	    j <<= 1)
 		k++;
 	r = (int * )Balloc(k);
@@ -777,7 +777,7 @@
 	char	*rv, *t;
 
 	t = rv = rv_alloc(n);
-	while (*t = *s++) 
+	while (*t = *s++)
 		t++;
 	if (rve)
 		*rve = t;
@@ -1114,7 +1114,7 @@
 	mhi = mlo = 0;
 	if (leftright) {
 		if (mode < 2) {
-			i = 
+			i =
 			    1 + P - bbits;
 		} else {
 			j = ilim - 1;
diff -Nru /n/sources/plan9/sys/src/libstdio/fdopen.c /sys/src/libstdio/fdopen.c
--- /n/sources/plan9/sys/src/libstdio/fdopen.c	Sun Dec 12 01:22:33 1999
+++ /sys/src/libstdio/fdopen.c	Thu Aug 25 00:00:00 2016
@@ -13,7 +13,7 @@
  * a+ a+b ab+	open to read and write, positioned at eof, creating if non-existant.
  */
 FILE *fdopen(const int fd, const char *mode){
-	FILE *f;	
+	FILE *f;
 	qlock(&_stdiolk);
 	for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++)
 		if(f->state==CLOSED)
@@ -24,7 +24,7 @@
 	}
 	f->fd=fd;
 	if(mode[0]=='a')
-		seek(f->fd, 0L, 2);
+		seek(f->fd, 0, SEEK_END);
 	if(f->fd==-1) return NULL;
 	f->flags=0;
 	f->state=OPEN;
diff -Nru /n/sources/plan9/sys/src/libstdio/fflush.c /sys/src/libstdio/fflush.c
--- /n/sources/plan9/sys/src/libstdio/fflush.c	Sun Dec 12 01:22:33 1999
+++ /sys/src/libstdio/fflush.c	Thu Aug 25 00:00:00 2016
@@ -6,10 +6,9 @@
  * pANS stdio -- data (put here, since loader won't load a separate file)
  */
 FILE _IO_stream[]={
-/*	fd	flags	state	buf	rp	wp	lp	bufl	unbuf */
-	0,	0,	OPEN,	0,	0,	0,	0,	0,	0,
-	1,	0,	OPEN,	0,	0,	0,	0,	0,	0,
-	2,	0,	OPEN,	0,	0,	0,	0,	0,	0,
+	{ .fd 0, .state OPEN, },
+	{ .fd 1, .state OPEN, },
+	{ .fd 2, .state OPEN, },
 };
 
 int _fflush(FILE *f){
diff -Nru /n/sources/plan9/sys/src/libstdio/freopen.c /sys/src/libstdio/freopen.c
--- /n/sources/plan9/sys/src/libstdio/freopen.c	Sat Sep 28 00:10:23 2002
+++ /sys/src/libstdio/freopen.c	Thu Aug 25 00:00:00 2016
@@ -40,7 +40,7 @@
 		f->fd=open(name, m);
 		if(f->fd<0)
 			f->fd=create(name, m, 0666);
-		seek(f->fd, 0LL, 2);
+		seek(f->fd, 0, SEEK_END);
 		break;
 	}
 
diff -Nru /n/sources/plan9/sys/src/libstdio/ftell.c /sys/src/libstdio/ftell.c
--- /n/sources/plan9/sys/src/libstdio/ftell.c	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/ftell.c	Thu Aug 25 00:00:00 2016
@@ -3,7 +3,7 @@
  */
 #include "iolib.h"
 long ftell(FILE *f){
-	long seekp=seek(f->fd, 0L, 1);
+	long seekp=seek(f->fd, 0, SEEK_CUR);
 	if(seekp<0) return -1;		/* enter error state? */
 	switch(f->state){
 	default:
diff -Nru /n/sources/plan9/sys/src/libstdio/ftello.c /sys/src/libstdio/ftello.c
--- /n/sources/plan9/sys/src/libstdio/ftello.c	Sun Jun 15 18:06:24 2003
+++ /sys/src/libstdio/ftello.c	Thu Aug 25 00:00:00 2016
@@ -3,7 +3,7 @@
  */
 #include "iolib.h"
 long long ftello(FILE *f){
-	long long seekp=seek(f->fd, 0L, 1);
+	long long seekp=seek(f->fd, 0, SEEK_CUR);
 	if(seekp<0) return -1;		/* enter error state? */
 	switch(f->state){
 	default:
diff -Nru /n/sources/plan9/sys/src/libstdio/fwrite.c /sys/src/libstdio/fwrite.c
--- /n/sources/plan9/sys/src/libstdio/fwrite.c	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/fwrite.c	Thu Aug 25 00:00:00 2016
@@ -23,7 +23,7 @@
 				d=f->wp-f->buf;
 				if(d>0){
 					if(f->flags&APPEND)
-						seek(f->fd, 0L, 2);
+						seek(f->fd, 0, SEEK_END);
 					if(write(f->fd, f->buf, d)!=d){
 						f->state=ERR;
 						goto ret;
@@ -31,7 +31,7 @@
 					f->wp=f->rp=f->buf;
 				}
 				if(f->flags&APPEND)
-					seek(f->fd, 0L, 2);
+					seek(f->fd, 0, SEEK_END);
 				d=write(f->fd, s, n);
 				if(d<=0){
 					f->state=ERR;
diff -Nru /n/sources/plan9/sys/src/libstdio/iolib.h /sys/src/libstdio/iolib.h
--- /n/sources/plan9/sys/src/libstdio/iolib.h	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/iolib.h	Thu Aug 25 00:00:00 2016
@@ -19,7 +19,7 @@
 #include <u.h>
 #include <libc.h>
 #undef END
-#include "Stdio.h"
+#include <stdio.h>
 /*
  * Flag bits
  */
@@ -42,3 +42,7 @@
 
 /* half hearted attempt to make multi threaded */
 extern QLock _stdiolk;
+
+/* internal functions */
+char	*dtoa(double, int, int, int*, int*, char**);
+void	freedtoa(char*);
diff -Nru /n/sources/plan9/sys/src/libstdio/mkfile /sys/src/libstdio/mkfile
--- /n/sources/plan9/sys/src/libstdio/mkfile	Thu Jan 31 22:29:44 2013
+++ /sys/src/libstdio/mkfile	Thu Aug 25 00:00:00 2016
@@ -62,8 +62,7 @@
 	${LIB:/$objtype/%=/386/%}\
 
 </sys/src/cmd/mksyslib
-# this code really can't handle any flow-analysis warnings
-CFLAGS= -FTV
+CFLAGS= -FTVw
 
 test:V:	$OFILES
 	ar vu libstdio.a $OFILES
diff -Nru /n/sources/plan9/sys/src/libstdio/rewind.c /sys/src/libstdio/rewind.c
--- /n/sources/plan9/sys/src/libstdio/rewind.c	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/rewind.c	Thu Aug 25 00:00:00 2016
@@ -3,5 +3,5 @@
  */
 #include "iolib.h"
 void rewind(FILE *f){
-	fseek(f, 0L, SEEK_SET);
+	fseek(f, 0, SEEK_SET);
 }
diff -Nru /n/sources/plan9/sys/src/libstdio/sclose.c /sys/src/libstdio/sclose.c
--- /n/sources/plan9/sys/src/libstdio/sclose.c	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/sclose.c	Tue Aug 23 00:00:00 2016
@@ -30,5 +30,5 @@
 	}
 	f->state=CLOSED;
 	f->flags=0;
-	return f->buf;
+	return (char *)f->buf;
 }
diff -Nru /n/sources/plan9/sys/src/libstdio/setbuf.c /sys/src/libstdio/setbuf.c
--- /n/sources/plan9/sys/src/libstdio/setbuf.c	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/setbuf.c	Thu Aug 25 00:00:00 2016
@@ -2,7 +2,7 @@
  * pANS stdio -- setbuf
  */
 #include "iolib.h"
-void setbuf(FILE *f, char *buf){
+void setbuf(FILE *f, void *buf){
 	if(f->state==OPEN){
 		if(buf)
 			f->bufl=BUFSIZ;
diff -Nru /n/sources/plan9/sys/src/libstdio/setvbuf.c /sys/src/libstdio/setvbuf.c
--- /n/sources/plan9/sys/src/libstdio/setvbuf.c	Sun Apr 17 12:47:51 2005
+++ /sys/src/libstdio/setvbuf.c	Thu Aug 25 00:00:00 2016
@@ -2,7 +2,7 @@
  * pANS stdio -- setvbuf
  */
 #include "iolib.h"
-int setvbuf(FILE *f, char *buf, int mode, long size){
+int setvbuf(FILE *f, void *buf, int mode, long size){
 	if(f->state!=OPEN){
 		f->state=ERR;
 		return -1;
diff -Nru /n/sources/plan9/sys/src/libstdio/sopenr.c /sys/src/libstdio/sopenr.c
--- /n/sources/plan9/sys/src/libstdio/sopenr.c	Sun Dec 12 01:22:34 1999
+++ /sys/src/libstdio/sopenr.c	Tue Aug 23 00:00:00 2016
@@ -11,7 +11,7 @@
 		qunlock(&_stdiolk);
 		return NULL;
 	}
-	f->buf=f->rp=(char *)s;	/* what an annoyance const is */
+	f->buf=f->rp=(uchar *)s;	/* what an annoyance const is */
 	f->bufl=strlen(s);
 	f->wp=f->buf+f->bufl;
 	f->state=RD;
diff -Nru /n/sources/plan9/sys/src/libstdio/vfprintf.c /sys/src/libstdio/vfprintf.c
--- /n/sources/plan9/sys/src/libstdio/vfprintf.c	Mon Feb 17 17:15:46 2003
+++ /sys/src/libstdio/vfprintf.c	Tue Aug 30 00:00:00 2016
@@ -146,12 +146,14 @@
 QLock _stdiolk;
 
 int
-vfprintf(FILE *f, const char *s, va_list args)
+vfprintf(FILE *f, const char *as, va_list args)
 {
 	int flags, width, precision;
+	uchar *s;
 
 	qlock(&_stdiolk);
 
+	s = (uchar *)as;
 	nprint = 0;
 	while(*s){
 		if(*s != '%'){
@@ -161,7 +163,7 @@
 		}
 		s++;
 		flags = 0;
-		while(lflag[*s&_IO_CHMASK]) flags |= lflag[*s++&_IO_CHMASK];
+		while(lflag[*s]) flags |= lflag[*s++];
 		if(*s == '*'){
 			width = va_arg(args, int);
 			s++;
@@ -187,7 +189,7 @@
 		}
 		else
 			precision = -1;
-		while(tflag[*s&_IO_CHMASK]) flags |= tflag[*s++&_IO_CHMASK];
+		while(tflag[*s]) flags |= tflag[*s++];
 		if(ocvt[*s]) nprint += (*ocvt[*s++])(f, &args, flags, width, precision);
 		else if(*s){
 			putc(*s++, f);
@@ -210,9 +212,9 @@
 static int
 ocvt_c(FILE *f, va_list *args, int flags, int width, int precision)
 {
-#pragma ref precision
 	int i;
 
+	USED(precision);
 	if(!(flags&LEFT)) for(i=1; i<width; i++) putc(' ', f);
 	putc((unsigned char)va_arg(*args, int), f);
 	if(flags&LEFT) for(i=1; i<width; i++) putc(' ', f);
@@ -259,9 +261,7 @@
 static int
 ocvt_n(FILE *f, va_list *args, int flags, int width, int precision)
 {
-#pragma ref f
-#pragma ref width
-#pragma ref precision
+	USED(precision, width, f);
 	if(flags&SHORT)
 		*va_arg(*args, short *) = nprint;
 	else if(flags&LONG)
@@ -293,7 +293,7 @@
 	int nout, npad, nlzero;
 
 	if(sgned){
-		if(flags&PTR) snum = (long)va_arg(*args, void *);
+		if(flags&PTR) snum = (uintptr)va_arg(*args, void *);
 		else if(flags&SHORT) snum = va_arg(*args, short);
 		else if(flags&LONG) snum = va_arg(*args, long);
 		else snum = va_arg(*args, int);
@@ -308,7 +308,7 @@
 		}
 	} else {
 		sign = "";
-		if(flags&PTR) num = (long)va_arg(*args, void *);
+		if(flags&PTR) num = (uintptr)va_arg(*args, void *);
 		else if(flags&SHORT) num = va_arg(*args, unsigned short);
 		else if(flags&LONG) num = va_arg(*args, unsigned long);
 		else num = va_arg(*args, unsigned int);
@@ -456,6 +456,7 @@
 	fmt = afmt;
 	d = va_arg(*args, double);
 	if(precision < 0) precision = 6;
+	digits = 0;			/* silence used and not set */
 	switch(fmt){
 	case 'f':
 		digits = dtoa(d, 3, precision, &exponent, &sign, &edigits);
@@ -512,6 +513,7 @@
 	if(fmt=='f' && exponent>0) nout += exponent;	/* digits before decimal point */
 	else nout++;					/* there's always at least one */
 	if(sign || flags&(SPACE|SIGN)) nout++;		/* sign */
+	eptr = nil;				/* silence used and not set */
 	if(fmt != 'f'){					/* exponent */
 		eptr = ebuf;
 		for(i=exponent<=0?1-exponent:exponent-1; i; i/=10)
diff -Nru /n/sources/plan9/sys/src/libstdio/vfscanf.c /sys/src/libstdio/vfscanf.c
--- /n/sources/plan9/sys/src/libstdio/vfscanf.c	Wed Jul 14 20:25:03 2010
+++ /sys/src/libstdio/vfscanf.c	Tue Aug 23 00:00:00 2016
@@ -103,8 +103,7 @@
 	return ncvt;	
 }
 static int icvt_n(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref f
-#pragma ref width
+	USED(f, width);
 	if(store){
 		--ncvt;	/* this assignment doesn't count! */
 		switch(type){
@@ -276,9 +275,10 @@
 	return 1;
 }
 static int icvt_s(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
+	USED(type);
 	int c, nn;
 	register char *s;
+	s = nil;				/* silence used and not set */
 	if(store) s=va_arg(*args, char *);
 	do
 		c=ngetc(f);
@@ -304,9 +304,10 @@
 	return 1;
 }
 static int icvt_c(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
+	USED(type);
 	int c;
 	register char *s;
+	s = nil;				/* silence used and not set */
 	if(store) s=va_arg(*args, char *);
 	if(width<0) width=1;
 	for(;;){
@@ -336,7 +337,7 @@
 	return !ok;
 }
 static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
+	USED(type);
 	int c, nn;
 	register char *s;
 	register const char *pat;
@@ -344,6 +345,7 @@
 	if(*fmtp=='^') fmtp++;
 	if(*fmtp!='\0') fmtp++;
 	while(*fmtp!='\0' && *fmtp!=']') fmtp++;
+	s = nil;				/* silence used and not set */
 	if(store) s=va_arg(*args, char *);
 	nn=0;
 	for(;;){
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_getc.c /sys/src/ape/lib/ap/stdio/_IO_getc.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_getc.c	Mon Nov 25 15:18:50 2002
+++ /sys/src/ape/lib/ap/stdio/_IO_getc.c	Thu Aug 25 00:00:00 2016
@@ -3,7 +3,7 @@
  */
 #include "iolib.h"
 int _IO_getc(FILE *f){
-	int cnt, n;
+	int cnt;
 	switch(f->state){
 	default:	/* CLOSED, WR, ERR, EOF */
 		return EOF;
@@ -12,11 +12,7 @@
 	case RDWR:
 	case RD:
 		if(f->flags&STRING) return EOF;
-		if(f->buf == f->unbuf)
-			n = 1;
-		else
-			n = f->bufl;
-		cnt=read(f->fd, f->buf, n);
+		cnt=read(f->fd, f->buf, f->buf==f->unbuf?1:f->bufl);
 		switch(cnt){
 		case -1: f->state=ERR; return EOF;
 		case 0: f->state=END; return EOF;
@@ -24,7 +20,7 @@
 			f->state=RD;
 			f->rp=f->buf;
 			f->wp=f->buf+cnt;
-			return (*f->rp++)&_IO_CHMASK;
+			return *f->rp++;
 		}
 	}
 }
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_putc.c /sys/src/ape/lib/ap/stdio/_IO_putc.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_IO_putc.c	Thu Feb 28 18:46:21 2002
+++ /sys/src/ape/lib/ap/stdio/_IO_putc.c	Thu Aug 25 00:00:00 2016
@@ -57,7 +57,7 @@
 	else if(f->flags&LINEBUF){
 		if(f->lp==f->rp){
 			cnt=f->lp-f->buf;
-			if(f->flags&APPEND) lseek(f->fd, 0L, SEEK_END);
+			if(f->flags&APPEND) lseek(f->fd, 0, SEEK_END);
 			if(cnt!=0 && write(f->fd, f->buf, cnt)!=cnt){
 				f->state=ERR;
 				return EOF;
@@ -67,7 +67,7 @@
 		*f->lp++=c;
 		if(c=='\n'){
 			cnt=f->lp-f->buf;
-			if(f->flags&APPEND) lseek(f->fd, 0L, SEEK_END);
+			if(f->flags&APPEND) lseek(f->fd, 0, SEEK_END);
 			if(cnt!=0 && write(f->fd, f->buf, cnt)!=cnt){
 				f->state=ERR;
 				return EOF;
@@ -77,7 +77,7 @@
 	}
 	else if(f->buf==f->unbuf){
 		f->unbuf[0]=c;
-		if(f->flags&APPEND) lseek(f->fd, 0L, SEEK_END);
+		if(f->flags&APPEND) lseek(f->fd, 0, SEEK_END);
 		if(write(f->fd, f->buf, 1)!=1){
 			f->state=ERR;
 			return EOF;
@@ -86,7 +86,7 @@
 	else{
 		if(f->wp==f->rp){
 			cnt=f->wp-f->buf;
-			if(f->flags&APPEND) lseek(f->fd, 0L, SEEK_END);
+			if(f->flags&APPEND) lseek(f->fd, 0, SEEK_END);
 			if(cnt!=0 && write(f->fd, f->buf, cnt)!=cnt){
 				f->state=ERR;
 				return EOF;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_dtoa.c /sys/src/ape/lib/ap/stdio/_dtoa.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_dtoa.c	Thu Feb 28 18:46:23 2002
+++ /sys/src/ape/lib/ap/stdio/_dtoa.c	Wed Aug 24 00:00:00 2016
@@ -89,6 +89,7 @@
 	static int result_k;
 	Dul d;
 
+	mlo = 0;
 	d.d = darg;
 	if (result) {
 		result->k = result_k;
@@ -230,6 +231,7 @@
 		try_quick = 0;
 		}
 	leftright = 1;
+	ilim = ilim1 = -1;
 	switch(mode) {
 		case 0:
 		case 1:
@@ -463,7 +465,7 @@
 		S = pow5mult(S, s5);
 
 	/* Check for special case that d is a normalized power of 2. */
-
+	spec_case = 0;
 	if (mode < 2) {
 		if (!word1(d) && !(word0(d) & Bndry_mask)
 #ifndef Sudden_Underflow
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/_fconv.c /sys/src/ape/lib/ap/stdio/_fconv.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/_fconv.c	Thu Feb 28 18:46:23 2002
+++ /sys/src/ape/lib/ap/stdio/_fconv.c	Wed Aug 24 00:00:00 2016
@@ -510,6 +510,7 @@
 		else
 			x[0] = y;
 		i = b->wds = (x[1] = z) ? 2 : 1;
+		USED(i);
 		}
 	else {
 #ifdef DEBUG
@@ -519,6 +520,7 @@
 		k = lo0bits(&z);
 		x[0] = z;
 		i = b->wds = 1;
+		USED(i);
 		k += 32;
 		}
 #else
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fdopen.c /sys/src/ape/lib/ap/stdio/fdopen.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fdopen.c	Thu Feb 28 18:46:21 2002
+++ /sys/src/ape/lib/ap/stdio/fdopen.c	Thu Aug 25 00:00:00 2016
@@ -21,7 +21,7 @@
 		return NULL;
 	f->fd=fd;
 	if(mode[0]=='a')
-		lseek(f->fd, 0L, 2);
+		lseek(f->fd, 0, SEEK_END);
 	if(f->fd==-1) return NULL;
 	f->flags=0;
 	f->state=OPEN;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/freopen.c /sys/src/ape/lib/ap/stdio/freopen.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/freopen.c	Fri Sep 27 14:03:11 2002
+++ /sys/src/ape/lib/ap/stdio/freopen.c	Thu Aug 25 00:00:00 2016
@@ -50,7 +50,7 @@
 				f->fd=open(name, O_RDWR);
 			}
 		}
-		lseek(f->fd, 0L, 2);
+		lseek(f->fd, 0, SEEK_END);
 		break;
 	}
 
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/ftell.c /sys/src/ape/lib/ap/stdio/ftell.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/ftell.c	Fri Apr 18 16:45:42 2003
+++ /sys/src/ape/lib/ap/stdio/ftell.c	Thu Aug 25 00:00:00 2016
@@ -3,7 +3,7 @@
  */
 #include "iolib.h"
 long ftell(FILE *f){
-	long seekp=lseek(f->fd, 0L, 1);
+	long seekp=lseek(f->fd, 0, SEEK_CUR);
 	if(seekp<0) return -1;		/* enter error state? */
 	switch(f->state){
 	default:
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/ftello.c /sys/src/ape/lib/ap/stdio/ftello.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/ftello.c	Fri Apr 18 16:45:42 2003
+++ /sys/src/ape/lib/ap/stdio/ftello.c	Thu Aug 25 00:00:00 2016
@@ -3,7 +3,7 @@
  */
 #include "iolib.h"
 off_t ftello(FILE *f){
-	off_t seekp=lseek(f->fd, 0L, 1);
+	off_t seekp=lseek(f->fd, 0, SEEK_CUR);
 	if(seekp<0) return -1;		/* enter error state? */
 	switch(f->state){
 	default:
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/ftoa.c /sys/src/ape/lib/ap/stdio/ftoa.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/ftoa.c	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/ftoa.c	Mon Aug 29 00:00:00 2016
@@ -27,7 +27,7 @@
 		e1=e/2;
 		e2=e-e1;
 		p=f*pow10(e2);
-		while((g=p*pow10(e1))<1.) e1++;
+		while(p*pow10(e1)<1.) e1++;
 		while((g=p*pow10(e1))>=10.) --e1;
 		e=e1+e2;
 		f=g;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/fwrite.c /sys/src/ape/lib/ap/stdio/fwrite.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/fwrite.c	Mon Nov 25 15:18:52 2002
+++ /sys/src/ape/lib/ap/stdio/fwrite.c	Thu Aug 25 00:00:00 2016
@@ -24,7 +24,7 @@
 				d=f->wp-f->buf;
 				if(d>0){
 					if(f->flags&APPEND)
-						lseek(f->fd, 0L, SEEK_END);
+						lseek(f->fd, 0, SEEK_END);
 					if(write(f->fd, f->buf, d)!=d){
 						f->state=ERR;
 						goto ret;
@@ -32,7 +32,7 @@
 					f->wp=f->rp=f->buf;
 				}
 				if(f->flags&APPEND)
-					lseek(f->fd, 0L, SEEK_END);
+					lseek(f->fd, 0, SEEK_END);
 				d=write(f->fd, s, n);
 				if(d<=0){
 					f->state=ERR;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/iolib.h /sys/src/ape/lib/ap/stdio/iolib.h
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/iolib.h	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/iolib.h	Tue Aug 30 00:00:00 2016
@@ -14,7 +14,12 @@
  *	fseek		fsetpos		ftell		rewind		clearerr
  *	feof		ferror		perror	
  */
+#ifndef _SUSV2_SOURCE
+#define _SUSV2_SOURCE	/* for *intptr_t types */
+#endif
+
 #include <stdio.h>
+#include <inttypes.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/mkfile /sys/src/ape/lib/ap/stdio/mkfile
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/mkfile	Thu Jan 31 22:27:55 2013
+++ /sys/src/ape/lib/ap/stdio/mkfile	Wed Aug 24 00:00:00 2016
@@ -65,5 +65,4 @@
 
 </sys/src/cmd/mksyslib
 
-# -w draws lots of "result of operation not used" warnings
-CFLAGS=-c -D_POSIX_SOURCE -FTV
+CFLAGS=-c -D_POSIX_SOURCE -FTVw
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/rdline.c /sys/src/ape/lib/ap/stdio/rdline.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/rdline.c	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/rdline.c	Thu Aug 25 00:00:00 2016
@@ -5,9 +5,13 @@
 #include "iolib.h"
 #include <string.h>
 
-char *rdline(FILE *f, char **ep){
+char *rdline(FILE *f, char **aep){
 	int cnt;
-	char *nlp, *vp;
+	void *vp;
+	unsigned char *nlp;
+	unsigned char **ep;
+
+	ep = (unsigned char **)aep;
 	switch(f->state){
 	default:	/* CLOSED, WR, ERR, EOF */
 		return NULL;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/rewind.c /sys/src/ape/lib/ap/stdio/rewind.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/rewind.c	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/rewind.c	Thu Aug 25 00:00:00 2016
@@ -3,5 +3,5 @@
  */
 #include "iolib.h"
 void rewind(FILE *f){
-	fseek(f, 0L, SEEK_SET);
+	fseek(f, 0, SEEK_SET);
 }
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/sclose.c /sys/src/ape/lib/ap/stdio/sclose.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/sclose.c	Fri Dec  9 15:43:31 2005
+++ /sys/src/ape/lib/ap/stdio/sclose.c	Thu Aug 25 00:00:00 2016
@@ -2,7 +2,6 @@
  * pANS stdio -- sclose
  */
 #include "iolib.h"
-#include <stdlib.h>
 
 char *_IO_sclose(FILE *f){
 	switch(f->state){
@@ -33,5 +32,5 @@
 	}
 	f->state=CLOSED;
 	f->flags=0;
-	return f->buf;
+	return (char *)f->buf;
 }
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/setbuf.c /sys/src/ape/lib/ap/stdio/setbuf.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/setbuf.c	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/setbuf.c	Tue Aug 23 00:00:00 2016
@@ -7,10 +7,10 @@
 		if(buf)
 			f->bufl=BUFSIZ;
 		else{
-			buf=f->unbuf;
+			buf=(char *)f->unbuf;
 			f->bufl=0;
 		}
-		f->rp=f->wp=f->lp=f->buf=buf;
+		f->rp=f->wp=f->lp=f->buf=(unsigned char *)buf;
 		f->state=RDWR;
 	}
 	/* else error, but there's no way to report it */
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/setvbuf.c /sys/src/ape/lib/ap/stdio/setvbuf.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/setvbuf.c	Thu Dec  8 14:33:02 2005
+++ /sys/src/ape/lib/ap/stdio/setvbuf.c	Thu Aug 25 00:00:00 2016
@@ -2,7 +2,6 @@
  * pANS stdio -- setvbuf
  */
 #include "iolib.h"
-#include <stdlib.h>
 int setvbuf(FILE *f, char *buf, int mode, size_t size){
 	if(f->state!=OPEN){
 		f->state=ERR;
@@ -24,11 +23,11 @@
 		f->bufl=size;
 		break;
 	case _IONBF:
-		buf=f->unbuf;
+		buf=(char *)f->unbuf;
 		f->bufl=0;
 		break;
 	}
-	f->rp=f->wp=f->lp=f->buf=buf;
+	f->rp=f->wp=f->lp=f->buf=(unsigned char *)buf;
 	f->state=RDWR;
 	return 0;
 }
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/sopenr.c /sys/src/ape/lib/ap/stdio/sopenr.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/sopenr.c	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/sopenr.c	Tue Aug 23 00:00:00 2016
@@ -8,7 +8,7 @@
 	FILE *f;
 	for(f=_IO_stream;f!=&_IO_stream[FOPEN_MAX];f++) if(f->state==CLOSED) break;
 	if(f==&_IO_stream[FOPEN_MAX]) return NULL;
-	f->buf=f->rp=(char *)s;	/* what an annoyance const is */
+	f->buf=f->rp=(unsigned char *)s;	/* what an annoyance const is */
 	f->bufl=strlen(s);
 	f->wp=f->buf+f->bufl;
 	f->state=RD;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/stdio.c /sys/src/ape/lib/ap/stdio/stdio.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/stdio.c	Thu Feb 28 18:46:22 2002
+++ /sys/src/ape/lib/ap/stdio/stdio.c	Thu Aug 25 00:00:00 2016
@@ -3,8 +3,7 @@
  */
 #include "iolib.h"
 FILE _IO_stream[]={
-/*	fd	flags	state	buf	rp	wp	lp	bufl	unbuf */
-	0,	0,	OPEN,	0,	0,	0,	0,	0,	0,
-	1,	0,	OPEN,	0,	0,	0,	0,	0,	0,
-	2,	0,	OPEN,	0,	0,	0,	0,	0,	0,
+	{ .fd 0, .state OPEN, },
+	{ .fd 1, .state OPEN, },
+	{ .fd 2, .state OPEN, },
 };
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/strtod.c /sys/src/ape/lib/ap/stdio/strtod.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/strtod.c	Wed Feb  3 20:38:07 2010
+++ /sys/src/ape/lib/ap/stdio/strtod.c	Wed Aug 24 00:00:00 2016
@@ -219,6 +219,8 @@
 	long L;
 	unsigned long y, z;
 	Bigint *bb, *bb1, *bd, *bd0, *bs, *delta;
+
+	bb = bd = bs = delta = 0;
 	sign = nz0 = nz = 0;
 	rv.d = 0.;
 	for(s = s00;;s++) switch(*s) {
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/ungetc.c /sys/src/ape/lib/ap/stdio/ungetc.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/ungetc.c	Mon Nov 25 15:18:53 2002
+++ /sys/src/ape/lib/ap/stdio/ungetc.c	Thu Aug 25 00:00:00 2016
@@ -15,12 +15,7 @@
 		_IO_setvbuf(f);
 	case RDWR:
 	case END:
-		f->wp=f->buf;
-		if(f->bufl==0)
-			f->wp += 1;
-		else
-			f->wp += f->bufl;
-		f->rp = f->wp;
+		f->rp=f->wp=f->buf+(f->bufl==0?1:f->bufl);
 		f->state=RD;
 	case RD:
 		if(f->rp==f->buf) return EOF;
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/vfprintf.c /sys/src/ape/lib/ap/stdio/vfprintf.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/vfprintf.c	Wed Jun 16 17:19:44 2004
+++ /sys/src/ape/lib/ap/stdio/vfprintf.c	Tue Aug 30 00:00:00 2016
@@ -4,7 +4,6 @@
 #include "iolib.h"
 #include <stdarg.h>
 #include <math.h>
-#include <stdlib.h>
 #include <string.h>
 /*
  * Leading flags
@@ -149,11 +148,13 @@
 static int nprint;
 
 int
-vfprintf(FILE *f, const char *s, va_list args)
+vfprintf(FILE *f, const char *as, va_list args)
 {
 	int tfl, flags, width, precision;
+	unsigned char *s;
 
 	nprint = 0;
+	s = (unsigned char *)as;
 	while(*s){
 		if(*s != '%'){
 			putc(*s++, f);
@@ -162,7 +163,7 @@
 		}
 		s++;
 		flags = 0;
-		while(lflag[*s&_IO_CHMASK]) flags |= lflag[*s++&_IO_CHMASK];
+		while(lflag[*s]) flags |= lflag[*s++];
 		if(*s == '*'){
 			width = va_arg(args, int);
 			s++;
@@ -188,7 +189,7 @@
 		}
 		else
 			precision = -1;
-		while(tfl = tflag[*s&_IO_CHMASK]){
+		while(tfl = tflag[*s]){
 			if(tfl == LONG && (flags & LONG)){
 				flags &= ~LONG;
 				tfl = VLONG;
@@ -208,9 +209,9 @@
 static int
 ocvt_c(FILE *f, va_list *args, int flags, int width, int precision)
 {
-#pragma ref precision
 	int i;
 
+	USED(precision);
 	if(!(flags&LEFT)) for(i=1; i<width; i++) putc(' ', f);
 	putc((unsigned char)va_arg(*args, int), f);
 	if(flags&LEFT) for(i=1; i<width; i++) putc(' ', f);
@@ -259,9 +260,7 @@
 static int
 ocvt_n(FILE *f, va_list *args, int flags, int width, int precision)
 {
-#pragma ref f
-#pragma ref width
-#pragma ref precision
+	USED(f, width, precision);
 	if(flags&SHORT)
 		*va_arg(*args, short *) = nprint;
 	else if(flags&LONG)
@@ -295,7 +294,8 @@
 	int nout, npad, nlzero;
 
 	if(sgned){
-		if(flags&PTR) snum = (long)va_arg(*args, void *);
+		if(flags&PTR) snum = /* (intptr_t) */ (long long)
+			va_arg(*args, void *);
 		else if(flags&SHORT) snum = va_arg(*args, short);
 		else if(flags&LONG) snum = va_arg(*args, long);
 		else if(flags&VLONG) snum = va_arg(*args, long long);
@@ -311,7 +311,8 @@
 		}
 	} else {
 		sign = "";
-		if(flags&PTR) num = (long)va_arg(*args, void *);
+		if(flags&PTR) num = /* (uintptr_t) */ (unsigned long long)
+			va_arg(*args, void *);
 		else if(flags&SHORT) num = va_arg(*args, unsigned short);
 		else if(flags&LONG) num = va_arg(*args, unsigned long);
 		else if(flags&VLONG) num = va_arg(*args, unsigned long long);
@@ -457,6 +458,7 @@
 	char *eptr;
 	double d;
 
+	digits = eptr = 0;
 	echr = 'e';
 	fmt = afmt;
 	d = va_arg(*args, double);
diff -Nru /n/sources/plan9/sys/src/ape/lib/ap/stdio/vfscanf.c /sys/src/ape/lib/ap/stdio/vfscanf.c
--- /n/sources/plan9/sys/src/ape/lib/ap/stdio/vfscanf.c	Wed Jul 14 20:24:39 2010
+++ /sys/src/ape/lib/ap/stdio/vfscanf.c	Thu Aug 25 00:00:00 2016
@@ -4,7 +4,6 @@
 #include "iolib.h"
 #include <stdarg.h>
 #include <math.h>
-#include <stdlib.h>
 #include <ctype.h>
 static int icvt_f(FILE *f, va_list *args, int store, int width, int type);
 static int icvt_x(FILE *f, va_list *args, int store, int width, int type);
@@ -106,8 +105,7 @@
 	return ncvt;	
 }
 static int icvt_n(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref f
-#pragma ref width
+	USED(f, width);
 	if(store){
 		--ncvt;	/* this assignment doesn't count! */
 		switch(type){
@@ -279,9 +277,11 @@
 	return 1;
 }
 static int icvt_s(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
 	int c, nn;
 	register char *s;
+
+	USED(type);
+	s = 0;
 	if(store) s=va_arg(*args, char *);
 	do
 		c=ngetc(f);
@@ -307,9 +307,11 @@
 	return 1;
 }
 static int icvt_c(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
 	int c;
 	register char *s;
+
+	USED(type);
+	s = 0;
 	if(store) s=va_arg(*args, char *);
 	if(width<0) width=1;
 	for(;;){
@@ -339,10 +341,11 @@
 	return !ok;
 }
 static int icvt_sq(FILE *f, va_list *args, int store, int width, int type){
-#pragma ref type
 	int c, nn;
 	register char *s;
 	register const char *pat;
+	USED(type);
+	s = 0;
 	pat=++fmtp;
 	if(*fmtp=='^') fmtp++;
 	if(*fmtp!='\0') fmtp++;

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.