]> git.decadent.org.uk Git - nfs-utils.git/blob - utils/statd/misc.c
44af30eea07ef8ccf7d4f9990c5ed18540c66041
[nfs-utils.git] / utils / statd / misc.c
1 /* 
2  * Copyright (C) 1995-1999 Jeffrey A. Uphoff
3  * Modified by Olaf Kirch, 1996.
4  * Modified by H.J. Lu, 1998.
5  *
6  * NSM for Linux.
7  */
8
9 #ifdef HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12
13 #include <errno.h>
14 #include <limits.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include "statd.h"
18 #include "notlist.h"
19
20 /*
21  * Error-checking malloc() wrapper.
22  */
23 void *
24 xmalloc (size_t size)
25 {
26   void *ptr;
27
28   if (size == 0)
29     return ((void *)NULL);
30
31   if (!(ptr = malloc (size)))
32     xlog_err ("malloc failed");
33
34   return (ptr);
35 }
36
37
38 /* 
39  * Error-checking strdup() wrapper.
40  */
41 char *
42 xstrdup (const char *string)
43 {
44   char *result;
45
46   /* Will only fail if underlying malloc() fails (ENOMEM). */
47   if (!(result = strdup (string)))
48     xlog_err ("strdup failed");
49
50   return (result);
51 }
52
53
54 /*
55  * Unlinking a file.
56  */
57 void
58 xunlink (char *path, char *host)
59 {
60         char *tozap;
61
62         tozap = malloc(strlen(path)+strlen(host)+2);
63         if (tozap == NULL) {
64                 xlog(L_ERROR, "xunlink: malloc failed: errno %d (%m)", errno);
65                 return;
66         }
67         sprintf (tozap, "%s/%s", path, host);
68
69         if (unlink (tozap) == -1)
70                 xlog(L_ERROR, "unlink (%s): %m", tozap);
71         else
72                 xlog(D_GENERAL, "Unlinked %s", tozap);
73
74         free(tozap);
75 }