git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] compat/mingw.c: MSVC build must use ANSI Win32 API's

From
Michael Wookey <michaelwookey@gmail.com>
Date
Sep 22, 2009, 04:10 UTC
Message-ID
<d2e97e800909212110w423e3b2fm85ac6f76439e0591@mail.gmail.com>

MSVC builds define UNICODE which results in the "WIDE" variation of Win32 API's being used.

Explicitly use the ANSI variation of the API's for compatibility with msysgit.

Signed-off-by: Michael Wookey <michaelwookey@gmail.com>
---
 compat/mingw.c |   26 +++++++++++++-------------
 1 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/compat/mingw.c b/compat/mingw.c
index 6b5b5b2..39be42f 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -135,7 +135,7 @@ int mingw_open (const char *filename, int oflags, ...)
 	fd = open(filename, oflags, mode);

 	if (fd < 0 && (oflags & O_CREAT) && errno == EACCES) {
-		DWORD attrs = GetFileAttributes(filename);
+		DWORD attrs = GetFileAttributesA(filename);
 		if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY))
 			errno = EISDIR;
 	}
@@ -607,7 +607,7 @@ static char *lookup_prog(const char *dir, const
char *cmd, int isexe, int exe_on
 		return xstrdup(path);
 	path[strlen(path)-4] = '\0';
 	if ((!exe_only || isexe) && access(path, F_OK) == 0)
-		if (!(GetFileAttributes(path) & FILE_ATTRIBUTE_DIRECTORY))
+		if (!(GetFileAttributesA(path) & FILE_ATTRIBUTE_DIRECTORY))
 			return xstrdup(path);
 	return NULL;
 }
@@ -641,14 +641,14 @@ static int env_compare(const void *a, const void *b)
 static pid_t mingw_spawnve(const char *cmd, const char **argv, char **env,
 			   int prepend_cmd)
 {
-	STARTUPINFO si;
+	STARTUPINFOA si;
 	PROCESS_INFORMATION pi;
 	struct strbuf envblk, args;
 	unsigned flags;
 	BOOL ret;

 	/* Determine whether or not we are associated to a console */
-	HANDLE cons = CreateFile("CONOUT$", GENERIC_WRITE,
+	HANDLE cons = CreateFileA("CONOUT$", GENERIC_WRITE,
 			FILE_SHARE_WRITE, NULL, OPEN_EXISTING,
 			FILE_ATTRIBUTE_NORMAL, NULL);
 	if (cons == INVALID_HANDLE_VALUE) {
@@ -717,7 +717,7 @@ static pid_t mingw_spawnve(const char *cmd, const
char **argv, char **env,
 	}

 	memset(&pi, 0, sizeof(pi));
-	ret = CreateProcess(cmd, args.buf, NULL, NULL, TRUE, flags,
+	ret = CreateProcessA(cmd, args.buf, NULL, NULL, TRUE, flags,
 		env ? envblk.buf : NULL, NULL, &si, &pi);

 	if (env)
@@ -965,23 +965,23 @@ int mingw_rename(const char *pold, const char *pnew)
 	if (errno != EEXIST)
 		return -1;
 repeat:
-	if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
+	if (MoveFileExA(pold, pnew, MOVEFILE_REPLACE_EXISTING))
 		return 0;
 	/* TODO: translate more errors */
 	gle = GetLastError();
 	if (gle == ERROR_ACCESS_DENIED &&
-	    (attrs = GetFileAttributes(pnew)) != INVALID_FILE_ATTRIBUTES) {
+	    (attrs = GetFileAttributesA(pnew)) != INVALID_FILE_ATTRIBUTES) {
 		if (attrs & FILE_ATTRIBUTE_DIRECTORY) {
 			errno = EISDIR;
 			return -1;
 		}
 		if ((attrs & FILE_ATTRIBUTE_READONLY) &&
-		    SetFileAttributes(pnew, attrs & ~FILE_ATTRIBUTE_READONLY)) {
-			if (MoveFileEx(pold, pnew, MOVEFILE_REPLACE_EXISTING))
+		    SetFileAttributesA(pnew, attrs & ~FILE_ATTRIBUTE_READONLY)) {
+			if (MoveFileExA(pold, pnew, MOVEFILE_REPLACE_EXISTING))
 				return 0;
 			gle = GetLastError();
 			/* revert file attributes on failure */
-			SetFileAttributes(pnew, attrs);
+			SetFileAttributesA(pnew, attrs);
 		}
 	}
 	if (tries < ARRAY_SIZE(delay) && gle == ERROR_ACCESS_DENIED) {
@@ -1006,7 +1006,7 @@ struct passwd *getpwuid(int uid)
 	static struct passwd p;

 	DWORD len = sizeof(user_name);
-	if (!GetUserName(user_name, &len))
+	if (!GetUserNameA(user_name, &len))
 		return NULL;
 	p.pw_name = user_name;
 	p.pw_gecos = "unknown";
@@ -1151,7 +1151,7 @@ void mingw_open_html(const char *unixpath)
 {
 	const char *htmlpath = make_backslash_path(unixpath);
 	printf("Launching default browser to display HTML ...\n");
-	ShellExecute(NULL, "open", htmlpath, NULL, "\\", 0);
+	ShellExecuteA(NULL, "open", htmlpath, NULL, "\\", 0);
 }

 int link(const char *oldpath, const char *newpath)
@@ -1160,7 +1160,7 @@ int link(const char *oldpath, const char *newpath)
 	static T create_hard_link = NULL;
 	if (!create_hard_link) {
 		create_hard_link = (T) GetProcAddress(
-			GetModuleHandle("kernel32.dll"), "CreateHardLinkA");
+			GetModuleHandleA("kernel32.dll"), "CreateHardLinkA");
 		if (!create_hard_link)
 			create_hard_link = (T)-1;
 	}
-- 
1.6.5.rc1.44.ga1675
Next: Johannes Sixt
Message 1 of 13 in “compat/mingw.c: MSVC build must use ANSI Win32 API's”
  1. compat/mingw.c: MSVC build must use ANSI Win32 API'sMichael Wookey, Sep 22, 2009
  2. Johannes SixtSep 22, 2009
  3. Marius Storm-OlsenSep 22, 2009
  4. Michael WookeySep 22, 2009
  5. Marius Storm-OlsenSep 22, 2009
  6. Michael WookeySep 22, 2009
  7. Michael WookeySep 23, 2009
  8. Johannes SixtSep 28, 2009
  9. Michael WookeySep 28, 2009
  10. Johannes SixtSep 28, 2009
  11. Michael WookeySep 28, 2009
  12. Michael WookeySep 28, 2009
  13. Marius Storm-OlsenSep 28, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.