From: John Wolfe Date: Mon, 5 Apr 2021 16:01:42 +0000 (-0700) Subject: lib/file/file.c: File_UnlinkIfExists() X-Git-Tag: stable-11.3.0~84 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47df40cccede41beffa9658889b51ce1738c61bd;p=thirdparty%2Fopen-vm-tools.git lib/file/file.c: File_UnlinkIfExists() 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. --- diff --git a/open-vm-tools/lib/file/file.c b/open-vm-tools/lib/file/file.c index 90677e833..a2924a50a 100644 --- a/open-vm-tools/lib/file/file.c +++ b/open-vm-tools/lib/file/file.c @@ -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; } diff --git a/open-vm-tools/lib/file/fileIO.c b/open-vm-tools/lib/file/fileIO.c index 677e7944b..4d7917571 100644 --- a/open-vm-tools/lib/file/fileIO.c +++ b/open-vm-tools/lib/file/fileIO.c @@ -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; }