{"thread":{"id":"18340","subject":"[PATCH 1/2] MinGW: a helper function that translates Win32 API error codes","startedAt":"2009-03-17T07:39:46Z","lastAt":"2009-03-17T10:12:37Z","messageCount":4,"participants":["Johannes Sixt","Johannes Schindelin"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"108186","messageId":"49BF53C2.6020707@kdbg.org","threadId":"18340","inReplyTo":null,"subject":"[PATCH 1/2] MinGW: a helper function that translates Win32 API error codes","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-03-17T07:39:46Z","receivedAt":"2009-03-17T07:39:46Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Petr Kodl <petrkodl@gmail.com>\nDate: Sat, 24 Jan 2009 15:04:39 +0100\n\nThis function translates many possible Win32 error codes to suitable\nerrno numbers.  We will use it in our wrapper functions that need to call\ninto Win32.\n\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\n---\n  Dscho,\n\n  I've split this off from the Petr's hard-link patch and moved the function\n  to the top or mingw.c because we should reuse it in our other wrappers\n  to convert error codes.\n\n  -- Hannes\n\n  compat/mingw.c |  113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n  1 files changed, 113 insertions(+), 0 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex 27bcf3f..f66ad56 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -4,6 +4,119 @@\n\n  unsigned int _CRT_fmode = _O_BINARY;\n\n+static int err_win_to_posix(DWORD winerr)\n+{\n+\tint error = ENOSYS;\n+\tswitch(winerr) {\n+\tcase ERROR_ACCESS_DENIED: error = EACCES; break;\n+\tcase ERROR_ACCOUNT_DISABLED: error = EACCES; break;\n+\tcase ERROR_ACCOUNT_RESTRICTION: error = EACCES; break;\n+\tcase ERROR_ALREADY_ASSIGNED: error = EBUSY; break;\n+\tcase ERROR_ALREADY_EXISTS: error = EEXIST; break;\n+\tcase ERROR_ARITHMETIC_OVERFLOW: error = ERANGE; break;\n+\tcase ERROR_BAD_COMMAND: error = EIO; break;\n+\tcase ERROR_BAD_DEVICE: error = ENODEV; break;\n+\tcase ERROR_BAD_DRIVER_LEVEL: error = ENXIO; break;\n+\tcase ERROR_BAD_EXE_FORMAT: error = ENOEXEC; break;\n+\tcase ERROR_BAD_FORMAT: error = ENOEXEC; break;\n+\tcase ERROR_BAD_LENGTH: error = EINVAL; break;\n+\tcase ERROR_BAD_PATHNAME: error = ENOENT; break;\n+\tcase ERROR_BAD_PIPE: error = EPIPE; break;\n+\tcase ERROR_BAD_UNIT: error = ENODEV; break;\n+\tcase ERROR_BAD_USERNAME: error = EINVAL; break;\n+\tcase ERROR_BROKEN_PIPE: error = EPIPE; break;\n+\tcase ERROR_BUFFER_OVERFLOW: error = ENAMETOOLONG; break;\n+\tcase ERROR_BUSY: error = EBUSY; break;\n+\tcase ERROR_BUSY_DRIVE: error = EBUSY; break;\n+\tcase ERROR_CALL_NOT_IMPLEMENTED: error = ENOSYS; break;\n+\tcase ERROR_CANNOT_MAKE: error = EACCES; break;\n+\tcase ERROR_CANTOPEN: error = EIO; break;\n+\tcase ERROR_CANTREAD: error = EIO; break;\n+\tcase ERROR_CANTWRITE: error = EIO; break;\n+\tcase ERROR_CRC: error = EIO; break;\n+\tcase ERROR_CURRENT_DIRECTORY: error = EACCES; break;\n+\tcase ERROR_DEVICE_IN_USE: error = EBUSY; break;\n+\tcase ERROR_DEV_NOT_EXIST: error = ENODEV; break;\n+\tcase ERROR_DIRECTORY: error = EINVAL; break;\n+\tcase ERROR_DIR_NOT_EMPTY: error = ENOTEMPTY; break;\n+\tcase ERROR_DISK_CHANGE: error = EIO; break;\n+\tcase ERROR_DISK_FULL: error = ENOSPC; break;\n+\tcase ERROR_DRIVE_LOCKED: error = EBUSY; break;\n+\tcase ERROR_ENVVAR_NOT_FOUND: error = EINVAL; break;\n+\tcase ERROR_EXE_MARKED_INVALID: error = ENOEXEC; break;\n+\tcase ERROR_FILENAME_EXCED_RANGE: error = ENAMETOOLONG; break;\n+\tcase ERROR_FILE_EXISTS: error = EEXIST; break;\n+\tcase ERROR_FILE_INVALID: error = ENODEV; break;\n+\tcase ERROR_FILE_NOT_FOUND: error = ENOENT; break;\n+\tcase ERROR_GEN_FAILURE: error = EIO; break;\n+\tcase ERROR_HANDLE_DISK_FULL: error = ENOSPC; break;\n+\tcase ERROR_INSUFFICIENT_BUFFER: error = ENOMEM; break;\n+\tcase ERROR_INVALID_ACCESS: error = EACCES; break;\n+\tcase ERROR_INVALID_ADDRESS: error = EFAULT; break;\n+\tcase ERROR_INVALID_BLOCK: error = EFAULT; break;\n+\tcase ERROR_INVALID_DATA: error = EINVAL; break;\n+\tcase ERROR_INVALID_DRIVE: error = ENODEV; break;\n+\tcase ERROR_INVALID_EXE_SIGNATURE: error = ENOEXEC; break;\n+\tcase ERROR_INVALID_FLAGS: error = EINVAL; break;\n+\tcase ERROR_INVALID_FUNCTION: error = ENOSYS; break;\n+\tcase ERROR_INVALID_HANDLE: error = EBADF; break;\n+\tcase ERROR_INVALID_LOGON_HOURS: error = EACCES; break;\n+\tcase ERROR_INVALID_NAME: error = EINVAL; break;\n+\tcase ERROR_INVALID_OWNER: error = EINVAL; break;\n+\tcase ERROR_INVALID_PARAMETER: error = EINVAL; break;\n+\tcase ERROR_INVALID_PASSWORD: error = EPERM; break;\n+\tcase ERROR_INVALID_PRIMARY_GROUP: error = EINVAL; break;\n+\tcase ERROR_INVALID_SIGNAL_NUMBER: error = EINVAL; break;\n+\tcase ERROR_INVALID_TARGET_HANDLE: error = EIO; break;\n+\tcase ERROR_INVALID_WORKSTATION: error = EACCES; break;\n+\tcase ERROR_IO_DEVICE: error = EIO; break;\n+\tcase ERROR_IO_INCOMPLETE: error = EINTR; break;\n+\tcase ERROR_LOCKED: error = EBUSY; break;\n+\tcase ERROR_LOCK_VIOLATION: error = EACCES; break;\n+\tcase ERROR_LOGON_FAILURE: error = EACCES; break;\n+\tcase ERROR_MAPPED_ALIGNMENT: error = EINVAL; break;\n+\tcase ERROR_META_EXPANSION_TOO_LONG: error = E2BIG; break;\n+\tcase ERROR_MORE_DATA: error = EPIPE; break;\n+\tcase ERROR_NEGATIVE_SEEK: error = ESPIPE; break;\n+\tcase ERROR_NOACCESS: error = EFAULT; break;\n+\tcase ERROR_NONE_MAPPED: error = EINVAL; break;\n+\tcase ERROR_NOT_ENOUGH_MEMORY: error = ENOMEM; break;\n+\tcase ERROR_NOT_READY: error = EAGAIN; break;\n+\tcase ERROR_NOT_SAME_DEVICE: error = EXDEV; break;\n+\tcase ERROR_NO_DATA: error = EPIPE; break;\n+\tcase ERROR_NO_MORE_SEARCH_HANDLES: error = EIO; break;\n+\tcase ERROR_NO_PROC_SLOTS: error = EAGAIN; break;\n+\tcase ERROR_NO_SUCH_PRIVILEGE: error = EACCES; break;\n+\tcase ERROR_OPEN_FAILED: error = EIO; break;\n+\tcase ERROR_OPEN_FILES: error = EBUSY; break;\n+\tcase ERROR_OPERATION_ABORTED: error = EINTR; break;\n+\tcase ERROR_OUTOFMEMORY: error = ENOMEM; break;\n+\tcase ERROR_PASSWORD_EXPIRED: error = EACCES; break;\n+\tcase ERROR_PATH_BUSY: error = EBUSY; break;\n+\tcase ERROR_PATH_NOT_FOUND: error = ENOENT; break;\n+\tcase ERROR_PIPE_BUSY: error = EBUSY; break;\n+\tcase ERROR_PIPE_CONNECTED: error = EPIPE; break;\n+\tcase ERROR_PIPE_LISTENING: error = EPIPE; break;\n+\tcase ERROR_PIPE_NOT_CONNECTED: error = EPIPE; break;\n+\tcase ERROR_PRIVILEGE_NOT_HELD: error = EACCES; break;\n+\tcase ERROR_READ_FAULT: error = EIO; break;\n+\tcase ERROR_SEEK: error = EIO; break;\n+\tcase ERROR_SEEK_ON_DEVICE: error = ESPIPE; break;\n+\tcase ERROR_SHARING_BUFFER_EXCEEDED: error = ENFILE; break;\n+\tcase ERROR_SHARING_VIOLATION: error = EACCES; break;\n+\tcase ERROR_STACK_OVERFLOW: error = ENOMEM; break;\n+\tcase ERROR_SWAPERROR: error = ENOENT; break;\n+\tcase ERROR_TOO_MANY_MODULES: error = EMFILE; break;\n+\tcase ERROR_TOO_MANY_OPEN_FILES: error = EMFILE; break;\n+\tcase ERROR_UNRECOGNIZED_MEDIA: error = ENXIO; break;\n+\tcase ERROR_UNRECOGNIZED_VOLUME: error = ENODEV; break;\n+\tcase ERROR_WAIT_NO_CHILDREN: error = ECHILD; break;\n+\tcase ERROR_WRITE_FAULT: error = EIO; break;\n+\tcase ERROR_WRITE_PROTECT: error = EROFS; break;\n+\t}\n+\treturn error;\n+}\n+\n  #undef open\n  int mingw_open (const char *filename, int oflags, ...)\n  {\n-- \n1.6.2.rc2.971.g14d5\n"},{"id":"108189","messageId":"49BF5563.2060500@kdbg.org","threadId":"18340","inReplyTo":"49BF53C2.6020707@kdbg.org","subject":"[PATCH 2/2] MinGW: a hardlink implementation","fromName":"Johannes Sixt","fromEmail":"j6t@kdbg.org","sentAt":"2009-03-17T07:46:43Z","receivedAt":"2009-03-17T07:46:43Z","isPatch":true,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"From: Petr Kodl <petrkodl@gmail.com>\nDate: Sat, 24 Jan 2009 15:04:39 +0100\n\nSigned-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\nSigned-off-by: Johannes Sixt <j6t@kdbg.org>\n---\n  This is the meat of Petr's original patch with the fixup that was\n  discussed in the msysgit mailing list (WINAPI was added in the\n  typedef).\n\n  -- Hannes\n\n  compat/mingw.c |   21 +++++++++++++++++++++\n  compat/mingw.h |    3 +--\n  2 files changed, 22 insertions(+), 2 deletions(-)\n\ndiff --git a/compat/mingw.c b/compat/mingw.c\nindex f66ad56..171fa85 100644\n--- a/compat/mingw.c\n+++ b/compat/mingw.c\n@@ -1118,3 +1118,24 @@ void mingw_open_html(const char *unixpath)\n  \tprintf(\"Launching default browser to display HTML ...\\n\");\n  \tShellExecute(NULL, \"open\", htmlpath, NULL, \"\\\\\", 0);\n  }\n+\n+int link(const char *oldpath, const char *newpath)\n+{\n+\ttypedef BOOL WINAPI (*T)(const char*, const char*, LPSECURITY_ATTRIBUTES);\n+\tstatic T create_hard_link = NULL;\n+\tif (!create_hard_link) {\n+\t\tcreate_hard_link = (T) GetProcAddress(\n+\t\t\tGetModuleHandle(\"kernel32.dll\"), \"CreateHardLinkA\");\n+\t\tif (!create_hard_link)\n+\t\t\tcreate_hard_link = (T)-1;\n+\t}\n+\tif (create_hard_link == (T)-1) {\n+\t\terrno = ENOSYS;\n+\t\treturn -1;\n+\t}\n+\tif (!create_hard_link(newpath, oldpath, NULL)) {\n+\t\terrno = err_win_to_posix(GetLastError());\n+\t\treturn -1;\n+\t}\n+\treturn 0;\n+}\ndiff --git a/compat/mingw.h b/compat/mingw.h\nindex f5da647..762eb14 100644\n--- a/compat/mingw.h\n+++ b/compat/mingw.h\n@@ -67,8 +67,6 @@ static inline int readlink(const char *path, char *buf, size_t bufsiz)\n  { errno = ENOSYS; return -1; }\n  static inline int symlink(const char *oldpath, const char *newpath)\n  { errno = ENOSYS; return -1; }\n-static inline int link(const char *oldpath, const char *newpath)\n-{ errno = ENOSYS; return -1; }\n  static inline int fchmod(int fildes, mode_t mode)\n  { errno = ENOSYS; return -1; }\n  static inline int fork(void)\n@@ -134,6 +132,7 @@ int getpagesize(void);\t/* defined in MinGW's libgcc.a */\n  struct passwd *getpwuid(int uid);\n  int setitimer(int type, struct itimerval *in, struct itimerval *out);\n  int sigaction(int sig, struct sigaction *in, struct sigaction *out);\n+int link(const char *oldpath, const char *newpath);\n\n  /*\n   * replacements of existing functions\n-- \n1.6.2.rc2.971.g14d5\n"},{"id":"108204","messageId":"alpine.DEB.1.00.0903171109510.6393@intel-tinevez-2-302","threadId":"18340","inReplyTo":"49BF53C2.6020707@kdbg.org","subject":"Re: [PATCH 1/2] MinGW: a helper function that translates Win32 API error codes","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-03-17T10:10:23Z","receivedAt":"2009-03-17T10:10:23Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 17 Mar 2009, Johannes Sixt wrote:\n\n> From: Petr Kodl <petrkodl@gmail.com>\n> Date: Sat, 24 Jan 2009 15:04:39 +0100\n> \n> This function translates many possible Win32 error codes to suitable\n> errno numbers.  We will use it in our wrapper functions that need to call\n> into Win32.\n> \n> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n> ---\n>  Dscho,\n> \n>  I've split this [error code translation from Win32 to POSIX] off from \n>  the Petr's hard-link patch and moved the function to the top or mingw.c \n>  because we should reuse it in our other wrappers to convert error \n>  codes.\n\nI fully agree.\n\nCiao,\nDscho\n"},{"id":"108205","messageId":"alpine.DEB.1.00.0903171110420.6393@intel-tinevez-2-302","threadId":"18340","inReplyTo":"49BF5563.2060500@kdbg.org","subject":"Re: [PATCH 2/2] MinGW: a hardlink implementation","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2009-03-17T10:12:37Z","receivedAt":"2009-03-17T10:12:37Z","isPatch":true,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi,\n\nOn Tue, 17 Mar 2009, Johannes Sixt wrote:\n\n> From: Petr Kodl <petrkodl@gmail.com>\n> Date: Sat, 24 Jan 2009 15:04:39 +0100\n> \n> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>\n> Signed-off-by: Johannes Sixt <j6t@kdbg.org>\n> ---\n>  This is the meat of Petr's original patch with the fixup that was \n>  discussed in the msysgit mailing list (WINAPI was added in the \n>  typedef).\n\nTo save everybody searching why WINAPI is needed: in the error case (e.g. \nwhen you try to hard link from a different device), the stack was \ncorrupted, leading to a rather nasty segmentation fault (which has a \ndifferent name on Windows, just as everything else: access violation):\n\n\thttp://code.google.com/p/msysgit/issues/detail?id=204\n\nCiao,\nDscho\n"}]}