Skip to content

Commit

Permalink
Merge pull request #10309 from dra27/win32unix-errno
Browse files Browse the repository at this point in the history
Fix a few more errno errors in win32unix
  • Loading branch information
nojb committed Apr 18, 2021
2 parents c0c241e + 23660a5 commit 72f76f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
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

0 comments on commit 72f76f4

Please sign in to comment.