Skip to content

Wrong Error Specified in unlink/remove#722

Merged
colin-home merged 1 commit intoMicrosoftDocs:masterfrom
gmittert:baderror
Jan 18, 2019
Merged

Wrong Error Specified in unlink/remove#722
colin-home merged 1 commit intoMicrosoftDocs:masterfrom
gmittert:baderror

Conversation

@gmittert
Copy link
Copy Markdown

@gmittert gmittert commented Jan 18, 2019

_unlink, _wulink, _remove, and _wremove in the docs all specify that if used on a directory, they set errno "to ENOENT, which means the file or path is not found or the path specified a directory."

However, actually using them on a directory gives EACCES, which makes sense given that they all seem to call through to DeleteFileW which gives ERROR_ACCESS_DENIED when used on a directory.

This can be reproduced using something like

#include <stdio.h>
#include <windows.h>

int main() {
  if (!DeleteFileA("testDir")) {
    printf("GetLastError %d\n", GetLastError());
  }

  if (_unlink("testDir") != 0) {
    printf(_strerror(NULL));
    printf("Errno: %d\n", errno);
  }
}
C:\Users\jmittertreiner\tmp\testRm> mkdir testDir
C:\Users\jmittertreiner\tmp\testRm>cl .\testrm.cpp  && .\testrm.exe
Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27024.1 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

testrm.cpp
Microsoft (R) Incremental Linker Version 14.16.27024.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:testrm.exe
testrm.obj
GetLastError 5
Permission denied
Errno: 13

_unlink, _wulink, _remove, and _wremove actually give EACCES if used on
a directory, no ENOENT.
@msftclas
Copy link
Copy Markdown

msftclas commented Jan 18, 2019

CLA assistant check
All CLA requirements met.

@PRMerger17
Copy link
Copy Markdown
Contributor

@jmittert : Thanks for your contribution! The author, @, has been notified to review your proposed change.

Copy link
Copy Markdown
Contributor

@colin-home colin-home left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jmittert I love PRs with supporting evidence attached. Thanks for the update!

@colin-home colin-home merged commit 1ea5b1b into MicrosoftDocs:master Jan 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants