X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=development%2Fcygwin%2Flyxeditor.c;h=9bbf0064d86582aed4e5627e2d32567565fce2e6;hb=e798db5739871aaa29f95de321c52f19058064c9;hp=c82a9f22bed7aa6c64210cc5d4c7b2798661b951;hpb=68d936250e909b1746ba03968cc5f09b21b5ec04;p=lyx.git diff --git a/development/cygwin/lyxeditor.c b/development/cygwin/lyxeditor.c index c82a9f22be..9bbf0064d8 100644 --- a/development/cygwin/lyxeditor.c +++ b/development/cygwin/lyxeditor.c @@ -15,13 +15,24 @@ #include #include #include +#include #include #include +void convert_to_full_posix_path(char const * from, char *to) +{ +#if CYGWIN_VERSION_DLL_MAJOR >= 1007 + cygwin_conv_path(CCP_WIN_A_TO_POSIX, from, to, PATH_MAX); +#else + cygwin_conv_to_full_posix_path(from, to); +#endif +} + int main(int ac, char **av) { - char buf[2 * PATH_MAX]; - char posixpath[PATH_MAX + 1]; + char * buf; + int bufsize; + char posixpath[PATH_MAX]; if (ac < 3 || ac > 4) { MessageBox(0, "Usage: lyxeditor [-g] ", @@ -30,14 +41,24 @@ int main(int ac, char **av) } if (ac == 3) { - cygwin_conv_to_full_posix_path(av[1], posixpath); - sprintf(buf, "lyxeditor.sh" PROGRAM_SUFFIX " '%s' %s", - posixpath, av[2]); + char const * fmt = "lyxeditor.sh" PROGRAM_SUFFIX " '%s' %s"; + convert_to_full_posix_path(av[1], posixpath); + bufsize = snprintf(0, 0, fmt, posixpath, av[2]) + 1; + if ((buf = malloc(bufsize))) + snprintf(buf, bufsize, fmt, posixpath, av[2]); } else { - cygwin_conv_to_full_posix_path(av[2], posixpath); - sprintf(buf, "lyxclient" PROGRAM_SUFFIX " %s '%s' %s", - av[1], posixpath, av[3]); + char const * fmt = "lyxclient" PROGRAM_SUFFIX " %s '%s' %s"; + convert_to_full_posix_path(av[2], posixpath); + bufsize = snprintf(0, 0, fmt, av[1], posixpath, av[3]) + 1; + if ((buf = malloc(bufsize))) + snprintf(buf, bufsize, fmt, av[1], posixpath, av[3]); + } + + if (!buf) { + MessageBox(0, "Too long arguments", "lyxeditor", 0); + return 1; } system(buf); + free(buf); return 0; }