Le samedi 26 avril 2008 à 02:31 +0200, Bruno Haible a écrit :
> Yoann Vandoorselaere wrote:
> > I guess mkdir could use the original malloc implementation, returning an
> > error on allocation failure. Or is that a problem?
>
> Sounds ok to me: There is no reason why a system call replacement like mkdir()
> should not report its allocation failures through -1/ENOMEM. Care to provide
> a patch that is acceptable to Jim?
Attached. Is the license change ok thought?
--
Yoann Vandoorselaere <[EMAIL PROTECTED]>
diff --git a/lib/basename.c b/lib/basename.c
index 426ed40..cf625d8 100644
--- a/lib/basename.c
+++ b/lib/basename.c
@@ -19,10 +19,7 @@
#include <config.h>
#include "dirname.h"
-
#include <string.h>
-#include "xalloc.h"
-#include "xstrndup.h"
/* Return the address of the last file name component of NAME. If
NAME has no relative file name components because it is a file
@@ -79,7 +76,7 @@ base_name (char const *name)
/* If there is no last component, then name is a file system root or the
empty string. */
if (! *base)
- return xstrndup (name, base_len (name));
+ return strndup (name, base_len (name));
/* Collapse a sequence of trailing slashes into one. */
length = base_len (base);
@@ -91,7 +88,10 @@ base_name (char const *name)
with pure POSIX semantics, this is not an issue. */
if (FILE_SYSTEM_PREFIX_LEN (base))
{
- char *p = xmalloc (length + 3);
+ char *p = malloc (length + 3);
+ if (p == NULL)
+ return NULL;
+
p[0] = '.';
p[1] = '/';
memcpy (p + 2, base, length);
@@ -100,7 +100,7 @@ base_name (char const *name)
}
/* Finally, copy the basename. */
- return xstrndup (base, length);
+ return strndup (base, length);
}
/* Return the length of the basename NAME. Typically NAME is the
diff --git a/lib/dirname.c b/lib/dirname.c
index c27e5b5..f6b8c0c 100644
--- a/lib/dirname.c
+++ b/lib/dirname.c
@@ -21,7 +21,6 @@
#include "dirname.h"
#include <string.h>
-#include "xalloc.h"
/* Return the length of the prefix of FILE that will be used by
dir_name. If FILE is in the working directory, this returns zero
@@ -75,7 +74,10 @@ dir_name (char const *file)
|| (FILE_SYSTEM_DRIVE_PREFIX_CAN_BE_RELATIVE
&& length == FILE_SYSTEM_PREFIX_LEN (file)
&& file[2] != '\0' && ! ISSLASH (file[2])));
- char *dir = xmalloc (length + append_dot + 1);
+ char *dir = malloc (length + append_dot + 1);
+ if (dir == NULL)
+ return NULL;
+
memcpy (dir, file, length);
if (append_dot)
dir[length++] = '.';
diff --git a/lib/mkdir.c b/lib/mkdir.c
index 8073dc8..cc9cea0 100644
--- a/lib/mkdir.c
+++ b/lib/mkdir.c
@@ -29,7 +29,6 @@
#include <string.h>
#include "dirname.h"
-#include "xalloc.h"
/* Disable the definition of mkdir to rpl_mkdir (from the <sys/stat.h>
substitute) in this file. Otherwise, we'd get an endless recursion. */
@@ -53,7 +52,12 @@ rpl_mkdir (char const *dir, mode_t mode)
if (len && dir[len - 1] == '/')
{
- tmp_dir = xstrdup (dir);
+ tmp_dir = strdup (dir);
+ if (tmp_dir == NULL)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
strip_trailing_slashes (tmp_dir);
}
else
diff --git a/modules/dirname b/modules/dirname
index 7c405c2..5a8ca2d 100644
--- a/modules/dirname
+++ b/modules/dirname
@@ -12,8 +12,7 @@ m4/dos.m4
Depends-on:
double-slash-root
stdbool
-xalloc
-xstrndup
+strndup
configure.ac:
gl_DIRNAME
diff --git a/modules/mkdir b/modules/mkdir
index ed4ee10..532e2d1 100644
--- a/modules/mkdir
+++ b/modules/mkdir
@@ -7,7 +7,7 @@ m4/mkdir-slash.m4
Depends-on:
sys_stat
-xalloc
+strdup
dirname
configure.ac: