]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/file/file.c: File_UnlinkIfExists()
authorJohn Wolfe <jwolfe@vmware.com>
Mon, 5 Apr 2021 16:01:42 +0000 (09:01 -0700)
committerJohn Wolfe <jwolfe@vmware.com>
Mon, 5 Apr 2021 16:01:42 +0000 (09:01 -0700)
Revised File_UnlinkIfExists() to return 0 for success and an errno for
failure.  Previously, a failure was indicated by a -1 and the caller had
to retrieve the errno.

open-vm-tools/lib/file/file.c
open-vm-tools/lib/file/fileIO.c

index 90677e833ba92774737b4f3b604911f6339e161c..a2924a50aab4ee8e6f2253cb020a4392ce0b3717 100644 (file)
@@ -115,8 +115,8 @@ File_Exists(const char *pathName)  // IN: May be NULL.
  *      Errno/GetLastError is available upon failure.
  *
  * Results:
- *      Return 0 if the unlink is successful or if the file did not exist.
- *      Otherwise return -1.
+ *        0  success
+ *      > 0  failure (errno)
  *
  * Side effects:
  *      May unlink the file.
@@ -127,13 +127,13 @@ File_Exists(const char *pathName)  // IN: May be NULL.
 int
 File_UnlinkIfExists(const char *pathName)  // IN:
 {
-   int ret = FileDeletion(pathName, TRUE);
+   errno = FileDeletion(pathName, TRUE);
 
-   if (ret != 0) {
-      ret = (ret == ENOENT) ? 0 : -1;
+   if (errno == ENOENT) {
+      errno = 0;
    }
 
-   return ret;
+   return errno;
 }
 
 
index 677e7944b4843b5b033e318111a702d50e224770..4d79175717476caaa5d6fa0fbd595424ce669a58 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************
- * Copyright (C) 1998-2019 VMware, Inc. All rights reserved.
+ * Copyright (C) 1998-2021 VMware, Inc. All rights reserved.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as published
@@ -524,7 +524,7 @@ FileIO_CloseAndUnlink(FileIODescriptor *fd)  // IN:
    path = Unicode_Duplicate(fd->fileName);
 
    ret = FileIO_Close(fd);
-   if ((File_UnlinkIfExists(path) == -1) && FileIO_IsSuccess(ret)) {
+   if ((File_UnlinkIfExists(path) != 0) && FileIO_IsSuccess(ret)) {
       ret = FILEIO_ERROR;
    }