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.
* 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.
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;
}
/*********************************************************
- * 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
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;
}