From ff7df21b6740d7da4f9bcf56f03b9c5b209f6996 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 9 Mar 2007 00:53:49 +0000 Subject: [PATCH] New module 'fseterr'. --- ChangeLog | 6 ++++++ lib/fseterr.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/fseterr.h | 38 ++++++++++++++++++++++++++++++++++++++ modules/fseterr | 23 +++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 lib/fseterr.c create mode 100644 lib/fseterr.h create mode 100644 modules/fseterr diff --git a/ChangeLog b/ChangeLog index f8b6a7bcb..8b308c17b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2007-03-08 Bruno Haible + * modules/fseterr: New file. + * lib/fseterr.h: New file. + * lib/fseterr.c: New file. + +2007-03-08 Bruno Haible + * lib/fnmatch_.h: Convert tabs in the middle of lines to spaces. * lib/getopt_.h: Likewise. * lib/mbswidth.h: Likewise. diff --git a/lib/fseterr.c b/lib/fseterr.c new file mode 100644 index 000000000..5ff8ba7e7 --- /dev/null +++ b/lib/fseterr.c @@ -0,0 +1,55 @@ +/* Set the error indicator of a stream. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#include + +/* Specification. */ +#include "fseterr.h" + +void +fseterr (FILE *fp) +{ + /* Most systems provide FILE as a struct and the necessary bitmask in + , because they need it for implementing getc() and putc() as + fast macros. */ +#if defined _IO_ferror_unlocked /* GNU libc, BeOS */ + fp->_flags |= _IO_ERR_SEEN; +#elif defined __sferror /* FreeBSD, NetBSD, OpenBSD, MacOS X, Cygwin */ + fp->_flags |= __SERR; +#elif defined _IOERR /* AIX, HP-UX, IRIX, OSF/1, Solaris, mingw */ + fp->_flag |= _IOERR; +#else /* unknown */ + /* Portable fallback, based on an idea by Rich Felker. + Wow! 6 system calls for something that is just a bit operation! */ + int fd; + int fd2; + + fflush (fp); + fd = fileno (fp); + fd2 = dup (fd); + if (fd2 >= 0) + { + close (fd); + fputc ('\0', fp); /* This should set the error indicator. */ + fflush (fp); /* Or this. */ + if (dup2 (fd2, fd) < 0) + /* Whee... we botched the stream and now cannot restore it! */ + abort (); + close (fd2); + } +#endif +} diff --git a/lib/fseterr.h b/lib/fseterr.h new file mode 100644 index 000000000..0ed749a44 --- /dev/null +++ b/lib/fseterr.h @@ -0,0 +1,38 @@ +/* Set the error indicator of a stream. + Copyright (C) 2007 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef _FSETERR_H +#define _FSETERR_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + + +/* Set the error indicator of the stream FP. + The "error indicator" is set when an I/O operation on the stream fails, and + is cleared (together with the "end-of-file" indicator) by clearerr (FP). */ +extern void fseterr (FILE *fp); + + +#ifdef __cplusplus +} +#endif + +#endif /* _FSETERR_H */ diff --git a/modules/fseterr b/modules/fseterr new file mode 100644 index 000000000..2ff5961b4 --- /dev/null +++ b/modules/fseterr @@ -0,0 +1,23 @@ +Description: +Set the error indicator of a stream. + +Files: +lib/fseterr.h +lib/fseterr.c + +Depends-on: + +configure.ac: + +Makefile.am: +lib_SOURCES += fseterr.c + +Include: +"fseterr.h" + +License: +LGPL + +Maintainer: +Bruno Haible + -- 2.11.0