]>
diplodocus.org Git - nmh/blob - sbr/utils.c
2120b84541cb77ee7d3933c00e07f6823ec90d5d
3 * utils.c -- various utility routines
7 * This code is Copyright (c) 2006, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
20 mh_xmalloc(size_t size
)
25 adios(NULL
, "Tried to malloc 0 bytes");
27 memory
= malloc(size
);
29 adios(NULL
, "Malloc failed");
38 mh_xrealloc(void *ptr
, size_t size
)
43 adios(NULL
, "Tried to realloc 0bytes");
45 memory
= realloc(ptr
, size
);
47 adios(NULL
, "Realloc failed");
53 * Return the present working directory, if the current directory does not
54 * exist, or is too long, make / the pwd.
60 static char curwd
[PATH_MAX
];
62 if (!getcwd (curwd
, PATH_MAX
)) {
63 admonish (NULL
, "unable to determine working directory");
64 if (!mypath
|| !*mypath
65 || (strcpy (curwd
, mypath
), chdir (curwd
)) == -1) {
72 if ((cp
= curwd
+ strlen (curwd
) - 1) > curwd
&& *cp
== '/')