diff options
author | Simon Josefsson <simon@josefsson.org> | 2004-08-14 16:58:03 +0000 |
---|---|---|
committer | Simon Josefsson <simon@josefsson.org> | 2004-08-14 16:58:03 +0000 |
commit | 83dcb7d3576caa762b191c5da342093d16f64a81 (patch) | |
tree | bc84b583c2eb9f083584b6ed9357c19672f61d14 /gl | |
parent | 33412ddebe0aad0ffaa9514450f4884c471becc2 (diff) | |
download | gnutls-83dcb7d3576caa762b191c5da342093d16f64a81.tar.gz |
Set up GnuTLS to use gnulib for portability files.
Initially only adding "getline", I will need it for S/MIME parsing.
Diffstat (limited to 'gl')
-rw-r--r-- | gl/Makefile.am | 32 | ||||
-rw-r--r-- | gl/getline.c | 44 | ||||
-rw-r--r-- | gl/getline.h | 39 | ||||
-rw-r--r-- | gl/getndelim2.c | 153 | ||||
-rw-r--r-- | gl/getndelim2.h | 43 | ||||
-rw-r--r-- | gl/m4/extensions.m4 | 29 | ||||
-rw-r--r-- | gl/m4/getline.m4 | 76 | ||||
-rw-r--r-- | gl/m4/getndelim2.m4 | 27 | ||||
-rw-r--r-- | gl/m4/gnulib.m4 | 32 | ||||
-rw-r--r-- | gl/m4/onceonly_2_57.m4 | 86 | ||||
-rw-r--r-- | gl/m4/ssize_t.m4 | 22 | ||||
-rw-r--r-- | gl/m4/unlocked-io.m4 | 22 | ||||
-rw-r--r-- | gl/unlocked-io.h | 132 |
13 files changed, 737 insertions, 0 deletions
diff --git a/gl/Makefile.am b/gl/Makefile.am new file mode 100644 index 0000000000..70a41338be --- /dev/null +++ b/gl/Makefile.am @@ -0,0 +1,32 @@ +## Process this file with automake to produce Makefile.in. +# Copyright (C) 2004 Free Software Foundation, Inc. +# +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Automake, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool + +AUTOMAKE_OPTIONS = 1.8 gnits + +noinst_LTLIBRARIES = libgnu.la + +libgnu_la_SOURCES = +libgnu_la_LIBADD = @LTLIBOBJS@ +EXTRA_DIST = +BUILT_SOURCES = +SUFFIXES = +MOSTLYCLEANFILES = +CLEANFILES = +DISTCLEANFILES = +MAINTAINERCLEANFILES = + +libgnu_la_SOURCES += getline.h +EXTRA_DIST += getndelim2.h getndelim2.c + +libgnu_la_SOURCES += unlocked-io.h + diff --git a/gl/getline.c b/gl/getline.c new file mode 100644 index 0000000000..746d708878 --- /dev/null +++ b/gl/getline.c @@ -0,0 +1,44 @@ +/* getline.c -- Replacement for GNU C library function getline + + Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003, 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Jan Brittenson, bson@gnu.ai.mit.edu. */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +#include "getline.h" + +#if ! (defined __GNU_LIBRARY__ && HAVE_GETDELIM) + +# include "getndelim2.h" + +ssize_t +getdelim (char **lineptr, size_t *linesize, int delimiter, FILE *stream) +{ + return getndelim2 (lineptr, linesize, 0, GETNLINE_NO_LIMIT, delimiter, EOF, + stream); +} +#endif + +ssize_t +getline (char **lineptr, size_t *linesize, FILE *stream) +{ + return getdelim (lineptr, linesize, '\n', stream); +} diff --git a/gl/getline.h b/gl/getline.h new file mode 100644 index 0000000000..ee9fc052c1 --- /dev/null +++ b/gl/getline.h @@ -0,0 +1,39 @@ +/* Replacement for GNU C library function getline + + Copyright (C) 1995, 1997, 1999, 2000, 2001, 2002, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef GETLINE_H_ +# define GETLINE_H_ 1 + +# include <stddef.h> +# include <stdio.h> + +/* Get ssize_t. */ +# include <sys/types.h> + +/* glibc2 has these functions declared in <stdio.h>. Avoid redeclarations. */ +# if __GLIBC__ < 2 + +extern ssize_t getline (char **_lineptr, size_t *_linesize, FILE *_stream); + +extern ssize_t getdelim (char **_lineptr, size_t *_linesize, int _delimiter, + FILE *_stream); + +# endif + +#endif /* not GETLINE_H_ */ diff --git a/gl/getndelim2.c b/gl/getndelim2.c new file mode 100644 index 0000000000..9571e50a8f --- /dev/null +++ b/gl/getndelim2.c @@ -0,0 +1,153 @@ +/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters, + with bounded memory allocation. + + Copyright (C) 1993, 1996, 1997, 1998, 2000, 2003, 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Originally written by Jan Brittenson, bson@gnu.ai.mit.edu. */ + +#if HAVE_CONFIG_H +# include <config.h> +#endif + +#include "getndelim2.h" + +#include <stdlib.h> +#include <stddef.h> + +#include "unlocked-io.h" + +#include <limits.h> +#if HAVE_INTTYPES_H +# include <inttypes.h> +#endif +#if HAVE_STDINT_H +# include <stdint.h> +#endif +#ifndef PTRDIFF_MAX +# define PTRDIFF_MAX ((ptrdiff_t) (SIZE_MAX / 2)) +#endif +#ifndef SIZE_MAX +# define SIZE_MAX ((size_t) -1) +#endif +#ifndef SSIZE_MAX +# define SSIZE_MAX ((ssize_t) (SIZE_MAX / 2)) +#endif + +/* The maximum value that getndelim2 can return without suffering from + overflow problems, either internally (because of pointer + subtraction overflow) or due to the API (because of ssize_t). */ +#define GETNDELIM2_MAXIMUM (PTRDIFF_MAX < SSIZE_MAX ? PTRDIFF_MAX : SSIZE_MAX) + +/* Try to add at least this many bytes when extending the buffer. + MIN_CHUNK must be no greater than GETNDELIM2_MAXIMUM. */ +#define MIN_CHUNK 64 + +ssize_t +getndelim2 (char **lineptr, size_t *linesize, size_t offset, size_t nmax, + int delim1, int delim2, FILE *stream) +{ + size_t nbytes_avail; /* Allocated but unused bytes in *LINEPTR. */ + char *read_pos; /* Where we're reading into *LINEPTR. */ + ssize_t bytes_stored = -1; + char *ptr = *lineptr; + size_t size = *linesize; + + if (!ptr) + { + size = nmax < MIN_CHUNK ? nmax : MIN_CHUNK; + ptr = malloc (size); + if (!ptr) + return -1; + } + + if (size < offset) + goto done; + + nbytes_avail = size - offset; + read_pos = ptr + offset; + + if (nbytes_avail == 0 && nmax <= size) + goto done; + + for (;;) + { + /* Here always ptr + size == read_pos + nbytes_avail. */ + + int c; + + /* We always want at least one byte left in the buffer, since we + always (unless we get an error while reading the first byte) + NUL-terminate the line buffer. */ + + if (nbytes_avail < 2 && size < nmax) + { + size_t newsize = size < MIN_CHUNK ? size + MIN_CHUNK : 2 * size; + char *newptr; + + if (! (size < newsize && newsize <= nmax)) + newsize = nmax; + + if (GETNDELIM2_MAXIMUM < newsize - offset) + { + size_t newsizemax = offset + GETNDELIM2_MAXIMUM + 1; + if (size == newsizemax) + goto done; + newsize = newsizemax; + } + + nbytes_avail = newsize - (read_pos - ptr); + newptr = realloc (ptr, newsize); + if (!newptr) + goto done; + ptr = newptr; + size = newsize; + read_pos = size - nbytes_avail + ptr; + } + + c = getc (stream); + if (c == EOF) + { + /* Return partial line, if any. */ + if (read_pos == ptr) + goto done; + else + break; + } + + if (nbytes_avail >= 2) + { + *read_pos++ = c; + nbytes_avail--; + } + + if (c == delim1 || c == delim2) + /* Return the line. */ + break; + } + + /* Done - NUL terminate and return the number of bytes read. + At this point we know that nbytes_avail >= 1. */ + *read_pos = '\0'; + + bytes_stored = read_pos - (ptr + offset); + + done: + *lineptr = ptr; + *linesize = size; + return bytes_stored; +} diff --git a/gl/getndelim2.h b/gl/getndelim2.h new file mode 100644 index 0000000000..39f80cb557 --- /dev/null +++ b/gl/getndelim2.h @@ -0,0 +1,43 @@ +/* getndelim2 - Read a line from a stream, stopping at one of 2 delimiters, + with bounded memory allocation. + + Copyright (C) 2003, 2004 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +#ifndef GETNDELIM2_H +#define GETNDELIM2_H 1 + +#include <stdio.h> +#include <sys/types.h> + +#define GETNLINE_NO_LIMIT ((size_t) -1) + +/* Read into a buffer *LINEPTR returned from malloc (or NULL), + pointing to *LINESIZE bytes of space. Store the input bytes + starting at *LINEPTR + OFFSET, and null-terminate them. Reallocate + the buffer as necessary, but if NMAX is not GETNLINE_NO_LIMIT + then do not allocate more than NMAX bytes; if the line is longer + than that, read and discard the extra bytes. Stop reading after + after the first occurrence of DELIM1 or DELIM2, whichever comes + first; a delimiter equal to EOF stands for no delimiter. Read the + input bytes from STREAM. + Return the number of bytes read and stored at *LINEPTR + OFFSET (not + including the NUL terminator), or -1 on error or EOF. */ +extern ssize_t getndelim2 (char **lineptr, size_t *linesize, size_t offset, + size_t nmax, int delim1, int delim2, + FILE *stream); + +#endif /* GETNDELIM2_H */ diff --git a/gl/m4/extensions.m4 b/gl/m4/extensions.m4 new file mode 100644 index 0000000000..58bc0beb6d --- /dev/null +++ b/gl/m4/extensions.m4 @@ -0,0 +1,29 @@ +# Enable extensions on systems that normally disable them. + +# Copyright (C) 2003 Free Software Foundation, Inc. + +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. + +# gl_USE_SYSTEM_EXTENSIONS +# ------------------------ +# Enable extensions on systems that normally disable them, +# typically due to standards-conformance issues. +AC_DEFUN([gl_USE_SYSTEM_EXTENSIONS], [ + AC_BEFORE([$0], [AC_COMPILE_IFELSE]) + AC_BEFORE([$0], [AC_RUN_IFELSE]) + + AC_REQUIRE([AC_GNU_SOURCE]) + AC_REQUIRE([AC_AIX]) + AC_REQUIRE([AC_MINIX]) + + AH_VERBATIM([__EXTENSIONS__], +[/* Enable extensions on Solaris. */ +#ifndef __EXTENSIONS__ +# undef __EXTENSIONS__ +#endif]) + AC_DEFINE([__EXTENSIONS__]) +]) diff --git a/gl/m4/getline.m4 b/gl/m4/getline.m4 new file mode 100644 index 0000000000..56960c9371 --- /dev/null +++ b/gl/m4/getline.m4 @@ -0,0 +1,76 @@ +# getline.m4 serial 10 + +dnl Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 Free Software +dnl Foundation, Inc. + +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +AC_PREREQ(2.52) + +dnl See if there's a working, system-supplied version of the getline function. +dnl We can't just do AC_REPLACE_FUNCS(getline) because some systems +dnl have a function by that name in -linet that doesn't have anything +dnl to do with the function we need. +AC_DEFUN([AM_FUNC_GETLINE], +[ + dnl Persuade glibc <stdio.h> to declare getline() and getdelim(). + AC_REQUIRE([AC_GNU_SOURCE]) + + am_getline_needs_run_time_check=no + AC_CHECK_FUNC(getline, + dnl Found it in some library. Verify that it works. + am_getline_needs_run_time_check=yes, + am_cv_func_working_getline=no) + if test $am_getline_needs_run_time_check = yes; then + AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline, + [echo fooN |tr -d '\012'|tr N '\012' > conftest.data + AC_TRY_RUN([ +# include <stdio.h> +# include <stdlib.h> +# include <string.h> + int main () + { /* Based on a test program from Karl Heuer. */ + char *line = NULL; + size_t siz = 0; + int len; + FILE *in = fopen ("./conftest.data", "r"); + if (!in) + return 1; + len = getline (&line, &siz, in); + exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1); + } + ], am_cv_func_working_getline=yes dnl The library version works. + , am_cv_func_working_getline=no dnl The library version does NOT work. + , am_cv_func_working_getline=no dnl We're cross compiling. + )]) + fi + + if test $am_cv_func_working_getline = no; then + dnl We must choose a different name for our function, since on ELF systems + dnl a broken getline() in libc.so would override our getline() in + dnl libgettextlib.so. + AC_DEFINE([getline], [gnu_getline], + [Define to a replacement function name for getline().]) + AC_LIBOBJ(getline) + + # Avoid multiple inclusions of getndelim2.o into LIBOBJS. + # This hack won't be needed after gnulib requires Autoconf 2.58 or later. + case " $LIB@&t@OBJS " in + *" getndelim2.$ac_objext "* ) ;; + *) AC_LIBOBJ(getndelim2);; + esac + + gl_PREREQ_GETLINE + gl_PREREQ_GETNDELIM2 + fi +]) + +# Prerequisites of lib/getline.c. +AC_DEFUN([gl_PREREQ_GETLINE], +[ + AC_CHECK_FUNCS(getdelim) +]) diff --git a/gl/m4/getndelim2.m4 b/gl/m4/getndelim2.m4 new file mode 100644 index 0000000000..cd4ef4b671 --- /dev/null +++ b/gl/m4/getndelim2.m4 @@ -0,0 +1,27 @@ +# getndelim2.m4 serial 3 +dnl Copyright (C) 2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +AC_DEFUN([gl_GETNDELIM2], +[ + # Avoid multiple inclusions of getndelim2.o into LIBOBJS. + # This hack won't be needed after gnulib requires Autoconf 2.58 or later. + case " $LIB@&t@OBJS " in + *" getndelim2.$ac_objext "* ) ;; + *) AC_LIBOBJ(getndelim2);; + esac + + gl_PREREQ_GETNDELIM2 +]) + +# Prerequisites of lib/getndelim2.h and lib/getndelim2.c. +AC_DEFUN([gl_PREREQ_GETNDELIM2], +[ + dnl Prerequisites of lib/getndelim2.h. + AC_REQUIRE([gt_TYPE_SSIZE_T]) + dnl No prerequisites of lib/getndelim2.c. +]) diff --git a/gl/m4/gnulib.m4 b/gl/m4/gnulib.m4 new file mode 100644 index 0000000000..c5bef0a17e --- /dev/null +++ b/gl/m4/gnulib.m4 @@ -0,0 +1,32 @@ +# Copyright (C) 2004 Free Software Foundation, Inc. +# This file is free software, distributed under the terms of the GNU +# General Public License. As a special exception to the GNU General +# Public License, this file may be distributed as part of a program +# that contains a configuration script generated by Autoconf, under +# the same distribution terms as the rest of that program. +# +# Generated by gnulib-tool. +# +# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --libtool + +AC_DEFUN([gl_EARLY], +[ + AC_GNU_SOURCE + gl_USE_SYSTEM_EXTENSIONS +]) + +AC_DEFUN([gl_INIT], +[ + dnl gl_USE_SYSTEM_EXTENSIONS must be added quite early to configure.ac. + AM_FUNC_GETLINE + gl_FUNC_GLIBC_UNLOCKED_IO +]) + +dnl Usage: gl_MODULES(module1 module2 ...) +AC_DEFUN([gl_MODULES], []) + +dnl Usage: gl_SOURCE_BASE(DIR) +AC_DEFUN([gl_SOURCE_BASE], []) + +dnl Usage: gl_M4_BASE(DIR) +AC_DEFUN([gl_M4_BASE], []) diff --git a/gl/m4/onceonly_2_57.m4 b/gl/m4/onceonly_2_57.m4 new file mode 100644 index 0000000000..9fc510e06e --- /dev/null +++ b/gl/m4/onceonly_2_57.m4 @@ -0,0 +1,86 @@ +# onceonly_2_57.m4 serial 3 +dnl Copyright (C) 2002-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl This file defines some "once only" variants of standard autoconf macros. +dnl AC_CHECK_HEADERS_ONCE like AC_CHECK_HEADERS +dnl AC_CHECK_FUNCS_ONCE like AC_CHECK_FUNCS +dnl AC_CHECK_DECLS_ONCE like AC_CHECK_DECLS +dnl AC_REQUIRE([AC_HEADER_STDC]) like AC_HEADER_STDC +dnl The advantage is that the check for each of the headers/functions/decls +dnl will be put only once into the 'configure' file. It keeps the size of +dnl the 'configure' file down, and avoids redundant output when 'configure' +dnl is run. +dnl The drawback is that the checks cannot be conditionalized. If you write +dnl if some_condition; then gl_CHECK_HEADERS(stdlib.h); fi +dnl inside an AC_DEFUNed function, the gl_CHECK_HEADERS macro call expands to +dnl empty, and the check will be inserted before the body of the AC_DEFUNed +dnl function. + +dnl This is like onceonly.m4, except that it uses diversions to named sections +dnl DEFAULTS and INIT_PREPARE in order to check all requested headers at once, +dnl thus reducing the size of 'configure'. Works with autoconf-2.57. The +dnl size reduction is ca. 9%. + +dnl Autoconf version 2.57 or newer is recommended. +AC_PREREQ(2.54) + +# AC_CHECK_HEADERS_ONCE(HEADER1 HEADER2 ...) is a once-only variant of +# AC_CHECK_HEADERS(HEADER1 HEADER2 ...). +AC_DEFUN([AC_CHECK_HEADERS_ONCE], [ + : + AC_FOREACH([gl_HEADER_NAME], [$1], [ + AC_DEFUN([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, + [./-], [___])), [ + m4_divert_text([INIT_PREPARE], + [gl_header_list="$gl_header_list gl_HEADER_NAME"]) + gl_HEADERS_EXPANSION + AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_HEADER_NAME])), + [Define to 1 if you have the <]m4_defn([gl_HEADER_NAME])[> header file.]) + ]) + AC_REQUIRE([gl_CHECK_HEADER_]m4_quote(translit(gl_HEADER_NAME, + [./-], [___]))) + ]) +]) +m4_define([gl_HEADERS_EXPANSION], [ + m4_divert_text([DEFAULTS], [gl_header_list=]) + AC_CHECK_HEADERS([$gl_header_list]) + m4_define([gl_HEADERS_EXPANSION], []) +]) + +# AC_CHECK_FUNCS_ONCE(FUNC1 FUNC2 ...) is a once-only variant of +# AC_CHECK_FUNCS(FUNC1 FUNC2 ...). +AC_DEFUN([AC_CHECK_FUNCS_ONCE], [ + : + AC_FOREACH([gl_FUNC_NAME], [$1], [ + AC_DEFUN([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME]), [ + m4_divert_text([INIT_PREPARE], + [gl_func_list="$gl_func_list gl_FUNC_NAME"]) + gl_FUNCS_EXPANSION + AH_TEMPLATE(AS_TR_CPP([HAVE_]m4_defn([gl_FUNC_NAME])), + [Define to 1 if you have the `]m4_defn([gl_FUNC_NAME])[' function.]) + ]) + AC_REQUIRE([gl_CHECK_FUNC_]m4_defn([gl_FUNC_NAME])) + ]) +]) +m4_define([gl_FUNCS_EXPANSION], [ + m4_divert_text([DEFAULTS], [gl_func_list=]) + AC_CHECK_FUNCS([$gl_func_list]) + m4_define([gl_FUNCS_EXPANSION], []) +]) + +# AC_CHECK_DECLS_ONCE(DECL1 DECL2 ...) is a once-only variant of +# AC_CHECK_DECLS(DECL1, DECL2, ...). +AC_DEFUN([AC_CHECK_DECLS_ONCE], [ + : + AC_FOREACH([gl_DECL_NAME], [$1], [ + AC_DEFUN([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME]), [ + AC_CHECK_DECLS(m4_defn([gl_DECL_NAME])) + ]) + AC_REQUIRE([gl_CHECK_DECL_]m4_defn([gl_DECL_NAME])) + ]) +]) diff --git a/gl/m4/ssize_t.m4 b/gl/m4/ssize_t.m4 new file mode 100644 index 0000000000..56b7ea4336 --- /dev/null +++ b/gl/m4/ssize_t.m4 @@ -0,0 +1,22 @@ +# ssize_t.m4 serial 3 (gettext-0.13) +dnl Copyright (C) 2001-2003 Free Software Foundation, Inc. +dnl This file is free software, distributed under the terms of the GNU +dnl General Public License. As a special exception to the GNU General +dnl Public License, this file may be distributed as part of a program +dnl that contains a configuration script generated by Autoconf, under +dnl the same distribution terms as the rest of that program. + +dnl From Bruno Haible. +dnl Test whether ssize_t is defined. + +AC_DEFUN([gt_TYPE_SSIZE_T], +[ + AC_CACHE_CHECK([for ssize_t], gt_cv_ssize_t, + [AC_TRY_COMPILE([#include <sys/types.h>], + [int x = sizeof (ssize_t *) + sizeof (ssize_t);], + gt_cv_ssize_t=yes, gt_cv_ssize_t=no)]) + if test $gt_cv_ssize_t = no; then + AC_DEFINE(ssize_t, int, + [Define as a signed type of the same size as size_t.]) + fi +]) diff --git a/gl/m4/unlocked-io.m4 b/gl/m4/unlocked-io.m4 new file mode 100644 index 0000000000..cd1c5f4ef7 --- /dev/null +++ b/gl/m4/unlocked-io.m4 @@ -0,0 +1,22 @@ +#serial 9 + +dnl From Jim Meyering. +dnl +dnl See if the glibc *_unlocked I/O macros or functions are available. +dnl Use only those *_unlocked macros or functions that are declared +dnl (because some of them were declared in Solaris 2.5.1 but were removed +dnl in Solaris 2.6, whereas we want binaries built on Solaris 2.5.1 to run +dnl on Solaris 2.6). + +AC_DEFUN([gl_FUNC_GLIBC_UNLOCKED_IO], +[ + dnl Persuade glibc and Solaris <stdio.h> to declare + dnl fgets_unlocked(), fputs_unlocked() etc. + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_DECLS_ONCE( + [clearerr_unlocked feof_unlocked ferror_unlocked + fflush_unlocked fgets_unlocked fputc_unlocked fputs_unlocked + fread_unlocked fwrite_unlocked getc_unlocked + getchar_unlocked putc_unlocked putchar_unlocked]) +]) diff --git a/gl/unlocked-io.h b/gl/unlocked-io.h new file mode 100644 index 0000000000..36a7a4885d --- /dev/null +++ b/gl/unlocked-io.h @@ -0,0 +1,132 @@ +/* Prefer faster, non-thread-safe stdio functions if available. + + Copyright (C) 2001, 2002, 2003 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ + +/* Written by Jim Meyering. */ + +#ifndef UNLOCKED_IO_H +# define UNLOCKED_IO_H 1 + +# ifndef USE_UNLOCKED_IO +# define USE_UNLOCKED_IO 1 +# endif + +# if USE_UNLOCKED_IO + +/* These are wrappers for functions/macros from the GNU C library, and + from other C libraries supporting POSIX's optional thread-safe functions. + + The standard I/O functions are thread-safe. These *_unlocked ones are + more efficient but not thread-safe. That they're not thread-safe is + fine since all of the applications in this package are single threaded. + + Also, some code that is shared with the GNU C library may invoke + the *_unlocked functions directly. On hosts that lack those + functions, invoke the non-thread-safe versions instead. */ + +# include <stdio.h> + +# if HAVE_DECL_CLEARERR_UNLOCKED +# undef clearerr +# define clearerr(x) clearerr_unlocked (x) +# else +# define clearerr_unlocked(x) clearerr (x) +# endif +# if HAVE_DECL_FEOF_UNLOCKED +# undef feof +# define feof(x) feof_unlocked (x) +# else +# define feof_unlocked(x) feof (x) +# endif +# if HAVE_DECL_FERROR_UNLOCKED +# undef ferror +# define ferror(x) ferror_unlocked (x) +# else +# define ferror_unlocked(x) ferror (x) +# endif +# if HAVE_DECL_FFLUSH_UNLOCKED +# undef fflush +# define fflush(x) fflush_unlocked (x) +# else +# define fflush_unlocked(x) fflush (x) +# endif +# if HAVE_DECL_FGETS_UNLOCKED +# undef fgets +# define fgets(x,y,z) fgets_unlocked (x,y,z) +# else +# define fgets_unlocked(x,y,z) fgets (x,y,z) +# endif +# if HAVE_DECL_FPUTC_UNLOCKED +# undef fputc +# define fputc(x,y) fputc_unlocked (x,y) +# else +# define fputc_unlocked(x,y) fputc (x,y) +# endif +# if HAVE_DECL_FPUTS_UNLOCKED +# undef fputs +# define fputs(x,y) fputs_unlocked (x,y) +# else +# define fputs_unlocked(x,y) fputs (x,y) +# endif +# if HAVE_DECL_FREAD_UNLOCKED +# undef fread +# define fread(w,x,y,z) fread_unlocked (w,x,y,z) +# else +# define fread_unlocked(w,x,y,z) fread (w,x,y,z) +# endif +# if HAVE_DECL_FWRITE_UNLOCKED +# undef fwrite +# define fwrite(w,x,y,z) fwrite_unlocked (w,x,y,z) +# else +# define fwrite_unlocked(w,x,y,z) fwrite (w,x,y,z) +# endif +# if HAVE_DECL_GETC_UNLOCKED +# undef getc +# define getc(x) getc_unlocked (x) +# else +# define getc_unlocked(x) getc (x) +# endif +# if HAVE_DECL_GETCHAR_UNLOCKED +# undef getchar +# define getchar() getchar_unlocked () +# else +# define getchar_unlocked() getchar () +# endif +# if HAVE_DECL_PUTC_UNLOCKED +# undef putc +# define putc(x,y) putc_unlocked (x,y) +# else +# define putc_unlocked(x,y) putc (x,y) +# endif +# if HAVE_DECL_PUTCHAR_UNLOCKED +# undef putchar +# define putchar(x) putchar_unlocked (x) +# else +# define putchar_unlocked(x) putchar (x) +# endif + +# undef flockfile +# define flockfile(x) ((void) 0) + +# undef ftrylockfile +# define ftrylockfile(x) 0 + +# undef funlockfile +# define funlockfile(x) ((void) 0) + +# endif /* USE_UNLOCKED_IO */ +#endif /* UNLOCKED_IO_H */ |