]> Pileus Git - ~andy/fetchmail/blobdiff - xmalloc.c
Complete Dominik's name.
[~andy/fetchmail] / xmalloc.c
index ffae9dd9725eab74fd412a5c07cf7b1343f90b00..c2ca4a66e932a32d99716d851914b13ca05da6f0 100644 (file)
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -1,46 +1,20 @@
-/* Copyright 1993-95 by Carl Harris, Jr.
- * All rights reserved
+/*
+ * xmalloc.c -- allocate space or die 
  *
- * Distribute freely, except: don't remove my name from the source or
- * documentation (don't take credit for my work), mark your changes (don't
- * get me blamed for your possible bugs), don't alter or remove this
- * notice.  May be sold if buildable source is provided to buyer.  No
- * warrantee of any kind, express or implied, is included with this
- * software; use at your own risk, responsibility for damages (if any) to
- * anyone resulting from the use of this software rests entirely with the
- * user.
- *
- * Send bug reports, bug fixes, enhancements, requests, flames, etc., and
- * I'll try to keep a version up to date.  I can be reached as follows:
- * Carl Harris <ceharris@mal.com>
+ * Copyright 1998 by Eric S. Raymond.
+ * For license terms, see the file COPYING in this directory.
  */
 
-/***********************************************************************
-  module:       xmalloc.c
-  project:      popclient
-  programmer:   Carl Harris, ceharris@mal.com
-  description:  malloc wrapper.
-
-  $Log: xmalloc.c,v $
-  Revision 1.1  1996/06/28 14:50:30  esr
-  Initial revision
-
-  Revision 1.1  1995/08/09 01:33:08  ceharris
-  Version 3.0 beta 2 release.
-  Added
-  -    .poprc functionality
-  -    GNU long options
-  -    multiple servers on the command line.
-  Fixed
-  -    Passwords showing up in ps output.
-
- ***********************************************************************/
-
-
-#include <config.h>
-#include <stdio.h>
+#include "config.h"
 #include <sys/types.h>
-#include "popclient.h"
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#if defined(STDC_HEADERS)
+#include  <stdlib.h>
+#endif
+#include "fetchmail.h"
+#include "i18n.h"
 
 #if defined(HAVE_VOIDPOINTER)
 #define XMALLOCTYPE void
 #endif
 
 XMALLOCTYPE *
-xmalloc (n)
-size_t n;
+xmalloc (size_t n)
 {
-  XMALLOCTYPE *p;
-
-  p = (XMALLOCTYPE *) malloc(n);
-  if (p == (XMALLOCTYPE *) 0) {
-    fputs("malloc failed\n",stderr);
-    exit(PS_UNDEFINED);
-  }
-  return(p);
+    XMALLOCTYPE *p;
+
+    p = (XMALLOCTYPE *) malloc(n);
+    if (p == (XMALLOCTYPE *) 0)
+    {
+       report(stderr, GT_("malloc failed\n"));
+       abort();
+    }
+    return(p);
 }
+
+XMALLOCTYPE *
+xrealloc (XMALLOCTYPE *p, size_t n)
+{
+    if (p == 0)
+       return xmalloc (n);
+    p = (XMALLOCTYPE *) realloc(p, n);
+    if (p == (XMALLOCTYPE *) 0)
+    {
+       report(stderr, GT_("realloc failed\n"));
+       abort();
+    }
+    return p;
+}
+
+char *xstrdup(const char *s)
+{
+    char *p;
+    p = (char *) xmalloc(strlen(s)+1);
+    strcpy(p,s);
+    return p;
+}
+
+#if !defined(HAVE_STRDUP)
+char *strdup(const char *s)
+{
+    char *p;
+    p = (char *) malloc(strlen(s)+1);
+    if (p)
+           strcpy(p,s);
+    return p;
+}
+#endif /* !HAVE_STRDUP */
+
+char *xstrndup(const char *s, size_t len)
+{
+    char *p;
+    size_t l = strlen(s);
+
+    if (len < l) l = len;
+    p = (char *)xmalloc(l + 1);
+    memcpy(p, s, l);
+    p[l] = '\0';
+    return p;
+}
+
+/* xmalloc.c ends here */