glibc/stdio-common/tst-ungetc.c
Ulrich Drepper 74e8f2dcaa Update.
2002-12-19  Jakub Jelinek  <jakub@redhat.com>

	* nscd/connections.c (nscd_run): Shut up warning.
	* tst-ungetc.c (assert): Undefined before redefining.

2002-12-19  Ulrich Drepper  <drepper@redhat.com>

	* posix/regex.c: Use __builtin_expect even outside glibc if gcc 3
	is used.

2002-12-17  Art Haas  <ahaas@airmail.net>

	* iconvdata/cp737.h: Convert GCC extension initializer syntax to C99.
	* iconvdata/cp775.h: Likewise.
	* iconvdata/ibm1046.h: Likewise.
	* iconvdata/ibm1124.h: Likewise.
	* iconvdata/ibm1129.h: Likewise.
	* iconvdata/ibm1132.h: Likewise.
	* iconvdata/ibm1133.h: Likewise.
	* iconvdata/ibm1160.h: Likewise.
	* iconvdata/ibm1161.h: Likewise.
	* iconvdata/ibm1162.h: Likewise.
	* iconvdata/ibm1163.h: Likewise.
	* iconvdata/ibm1164.h: Likewise.

	(__ASSUME_CLONE_THREAD_FLAGS): Define for x86 and kernel >= 2.5.50.
2002-12-19 09:18:01 +00:00

64 lines
1.2 KiB
C

/* Test for ungetc bugs. */
#include <stdio.h>
#include <unistd.h>
#undef assert
#define assert(x) \
if (!(x)) \
{ \
fputs ("test failed: " #x "\n", stderr); \
retval = 1; \
goto the_end; \
}
int
main (int argc, char *argv[])
{
char *name;
FILE *fp = NULL;
int retval = 0;
int c;
char buffer[64];
name = tmpnam (NULL);
fp = fopen (name, "w");
assert (fp != NULL)
fputs ("bla", fp);
fclose (fp);
fp = NULL;
fp = fopen (name, "r");
assert (fp != NULL);
assert (ungetc ('z', fp) == 'z');
assert (getc (fp) == 'z');
assert (getc (fp) == 'b');
assert (getc (fp) == 'l');
assert (ungetc ('m', fp) == 'm');
assert (getc (fp) == 'm');
assert ((c = getc (fp)) == 'a');
assert (getc (fp) == EOF);
assert (ungetc (c, fp) == c);
assert (feof (fp) == 0);
assert (getc (fp) == c);
assert (getc (fp) == EOF);
fclose (fp);
fp = NULL;
fp = fopen (name, "r");
assert (fp != NULL);
assert (getc (fp) == 'b');
assert (getc (fp) == 'l');
assert (ungetc ('b', fp) == 'b');
assert (fread (buffer, 1, 64, fp) == 2);
assert (buffer[0] == 'b');
assert (buffer[1] == 'a');
the_end:
if (fp != NULL)
fclose (fp);
unlink (name);
return retval;
}