From b7120d6a755fe29a9b149e11b7a5b355ea7ccf72 Mon Sep 17 00:00:00 2001 From: Simon Josefsson Date: Thu, 5 Dec 2002 01:11:18 +0000 Subject: [PATCH] An AC_LIBOBJ, from gnulib. --- lib/gethostname.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/memmove.c | 28 ++++++++++++++++++++++++++++ lib/memset.c | 26 ++++++++++++++++++++++++++ lib/strdup.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/strerror.c | 37 +++++++++++++++++++++++++++++++++++++ 5 files changed, 198 insertions(+) create mode 100644 lib/gethostname.c create mode 100644 lib/memmove.c create mode 100644 lib/memset.c create mode 100644 lib/strdup.c create mode 100644 lib/strerror.c diff --git a/lib/gethostname.c b/lib/gethostname.c new file mode 100644 index 0000000..3d66dc9 --- /dev/null +++ b/lib/gethostname.c @@ -0,0 +1,53 @@ +/* gethostname emulation for SysV and POSIX.1. + Copyright (C) 1992 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. */ + +/* David MacKenzie */ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#ifdef HAVE_UNAME +# include +#endif + +/* Put up to LEN chars of the host name into NAME. + Null terminate it if the name is shorter than LEN. + Return 0 if ok, -1 if error. */ + +int +gethostname (name, len) + char *name; + int len; +{ +#ifdef HAVE_UNAME + struct utsname uts; + + if (uname (&uts) == -1) + return -1; + if (len > sizeof (uts.nodename)) + { + /* More space than we need is available. */ + name[sizeof (uts.nodename)] = '\0'; + len = sizeof (uts.nodename); + } + strncpy (name, uts.nodename, len); +#else + strcpy (name, ""); /* Hardcode your system name if you want. */ +#endif + return 0; +} diff --git a/lib/memmove.c b/lib/memmove.c new file mode 100644 index 0000000..ea38e8d --- /dev/null +++ b/lib/memmove.c @@ -0,0 +1,28 @@ +/* memmove.c -- copy memory. + Copy LENGTH bytes from SOURCE to DEST. Does not null-terminate. + In the public domain. + By David MacKenzie . */ + +#if HAVE_CONFIG_H +# include +#endif + +void * +memmove (dest, source, length) + char *dest; + const char *source; + unsigned length; +{ + char *d0 = dest; + if (source < dest) + /* Moving from low mem to hi mem; start at end. */ + for (source += length, dest += length; length; --length) + *--dest = *--source; + else if (source != dest) + { + /* Moving from hi mem to low mem; start at beginning. */ + for (; length; --length) + *dest++ = *source++; + } + return (void *) d0; +} diff --git a/lib/memset.c b/lib/memset.c new file mode 100644 index 0000000..5744bcb --- /dev/null +++ b/lib/memset.c @@ -0,0 +1,26 @@ +/* memset.c -- set an area of memory to a given value + Copyright (C) 1991 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. */ + +char * +memset (char *str, int c, unsigned int len) +{ + register char *st = str; + + while (len-- > 0) + *st++ = c; + return str; +} diff --git a/lib/strdup.c b/lib/strdup.c new file mode 100644 index 0000000..5aa09a6 --- /dev/null +++ b/lib/strdup.c @@ -0,0 +1,54 @@ +/* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + 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. */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if defined _LIBC || defined STDC_HEADERS +# include +# include +#else +char *malloc (); +char *memcpy (); +#endif + +#undef __strdup +#undef strdup + +#ifndef weak_alias +# define __strdup strdup +#endif + +/* Duplicate S, returning an identical malloc'd string. */ +char * +__strdup (const char *s) +{ + size_t len = strlen (s) + 1; + void *new = malloc (len); + + if (new == NULL) + return NULL; + + return (char *) memcpy (new, s, len); +} +#ifdef libc_hidden_def +libc_hidden_def (__strdup) +#endif +#ifdef weak_alias +weak_alias (__strdup, strdup) +#endif diff --git a/lib/strerror.c b/lib/strerror.c new file mode 100644 index 0000000..5dba4d9 --- /dev/null +++ b/lib/strerror.c @@ -0,0 +1,37 @@ +/* strerror.c --- ANSI C compatible system error routine + + Copyright (C) 1986, 1988, 1989, 1991, 2002 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. */ + +#if 0 +# include +#endif + +extern int sys_nerr; +extern char *sys_errlist[]; + +char * +strerror(n) +int n; +{ + static char mesg[30]; + + if (n < 0 || n >= sys_nerr) { + sprintf(mesg, "Unknown error (%d)", n); + return mesg; + } else + return sys_errlist[n]; +} -- 2.11.4.GIT