* complete copyright information.
*/
-#include <h/nmh.h>
+#include <h/mh.h>
#include <h/utils.h>
#include <stdlib.h>
+/*
+ * Safely call malloc
+ */
void *
mh_xmalloc(size_t size)
{
return memory;
}
+
+/*
+ * Safely call realloc
+ */
+void *
+mh_xrealloc(void *ptr, size_t size)
+{
+ void *memory;
+
+ if (size == 0)
+ adios(NULL, "Tried to realloc 0bytes");
+
+ memory = realloc(ptr, size);
+ if (!memory)
+ adios(NULL, "Realloc failed");
+
+ return memory;
+}
+
+/*
+ * Return the present working directory, if the current directory does not
+ * exist, or is too long, make / the pwd.
+ */
+char *
+pwd(void)
+{
+ register char *cp;
+ static char curwd[PATH_MAX];
+
+ if (!getcwd (curwd, PATH_MAX)) {
+ admonish (NULL, "unable to determine working directory");
+ if (!mypath || !*mypath
+ || (strcpy (curwd, mypath), chdir (curwd)) == -1) {
+ strcpy (curwd, "/");
+ chdir (curwd);
+ }
+ return curwd;
+ }
+
+ if ((cp = curwd + strlen (curwd) - 1) > curwd && *cp == '/')
+ *cp = '\0';
+
+ return curwd;
+}