* stdio-common/Makefile (tests): Add tst-fmemopen.
	* stdio-common/tst-fmemopen.c: New file.
	Test case by Ben Collins <bcollins@debian.org>.

	* libio/iofopncook.c (_IO_cookie_seek): Correct test for error.

	* libio/fmemopen.c (fmemopen_read): Return 0 at end of buffer.
	(fmemopen_write): Set errno at end of buffer.
This commit is contained in:
Ulrich Drepper 2000-10-31 05:20:53 +00:00
parent 02fb3d179d
commit de153e7f50
5 changed files with 194 additions and 4 deletions

View file

@ -1,5 +1,14 @@
2000-10-30 Ulrich Drepper <drepper@redhat.com>
* stdio-common/Makefile (tests): Add tst-fmemopen.
* stdio-common/tst-fmemopen.c: New file.
Test case by Ben Collins <bcollins@debian.org>.
* libio/iofopncook.c (_IO_cookie_seek): Correct test for error.
* libio/fmemopen.c (fmemopen_read): Return 0 at end of buffer.
(fmemopen_write): Set errno at end of buffer.
* posix/runtests.c (main): Don't use exit() to avoid warning with
broken compilers.

View file

@ -69,6 +69,7 @@
* so I don't need the stream to add null characters on its own.)
*/
#include <errno.h>
#include <libio.h>
#include <stdio.h>
#include <stdlib.h>
@ -96,7 +97,7 @@ fmemopen_read (void *cookie, char *b, size_t s)
if (c->pos + s > c->size)
{
if (c->pos == c->size)
return -1;
return 0;
s = c->size - c->pos;
}
@ -123,7 +124,10 @@ fmemopen_write (void *cookie, const char *b, size_t s)
if (c->pos + s + addnullc > c->size)
{
if (c->pos + addnullc == c->size)
return -1;
{
__set_errno (ENOSPC);
return -1;
}
s = c->size - c->pos - addnullc;
}
@ -142,7 +146,7 @@ fmemopen_write (void *cookie, const char *b, size_t s)
int
fmemopen_seek (void *cookie, _IO_off64_t * p, int w)
fmemopen_seek (void *cookie, _IO_off64_t *p, int w)
{
_IO_off64_t np;
fmemopen_cookie_t *c;

View file

@ -76,7 +76,8 @@ _IO_cookie_seek (fp, offset, dir)
return ((cfile->__io_functions.seek == NULL
|| (cfile->__io_functions.seek (cfile->__cookie, &offset, dir)
== (_IO_off64_t) -1))
== -1)
|| offset == (_IO_off64_t) -1)
? _IO_pos_BAD : offset);
}

View file

@ -1,3 +1,68 @@
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/translit_hangul: New file.
* locales/ko_KR (LC_CTYPE): Include it.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/translit_cjk_variants: New file.
* locales/ja_JP (LC_CTYPE): Include it.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/da_DK (LC_CTYPE): Include translit_combining, add A-ring
transliteration rules.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/de_DE (LC_CTYPE): Include translit_combining, add umlaut
transliteration rules.
* locales/de_AT (LC_CTYPE): Include de_DE instead of i18n.
* locales/de_BE (LC_CTYPE): Likewise.
* locales/de_CH (LC_CTYPE): Likewise.
* locales/de_LU (LC_CTYPE): Likewise.
* locales/de_DE@euro (LC_CTYPE): Include de_DE instead of i18n.
* locales/de_AT@euro (LC_CTYPE): Include de_AT instead of i18n.
* locales/de_BE@euro (LC_CTYPE): Include de_BE instead of i18n.
* locales/de_LU@euro (LC_CTYPE): Include de_LU instead of i18n.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/translit_combining: New file.
* locales/fr_FR (LC_CTYPE): Include it.
* locales/fr_BE (LC_CTYPE): Include fr_FR instead of i18n.
* locales/fr_CA (LC_CTYPE): Likewise.
* locales/fr_CH (LC_CTYPE): Likewise.
* locales/fr_LU (LC_CTYPE): Likewise.
* locales/fr_FR@euro (LC_CTYPE): Include fr_FR instead of i18n.
* locales/fr_BE@euro (LC_CTYPE): Include fr_BE instead of i18n.
* locales/fr_LU@euro (LC_CTYPE): Include fr_LU instead of i18n.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/translit_wide: New file.
* locales/translit_narrow: New file.
* locales/translit_font: New file.
* locales/translit_circle: New file.
* locales/translit_small: New file.
* locales/translit_fraction: New file.
* locales/translit_compat: New file.
* locales/translit_cjk_compat: New file.
* locales/translit_neutral: New file. Include all of the above.
* locales/i18n (LC_CTYPE): Include translit_neutral. Remove a few
German and Danish specific rules.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* locales/ja_JP (LC_CTYPE): Refer to "i18n" instead of duplicating it.
* locales/zh_CN (LC_CTYPE): Likewise.
* locales/ko_KR (LC_CTYPE): Likewise.
2000-10-29 Bruno Haible <haible@clisp.cons.org>
* charmaps/UTF-8: Set width of U200B to 0.
* charmaps/GB18030: Likewise.
2000-10-29 Ulrich Drepper <drepper@redhat.com>
* charmaps/BIG5: Update.

111
stdio-common/tst-fmemopen.c Normal file
View file

@ -0,0 +1,111 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#define TEST_FILE "test-1"
int
main (void)
{
const char blah[] = "BLAH";
FILE *fp;
char *mmap_data;
int ch, fd;
struct stat fs;
const char *cp;
/* setup the physical file, and use it */
if ((fp = fopen (TEST_FILE, "w+")) == NULL)
exit (1);
if (fwrite (blah, 1, strlen (blah), fp) != strlen (blah))
exit (2);
rewind (fp);
printf ("file: ");
cp = blah;
while ((ch = getc (fp)) != EOF)
{
fputc (ch, stdout);
if (ch != *cp)
{
printf ("\ncharacter %d: '%c' instead of '%c'\n",
cp - blah, ch, *cp);
exit (1);
}
++cp;
}
fputc ('\n', stdout);
if (ferror (fp))
{
puts ("fp: error");
exit (1);
}
if (feof (fp))
printf ("fp: EOF\n");
else
{
puts ("not EOF");
exit (1);
}
fclose (fp);
/* Now, mmap the file into a buffer, and do that too */
if ((fd = open (TEST_FILE, O_RDONLY)) == -1)
exit (3);
if (fstat (fd, &fs) == -1)
exit (4);
if ((mmap_data = (char *) mmap (NULL, fs.st_size, PROT_READ,
MAP_SHARED, fd, 0)) == NULL)
{
if (errno == ENOSYS)
exit (0);
exit (5);
}
if ((fp = fmemopen (mmap_data, fs.st_size, "r")) == NULL)
exit (1);
printf ("mem: ");
cp = blah;
while ((ch = getc (fp)) != EOF)
{
fputc (ch, stdout);
if (ch != *cp)
{
printf ("%d character: '%c' instead of '%c'\n",
cp - blah, ch, *cp);
exit (1);
}
++cp;
}
fputc ('\n', stdout);
if (ferror (fp))
{
puts ("fp: error");
exit (1);
}
if (feof (fp))
printf ("fp: EOF\n");
else
{
puts ("not EOF");
exit (1);
}
fclose (fp);
munmap (mmap_data, fs.st_size);
unlink (TEST_FILE);
return 0;
}