Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a few more errno errors in win32unix #10309

Merged
merged 4 commits into from
Apr 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,11 @@ Working version
- #10306: Map WSA error code to Unix errno for sockopt and getsockname
functions (Antonin Décimo, review by David Allsopp)

- #10309: Properly return EBADF on error in Unix.descr_of_{in,out}_channel on
Win32 and map Windows error correctly in Unix.truncate and Unix.ftruncate on
Win32.
(David Allsopp, review by Nicolás Ojeda Bär)

### Tools:

- #10139: Remove confusing navigation bar from stdlib documentation.
Expand Down
3 changes: 2 additions & 1 deletion otherlibs/win32unix/channels.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "unixsupport.h"
#include <fcntl.h>
#include <io.h>
#include <errno.h>

/* Check that the given file descriptor has "stream semantics" and
can therefore be used as part of buffered I/O. Things that
Expand Down Expand Up @@ -119,7 +120,7 @@ CAMLprim value win_filedescr_of_channel(value vchan)
HANDLE h;

chan = Channel(vchan);
if (chan->fd == -1) uerror("descr_of_channel", Nothing);
if (chan->fd == -1) unix_error(EBADF, "descr_of_channel", Nothing);
h = (HANDLE) _get_osfhandle(chan->fd);
if (chan->flags & CHANNEL_FLAG_FROM_SOCKET)
fd = win_alloc_socket((SOCKET) h);
Expand Down
5 changes: 4 additions & 1 deletion otherlibs/win32unix/truncate.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static int win_truncate_handle(HANDLE fh, __int64 len)
fp.QuadPart = len;
if (SetFilePointerEx(fh, fp, NULL, FILE_BEGIN) == 0 ||
SetEndOfFile(fh) == 0) {
win32_maperr(GetLastError());
return -1;
}
return 0;
Expand All @@ -45,7 +46,8 @@ static int win_ftruncate(HANDLE fh, __int64 len)
/* Duplicate the handle, so we are free to modify its file position. */
if (DuplicateHandle(currproc, fh, currproc, &dupfh, 0, FALSE,
DUPLICATE_SAME_ACCESS) == 0) {
return -1;
win32_maperr(GetLastError());
return -1;
}
ret = win_truncate_handle(dupfh, len);
CloseHandle(dupfh);
Expand All @@ -59,6 +61,7 @@ static int win_truncate(WCHAR * path, __int64 len)
fh = CreateFile(path, GENERIC_WRITE, 0, NULL,
OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (fh == INVALID_HANDLE_VALUE) {
win32_maperr(GetLastError());
return -1;
}
ret = win_truncate_handle(fh, len);
Expand Down
7 changes: 1 addition & 6 deletions otherlibs/win32unix/unixsupport.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,7 @@ static struct error_entry win_error_table[] = {
{ WSAEINTR, 0, EINTR },
{ WSAEINVAL, 0, EINVAL },
{ WSAEMFILE, 0, EMFILE },
#ifdef WSANAMETOOLONG
{ WSANAMETOOLONG, 0, ENAMETOOLONG },
#endif
#ifdef WSAENFILE
{ WSAENFILE, 0, ENFILE },
#endif
{ WSAENAMETOOLONG, 0, ENAMETOOLONG },
{ WSAENOTEMPTY, 0, ENOTEMPTY },
{ 0, -1, 0 }
};
Expand Down