From: Simon Josefsson Date: Mon, 12 Jun 2006 15:39:09 +0000 (+0000) Subject: Update. X-Git-Tag: gnutls_1_4_1~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ce5db705284392d3236ddbd3a0875a2ae637d0e6;p=thirdparty%2Fgnutls.git Update. --- diff --git a/gl/Makefile.am b/gl/Makefile.am index bc49798890..f37e27fa90 100644 --- a/gl/Makefile.am +++ b/gl/Makefile.am @@ -8,7 +8,7 @@ # the same distribution terms as the rest of that program. # # Generated by gnulib-tool. -# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=. --lgpl --libtool --macro-prefix=gl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 getaddrinfo getline getpass gettext inet_ntop maintainer-makefile memmem memmove minmax readline snprintf socklen stdint +# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=. --lgpl --libtool --macro-prefix=gl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 getaddrinfo getline getpass gettext inet_ntop maintainer-makefile memmem memmove minmax read-file readline snprintf socklen stdint AUTOMAKE_OPTIONS = 1.5 gnits no-dependencies diff --git a/gl/gc-gnulib.c b/gl/gc-gnulib.c index ca0ee95299..4829730d45 100644 --- a/gl/gc-gnulib.c +++ b/gl/gc-gnulib.c @@ -858,9 +858,3 @@ gc_hmac_sha1 (const void *key, size_t keylen, return GC_OK; } #endif - -void -gc_hash_hmac_setkey (gc_hash_handle handle, size_t len, const char *key) -{ - return; -} diff --git a/gl/m4/gnulib-cache.m4 b/gl/m4/gnulib-cache.m4 index 9f1876452c..de62ba2b3a 100644 --- a/gl/m4/gnulib-cache.m4 +++ b/gl/m4/gnulib-cache.m4 @@ -15,10 +15,10 @@ # Specification in the form of a command-line invocation: -# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=. --lgpl --libtool --macro-prefix=gl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 getaddrinfo getline getpass gettext inet_ntop maintainer-makefile memmem memmove minmax readline snprintf socklen stdint +# gnulib-tool --import --dir=. --lib=libgnu --source-base=gl --m4-base=gl/m4 --aux-dir=. --lgpl --libtool --macro-prefix=gl gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 getaddrinfo getline getpass gettext inet_ntop maintainer-makefile memmem memmove minmax read-file readline snprintf socklen stdint # Specification in the form of a few gnulib-tool.m4 macro invocations: -gl_MODULES([gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 getaddrinfo getline getpass gettext inet_ntop maintainer-makefile memmem memmove minmax readline snprintf socklen stdint]) +gl_MODULES([gc gc-arcfour gc-arctwo gc-des gc-hmac-md5 gc-md2 gc-md4 gc-md5 gc-pbkdf2-sha1 gc-random gc-rijndael gc-sha1 getaddrinfo getline getpass gettext inet_ntop maintainer-makefile memmem memmove minmax read-file readline snprintf socklen stdint]) gl_AVOID([]) gl_SOURCE_BASE([gl]) gl_M4_BASE([gl/m4]) diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4 index f39eb2c1f7..062e59426c 100644 --- a/gl/m4/gnulib-comp.m4 +++ b/gl/m4/gnulib-comp.m4 @@ -53,6 +53,7 @@ AC_DEFUN([gl_INIT], gl_FUNC_MEMMEM gl_FUNC_MEMMOVE gl_MINMAX + gl_FUNC_READ_FILE gl_FUNC_READLINE gl_C_RESTRICT gl_SIZE_MAX @@ -116,6 +117,8 @@ AC_DEFUN([gl_FILE_LIST], [ lib/printf-args.h lib/printf-parse.c lib/printf-parse.h + lib/read-file.c + lib/read-file.h lib/readline.c lib/readline.h lib/rijndael-alg-fst.c @@ -190,6 +193,7 @@ AC_DEFUN([gl_FILE_LIST], [ m4/po.m4 m4/printf-posix.m4 m4/progtest.m4 + m4/read-file.m4 m4/readline.m4 m4/restrict.m4 m4/rijndael.m4 diff --git a/gl/m4/read-file.m4 b/gl/m4/read-file.m4 new file mode 100644 index 0000000000..15bcad98b4 --- /dev/null +++ b/gl/m4/read-file.m4 @@ -0,0 +1,15 @@ +# read-file.m4 serial 1 +dnl Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_READ_FILE], +[ + AC_LIBSOURCES([read-file.c, read-file.h]) + AC_LIBOBJ([read-file]) + gl_PREREQ_READ_FILE +]) + +# Prerequisites of lib/read-file.c. +AC_DEFUN([gl_PREREQ_READ_FILE], [:]) diff --git a/gl/read-file.c b/gl/read-file.c new file mode 100644 index 0000000000..12b2f17f4b --- /dev/null +++ b/gl/read-file.c @@ -0,0 +1,143 @@ +/* read-file.c -- read file contents into a string + Copyright (C) 2006 Free Software Foundation, Inc. + Written by Simon Josefsson and Bruno Haible. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser 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. */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include "read-file.h" + +/* Get realloc, free. */ +#include + +/* Get errno. */ +#include + +/* Read a STREAM and return a newly allocated string with the content, + and set *LENGTH to the length of the string. The string is + zero-terminated, but the terminating zero byte is not counted in + *LENGTH. On errors, *LENGTH is undefined, errno preserves the + values set by system functions (if any), and NULL is returned. */ +char * +fread_file (FILE * stream, size_t * length) +{ + char *buf = NULL; + size_t alloc = 0; + size_t size = 0; + + while (!feof (stream)) + { + size_t count; + + if (size + BUFSIZ + 1 > alloc) + { + char *new_buf; + + alloc += alloc / 2; + if (alloc < size + BUFSIZ + 1) + alloc = size + BUFSIZ + 1; + + new_buf = realloc (buf, alloc); + if (!new_buf) + { + int save_errno = errno; + free (buf); + errno = save_errno; + return NULL; + } + + buf = new_buf; + } + + count = fread (buf + size, 1, alloc - size - 1, stream); + size += count; + + if (ferror (stream)) + { + int save_errno = errno; + free (buf); + errno = save_errno; + return NULL; + } + } + + if (buf) + buf[size] = '\0'; + + *length = size; + + return buf; +} + +static char * +internal_read_file (const char *filename, size_t * length, const char *mode) +{ + FILE *stream = fopen (filename, mode); + char *out; + int rc; + + if (!stream) + return NULL; + + out = fread_file (stream, length); + + if (out) + rc = fclose (stream); + else + { + /* On failure, preserve the original errno value. */ + int save_errno = errno; + rc = fclose (stream); + errno = save_errno; + } + + if (rc != 0) + { + int save_errno = errno; + free (out); + errno = save_errno; + return NULL; + } + + return out; +} + +/* Open and read the contents of FILENAME, and return a newly + allocated string with the content, and set *LENGTH to the length of + the string. The string is zero-terminated, but the terminating + zero byte is not counted in *LENGTH. On errors, *LENGTH is + undefined, errno preserves the values set by system functions (if + any), and NULL is returned. */ +char * +read_file (const char *filename, size_t * length) +{ + return internal_read_file (filename, length, "r"); +} + +/* Open (on non-POSIX systems, in binary mode) and read the contents + of FILENAME, and return a newly allocated string with the content, + and set LENGTH to the length of the string. The string is + zero-terminated, but the terminating zero byte is not counted in + the LENGTH variable. On errors, *LENGTH is undefined, errno + preserves the values set by system functions (if any), and NULL is + returned. */ +char * +read_binary_file (const char *filename, size_t * length) +{ + return internal_read_file (filename, length, "rb"); +} diff --git a/gl/read-file.h b/gl/read-file.h new file mode 100644 index 0000000000..798d841fc3 --- /dev/null +++ b/gl/read-file.h @@ -0,0 +1,34 @@ +/* read-file.h -- read file contents into a string + Copyright (C) 2006 Free Software Foundation, Inc. + Written by Simon Josefsson. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as published by + the Free Software Foundation; either version 2.1, 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 Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser 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 READ_FILE_H +#define READ_FILE_H + +/* Get size_t. */ +#include + +/* Get FILE. */ +#include + +extern char *fread_file (FILE * stream, size_t * length); + +extern char *read_file (const char *filename, size_t * length); + +extern char *read_binary_file (const char *filename, size_t * length); + +#endif /* READ_FILE_H */