This is the mail archive of the newlib@sourceware.cygnus.com mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Implementations of getw() and putw()


I'm checking this in, approved by J. Johnston:

Index: newlib/ChangeLog
from  Alexandre Oliva  <oliva@lsd.ic.unicamp.br>
	
	* libc/stdio/Makefile.am (lib_a_SOURCES): Added getw.c and putw.c.
	(CHEWOUT_FILES): Added getw.def and putw.def.
	* libc/stdio/Makefile.in: Rebuilt.
	* libc/stdio/stdio.tex: Include getw.def and putw.def.
	* libc/stdio/getw.c: New file.
	* libc/stdio/putw.c: New file.

Index: newlib/libc/stdio/Makefile.am
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/stdio/Makefile.am,v
retrieving revision 1.2
diff -u -r1.2 Makefile.am
--- newlib/libc/stdio/Makefile.am	1999/07/06 14:52:14	1.2
+++ newlib/libc/stdio/Makefile.am	2000/03/04 06:54:37
@@ -36,6 +36,7 @@
 	getc.c 				\
 	getchar.c 			\
 	gets.c 				\
+	getw.c				\
 	iprintf.c 			\
 	makebuf.c			\
 	mktemp.c 			\
@@ -44,6 +45,7 @@
 	putc.c 				\
 	putchar.c 			\
 	puts.c 				\
+	putw.c				\
 	refill.c 			\
 	remove.c 			\
 	rename.c 			\
@@ -97,12 +99,14 @@
 	getc.def		\
 	getchar.def		\
 	gets.def		\
+	getw.def		\
 	iprintf.def		\
 	mktemp.def		\
 	perror.def		\
 	putc.def		\
 	putchar.def		\
 	puts.def		\
+	putw.def		\
 	remove.def		\
 	rename.def		\
 	rewind.def		\
Index: newlib/libc/stdio/stdio.tex
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/stdio/stdio.tex,v
retrieving revision 1.12
diff -u -r1.12 stdio.tex
--- newlib/libc/stdio/stdio.tex	1993/09/10 19:59:16	1.12
+++ newlib/libc/stdio/stdio.tex	2000/03/04 06:54:38
@@ -46,12 +46,14 @@
 * getc::        Get a character from a file or stream (macro)
 * getchar::     Get a character from standard input (macro)
 * gets::        Get character string from standard input (obsolete)
+* getw::        Get a word (int) from a file or stream
 * iprintf::     Write formatted output (integer only)
 * mktemp::      Generate unused file name
 * perror::      Print an error message on standard error
 * putc::        Write a character on a stream or file (macro)
 * putchar::     Write a character on standard output (macro)
 * puts::        Write a character string on standard output
+* putw::        Write a word (int) to a file or stream
 * remove::      Delete a file's name
 * rename::      Rename a file
 * rewind::      Reinitialize a file or stream
@@ -131,6 +133,9 @@
 @page 
 @include stdio/gets.def
 
+@page 
+@include stdio/getw.def 
+
 @page
 @include stdio/iprintf.def 
 
@@ -148,6 +153,9 @@
 
 @page
 @include stdio/puts.def
+
+@page 
+@include stdio/putw.def 
 
 @page
 @include stdio/remove.def
Index: newlib/libc/stdio/getw.c
===================================================================
RCS file: getw.c
diff -N getw.c
--- newlib/libc/stdio/getw.c	Tue May  5 13:32:27 1998
+++ newlib/libc/stdio/getw.c	Fri Mar  3 22:54:38 2000
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+FUNCTION
+<<getw>>---read a word (int)
+
+INDEX
+	getw
+
+ANSI_SYNOPSIS
+	#include <stdio.h>
+	int getw(FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+	#include <stdio.h>
+	int getw(<[fp]>)
+	FILE *<[fp]>;
+
+DESCRIPTION
+<<getw>> is a function, defined in <<stdio.h>>.  You can use <<getw>>
+to get the next word from the file or stream identified by <[fp]>.  As
+a side effect, <<getw>> advances the file's current position
+indicator.
+
+RETURNS The next word (read as an <<int>>), unless there is no more
+data, or the host system reports a read error; in either of these
+situations, <<getw>> returns <<EOF>>.  Since <<EOF>> is a valid
+<<int>>, you must use <<ferror>> or <<feof>> to distinguish these
+situations.
+
+PORTABILITY
+<<getw>> is a remnant of K&R C, it is not part of any ISO C Standard.
+<<fread>> should be used instead.  In fact, this implementation of
+<<getw>> is based upon <<fread>>.
+
+Supporting OS subroutines required: <<fread>>.  */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+
+int
+getw (fp)
+     register FILE *fp;
+{
+  int result;
+  if (fread((char*)&result, sizeof(result), 1, fp) != 1)
+    return EOF;
+  return result;
+}
Index: newlib/libc/stdio/putw.c
===================================================================
RCS file: putw.c
diff -N putw.c
--- newlib/libc/stdio/putw.c	Tue May  5 13:32:27 1998
+++ newlib/libc/stdio/putw.c	Fri Mar  3 22:54:39 2000
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+/*
+FUNCTION
+<<putw>>---write a word (int)
+
+INDEX
+	putw
+
+ANSI_SYNOPSIS
+	#include <stdio.h>
+	int putw(int <[w]>, FILE *<[fp]>);
+
+TRAD_SYNOPSIS
+	#include <stdio.h>
+	int putw(<w>, <[fp]>)
+	int <w>;
+	FILE *<[fp]>;
+
+DESCRIPTION
+<<putw>> is a function, defined in <<stdio.h>>.  You can use <<putw>>
+to write a word to the file or stream identified by <[fp]>.  As a side
+effect, <<putw>> advances the file's current position indicator.
+
+RETURNS The written word, unless the host system reports a write
+error, in which case <<putw>> returns <<EOF>>.  Since <<EOF>> is a
+valid <<int>>, you must use <<ferror>> or <<feof>> to distinguish
+these situations when writing the integer equal to <<EOF>>.
+
+PORTABILITY
+<<putw>> is a remnant of K&R C, it is not part of any ISO C Standard.
+<<fwrite>> should be used instead.  In fact, this implementation of
+<<putw>> is based upon <<fwrite>>.
+
+Supporting OS subroutines required: <<fwrite>>.  */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char sccsid[] = "%W% (Berkeley) %G%";
+#endif /* LIBC_SCCS and not lint */
+
+#include <stdio.h>
+
+int
+putw (w, fp)
+     int w;
+     register FILE *fp;
+{
+  if (fwrite((const char*)&w, sizeof(w), 1, fp) != 1)
+    return EOF;
+  return w;
+}
Index: newlib/libc/stdio/Makefile.in
===================================================================
RCS file: /cvs/cvsfiles/devo/newlib/libc/stdio/Makefile.in,v
retrieving revision 1.40
diff -u -r1.40 Makefile.in
--- newlib/libc/stdio/Makefile.in	1999/07/06 14:52:14	1.40
+++ newlib/libc/stdio/Makefile.in	2000/03/04 06:30:05
@@ -118,6 +118,7 @@
 	getc.c 				\
 	getchar.c 			\
 	gets.c 				\
+	getw.c 				\
 	iprintf.c 			\
 	makebuf.c			\
 	mktemp.c 			\
@@ -126,6 +127,7 @@
 	putc.c 				\
 	putchar.c 			\
 	puts.c 				\
+	putw.c 				\
 	refill.c 			\
 	remove.c 			\
 	rename.c 			\
@@ -177,12 +179,14 @@
 	getc.def		\
 	getchar.def		\
 	gets.def		\
+	getw.def		\
 	iprintf.def		\
 	mktemp.def		\
 	perror.def		\
 	putc.def		\
 	putchar.def		\
 	puts.def		\
+	putw.def		\
 	remove.def		\
 	rename.def		\
 	rewind.def		\
@@ -216,8 +220,8 @@
 lib_a_OBJECTS =  clearerr.o fclose.o fdopen.o feof.o ferror.o fflush.o \
 fgetc.o fgetpos.o fgets.o fileno.o findfp.o fiprintf.o flags.o fopen.o \
 fprintf.o fputc.o fputs.o fread.o freopen.o fscanf.o fseek.o fsetpos.o \
-ftell.o fvwrite.o fwalk.o fwrite.o getc.o getchar.o gets.o iprintf.o \
-makebuf.o mktemp.o perror.o printf.o putc.o putchar.o puts.o refill.o \
+ftell.o fvwrite.o fwalk.o fwrite.o getc.o getchar.o gets.o getw.o iprintf.o \
+makebuf.o mktemp.o perror.o printf.o putc.o putchar.o puts.o putw.o refill.o \
 remove.o rename.o rewind.o rget.o scanf.o setbuf.o setvbuf.o siprintf.o \
 snprintf.o sprintf.o sscanf.o stdio.o tmpfile.o tmpnam.o ungetc.o \
 vfprintf.o vfscanf.o vprintf.o vsnprintf.o vsprintf.o wbuf.o wsetup.o

-- 
Alexandre Oliva     http://www.ic.unicamp.br/~oliva/     Enjoy Guaranį
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]