+DEFUN ("w32-application-type", Fw32_application_type,
+ Sw32_application_type, 1, 1, 0,
+ doc: /* Return the type of an MS-Windows PROGRAM.
+
+Knowing the type of an executable could be useful for formatting
+file names passed to it or for quoting its command-line arguments.
+
+PROGRAM should specify an executable file, including the extension.
+
+The value is one of the following:
+
+`dos' -- a DOS .com program or some other non-PE executable
+`cygwin' -- a Cygwin program that depends on Cygwin DLL
+`msys' -- an MSYS 1.x or MSYS2 program
+`w32-native' -- a native Windows application
+`unknown' -- a file that doesn't exist, or cannot be open, or whose
+ name is not encodable in the current ANSI codepage.
+
+Note that for .bat and .cmd batch files the function returns the type
+of their command interpreter, as specified by the \"COMSPEC\"
+environment variable.
+
+This function returns `unknown' for programs whose file names
+include characters not supported by the current ANSI codepage, as
+such programs cannot be invoked by Emacs anyway. */)
+ (Lisp_Object program)
+{
+ int is_dos_app, is_cygwin_app, is_msys_app, dummy;
+ Lisp_Object encoded_progname;
+ char *progname, progname_a[MAX_PATH];
+
+ program = Fexpand_file_name (program, Qnil);
+ encoded_progname = ENCODE_FILE (program);
+ progname = SSDATA (encoded_progname);
+ unixtodos_filename (progname);
+ filename_to_ansi (progname, progname_a);
+ /* Reject file names that cannot be encoded in the current ANSI
+ codepage. */
+ if (_mbspbrk ((unsigned char *)progname_a, (const unsigned char *)"?"))
+ return Qunknown;
+
+ if (w32_executable_type (progname_a, &is_dos_app, &is_cygwin_app,
+ &is_msys_app, &dummy) != 0)
+ return Qunknown;
+ if (is_dos_app)
+ return Qdos;
+ if (is_cygwin_app)
+ return Qcygwin;
+ if (is_msys_app)
+ return Qmsys;
+ return Qw32_native;
+}
+