about summary refs log tree commit diff
path: root/sysdeps/posix/remove.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/posix/remove.c')
-rw-r--r--sysdeps/posix/remove.c22
1 files changed, 10 insertions, 12 deletions
diff --git a/sysdeps/posix/remove.c b/sysdeps/posix/remove.c
index 7473ee14f4..c44af92d74 100644
--- a/sysdeps/posix/remove.c
+++ b/sysdeps/posix/remove.c
@@ -1,5 +1,5 @@
 /* ANSI C `remove' function to delete a file or directory.  POSIX.1 version.
-   Copyright (C) 1995,96,97,2002 Free Software Foundation, Inc.
+   Copyright (C) 1995,96,97,2002,2003 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -25,17 +25,15 @@ int
 remove (file)
      const char *file;
 {
-  int save;
+  /* First try to unlink since this is more frequently the necessary action. */
+  if (__unlink (file) != 0
+      /* If it is indeed a directory...  */
+      && (errno != EISDIR
+	  /* ...try to remove it.  */
+	  || __rmdir (file) != 0))
+    /* Cannot remove the object for whatever reason.  */
+    return -1;
 
-  save = errno;
-  if (__rmdir (file) == 0)
-    return 0;
-  else if (errno == ENOTDIR && __unlink (file) == 0)
-    {
-      __set_errno (save);
-      return 0;
-    }
-
-  return -1;
+  return 0;
 }
 libc_hidden_def (remove)