From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 67205 invoked by alias); 25 Jun 2017 07:23:38 -0000 Mailing-List: contact cygwin-apps-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: cygwin-apps-cvs-owner@sourceware.org Received: (qmail 67122 invoked by uid 10114); 25 Jun 2017 07:23:36 -0000 Date: Sun, 25 Jun 2017 07:23:00 -0000 Message-ID: <20170625072336.67096.qmail@sourceware.org> From: mgeisert@sourceware.org To: cygwin-apps-cvs@sourceware.org Subject: [cygutils - Chuck Wilson's collection of Cygwin utilities] branch master, updated. v1_4_15a-1-g0bb5587 X-Git-Refname: refs/heads/master X-Git-Reftype: branch X-Git-Oldrev: c40468c023afa487d6c5ace0a541a319919b50fd X-Git-Newrev: 0bb5587562e46e5955c3e55f2047bfc87857ade6 X-SW-Source: 2017-q2/txt/msg00054.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=cygwin-apps/cygutils.git;h=0bb5587562e46e5955c3e55f2047bfc87857ade6 commit 0bb5587562e46e5955c3e55f2047bfc87857ade6 Author: Mark Geisert Date: Sat Jun 24 23:50:20 2017 -0700 Release 1.4.16 Diff: --- BRANCHES | 2 + ChangeLog | 17 +++- configure.ac | 2 +- cygutils.cygport | 6 +- src/banner/banner.c | 2 +- src/clip/getclip.c | 2 +- src/clip/putclip.c | 2 +- src/conv/conv.c | 2 +- src/cygstart/cygstart.c | 2 +- src/dump/dump.c | 2 +- src/ipc/ipck | 108 +++++++++--------- src/ipc/shmtool.c | 6 + src/mkshortcut/mkshortcut.c | 249 +++++++++++++++------------------------ src/readshortcut/readshortcut.c | 90 +++++++------- src/winln/winln.c | 1 + 15 files changed, 230 insertions(+), 263 deletions(-) diff --git a/ABOUT-NLS b/ABOUT-NLS old mode 100755 new mode 100644 diff --git a/BRANCHES b/BRANCHES index 3f1d629..753f632 100644 --- a/BRANCHES +++ b/BRANCHES @@ -102,3 +102,5 @@ v1_4_13 (devel) v1_4_14 | v1_4_15 + | +v1_4_16 diff --git a/ChangeLog b/ChangeLog index 7271f8f..6e57894 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2017-06-25 Mark Geisert + + Release 1.4.16 + * configure.ac: Bump version number to 1.4.16. + * BRANCHES: Ditto. + * cygutils.cygport: Ditto, plus remove execute bits from file mode. + * src/mkshortcut/mkshortcut.c: Add Unicode support from Thomas Wolff. + * src/readshortcut/readshortcut.c: Ditto, plus minor formatting fixes. + * src/conv/conv.c: Remove execute bits from file mode. + * src/ipc/semstat.c: Ditto. + * ABOUT-NLS: Ditto. + * src/ipc/ipck: Minor formatting fixes. + * src/*/*.c: Add 'void' type to printLicense() definition. + * src/winln/winln.c: Add "#define _GNU_SOURCE" to get asprintf() proto. + 2015-11-23 Mark Geisert * src/conv/conv.c: Add "#include " to avoid compiler warning. @@ -12,7 +27,7 @@ * BRANCHES: Ditto. * src/cygdrop/cygdrop.cc (match_priv): strcmpi() -> strcasecmp(). * src/lpr/Printer.cc (::mapPortName): stricmp() -> strcasecmp(). - * src/mkshortcut/mkshortcut.cc: Don't free() adjusted pointer. + * src/mkshortcut/mkshortcut.c: Don't free() adjusted pointer. Also handle changed Windows behavior when saving link to relative path; evident after Windows 7. Reporter Anthony Heading refers to https://msdn.microsoft.com/en-us/ diff --git a/configure.ac b/configure.ac index 2b6d1cd..830f1bf 100644 --- a/configure.ac +++ b/configure.ac @@ -1,6 +1,6 @@ # Process this file with autoconf to produce a configure script. AC_PREREQ(2.69) -AC_INIT(cygutils, 1.4.15, cygwin@cygwin.com) +AC_INIT(cygutils, 1.4.16, cygwin@cygwin.com) AC_CONFIG_SRCDIR([config.h.in]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/cygutils.cygport b/cygutils.cygport old mode 100755 new mode 100644 index c9ac76d..652d488 --- a/cygutils.cygport +++ b/cygutils.cygport @@ -1,13 +1,13 @@ NAME=cygutils -VERSION=1.4.15 -RELEASE=2 +VERSION=1.4.16 +RELEASE=1 SUMM="A collection of simple utilities" DESC="A collection of simple (single source file) utilities, including" HOMEPAGE="http://cygutils.fruitbat.org/cygutils-package/index.html" GIT_URI="git://cygwin.com/git/cygwin-cygutils.git" -GIT_TAG="v1_4_15a" +GIT_TAG="v1_4_16" inherit git PKG_NAMES="cygutils cygutils-extra cygutils-x11" diff --git a/src/banner/banner.c b/src/banner/banner.c index 1e4e4fe..86e3322 100644 --- a/src/banner/banner.c +++ b/src/banner/banner.c @@ -253,7 +253,7 @@ printBottomDescription (FILE * f, char *name) fprintf (f, "The banner text is displayed horizontally.\n"); } -static +static void printLicense (FILE * f, char *name) { fprintf (f, diff --git a/src/clip/getclip.c b/src/clip/getclip.c index b9e169d..4ddbce3 100644 --- a/src/clip/getclip.c +++ b/src/clip/getclip.c @@ -231,7 +231,7 @@ printBottomDescription (FILE * f, char *name) "\nNOTE: by default, no line ending conversion is performed.\n"); } -static +static void printLicense (FILE * f, char *name) { fprintf (f, diff --git a/src/clip/putclip.c b/src/clip/putclip.c index 08c4931..24aefdf 100644 --- a/src/clip/putclip.c +++ b/src/clip/putclip.c @@ -229,7 +229,7 @@ printBottomDescription (FILE * f, char *name) fprintf (f, "NOTE: by default, no line ending conversion is performed.\n"); } -static +static void printLicense (FILE * f, char *name) { fprintf (f, diff --git a/src/conv/conv.c b/src/conv/conv.c old mode 100755 new mode 100644 index 0a01576..dc0389b --- a/src/conv/conv.c +++ b/src/conv/conv.c @@ -328,7 +328,7 @@ static void printBottomDescription(FILE * f, char * name) fprintf(f, " [input file list...] for each file listed, convert in place.\n"); fprintf(f, " If none specified, then use stdin/stdout\n"); } -static printLicense(FILE * f, char * name) +static void printLicense(FILE * f, char * name) { fprintf (f, "This program is free software: you can redistribute it and/or modify\n" diff --git a/src/cygstart/cygstart.c b/src/cygstart/cygstart.c index d558cb9..7e5bf3a 100644 --- a/src/cygstart/cygstart.c +++ b/src/cygstart/cygstart.c @@ -800,7 +800,7 @@ printBottomDescription (FILE * f, char *name) fprintf (f, "Please report any bugs to .\n"); } -static +static void printLicense (FILE * f, char *name) { fprintf (f, diff --git a/src/dump/dump.c b/src/dump/dump.c index 3693957..608dace 100644 --- a/src/dump/dump.c +++ b/src/dump/dump.c @@ -174,7 +174,7 @@ printBottomDescription (FILE * f, char *name) "\nSimilar in behavior to 'od -Ax -tx2z [a file]'\n"); } -static +static void printLicense (FILE * f, char *name) { fprintf (f, diff --git a/src/ipc/ipck b/src/ipc/ipck index f332416..48bf42d 100755 --- a/src/ipc/ipck +++ b/src/ipc/ipck @@ -24,63 +24,63 @@ IPCRM=${DIR}/ipcrm${MOD} syntaxe() { - echo "" - echo "IPC destruction" - echo "---------------" - echo "" - echo " ipck [all | allsem | allmsg | allshm]" - echo "" + echo "" + echo "IPC destruction" + echo "---------------" + echo "" + echo " ipck [all | allsem | allmsg | allshm]" + echo "" } if test $# -eq 1 then - case $1 in - all) - echo "kill all ipc" - a=`${IPCS} | grep "_sem" | awk '{print $2}'` - if test " $a" != " " - then - ${IPCRM} sem $a - fi - a=`${IPCS} | grep "_shm" | awk '{print $2}'` - if test " $a" != " " - then - ${IPCRM} shm $a - fi - a=`${IPCS} | grep "_msg" | awk '{print $2}'` - if test " $a" != " " - then - ${IPCRM} msg $a - fi - ;; - allsem) - echo "kill all sem" - a=`${IPCS} | grep "_sem" | awk '{print $2}'` - if test " $a" != " " - then - ${IPCRM} sem $a - fi - ;; - allmsg) - echo "kill all msg" - a=`${IPCS} | grep "_msg" | awk '{print $2}'` - if test " $a" != " " - then - ${IPCRM} msg $a - fi - ;; - allshm) - echo "kill all shm" - a=`${IPCS} | grep "_shm" | awk '{print $2}'` - if test " $a" != " " - then - ${IPCRM} shm $a - fi - ;; - *) - syntaxe - ;; - esac + case $1 in + all) + echo "kill all ipc" + a=`${IPCS} | grep "_sem" | awk '{print $2}'` + if test " $a" != " " + then + ${IPCRM} sem $a + fi + a=`${IPCS} | grep "_shm" | awk '{print $2}'` + if test " $a" != " " + then + ${IPCRM} shm $a + fi + a=`${IPCS} | grep "_msg" | awk '{print $2}'` + if test " $a" != " " + then + ${IPCRM} msg $a + fi + ;; + allsem) + echo "kill all sem" + a=`${IPCS} | grep "_sem" | awk '{print $2}'` + if test " $a" != " " + then + ${IPCRM} sem $a + fi + ;; + allmsg) + echo "kill all msg" + a=`${IPCS} | grep "_msg" | awk '{print $2}'` + if test " $a" != " " + then + ${IPCRM} msg $a + fi + ;; + allshm) + echo "kill all shm" + a=`${IPCS} | grep "_shm" | awk '{print $2}'` + if test " $a" != " " + then + ${IPCRM} shm $a + fi + ;; + *) + syntaxe + ;; + esac else - syntaxe + syntaxe fi diff --git a/src/ipc/semstat.c b/src/ipc/semstat.c old mode 100755 new mode 100644 diff --git a/src/ipc/shmtool.c b/src/ipc/shmtool.c index 70b4c41..3634eb7 100644 --- a/src/ipc/shmtool.c +++ b/src/ipc/shmtool.c @@ -39,6 +39,7 @@ #define SEGSIZE 100 +int usage () { fprintf (stderr, "shmtool - A utility for tinkering with shared memory\n"); @@ -49,23 +50,27 @@ usage () exit (1); } +int writeshm (int shmid, char *segptr, char *text) { strcpy (segptr, text); printf ("Done...\n"); } +int readshm (int shmid, char *segptr) { printf ("segptr: %s\n", segptr); } +int removeshm (int shmid) { shmctl (shmid, IPC_RMID, 0); printf ("Shared memory segment marked for deletion\n"); } +int changemode (int shmid, char *mode) { struct shmid_ds myshmds; @@ -85,6 +90,7 @@ changemode (int shmid, char *mode) printf ("New permissions are : %o\n", myshmds.shm_perm.mode); } +int main (int argc, char *argv[]) { key_t key; diff --git a/src/mkshortcut/mkshortcut.c b/src/mkshortcut/mkshortcut.c index 6707eb4..098884d 100644 --- a/src/mkshortcut/mkshortcut.c +++ b/src/mkshortcut/mkshortcut.c @@ -2,6 +2,10 @@ * * Copyright (c) 2002 Joshua Daniel Franklin * + * Unicode-enabled by (C) 2015 Thomas Wolff + * semantic changes: + Allow dir to be empty (legal in shortcut) + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -22,7 +26,7 @@ * 2: system error (out of memory, etc.) * 3: windows error (interface failed) * - * Compile with: gcc -o prog.exe mkshortcut.c -lpopt -lole32 -luuid + * Compile with: gcc -o mkshortcut mkshortcut.c -lpopt -lole32 /usr/lib/w32api/libuuid.a * (You'd need to uncomment the moved to common.h lines.) * */ @@ -31,6 +35,9 @@ # include "config.h" #endif #include "common.h" +#include + +#include #define NOCOMATTRIBUTE @@ -42,6 +49,8 @@ #include */ #include +#include // strlen + static const char versionID[] = PACKAGE_VERSION; static const char revID[] = @@ -79,6 +88,15 @@ static void license (FILE * f, char *name); static char *program_name; static poptContext optCon; +static WCHAR * +towcs (const char * s) +{ + int sizew = (strlen (s) * 2 + 1); // worst case: surrogates + WCHAR * ws = malloc (sizew * sizeof (WCHAR)); + mbstowcs (ws, s, sizew); + return ws; +} + int main (int argc, const char **argv) { @@ -136,6 +154,8 @@ main (int argc, const char **argv) {NULL, '\0', 0, NULL, 0, NULL, NULL} }; + setlocale (LC_CTYPE, ""); + tmp_str = strrchr (argv[0], '/'); if (tmp_str == NULL) { @@ -207,12 +227,12 @@ main (int argc, const char **argv) opts.icon_flag = 1; if (arg = poptGetOptArg (optCon)) { - opts.icon_name_arg = (char *) cygwin_create_path( + opts.icon_name_arg = (char *) cygwin_create_path ( CCP_POSIX_TO_WIN_A, arg); if (opts.icon_name_arg == NULL) { fprintf (stderr, "%s: error converting posix path to win32 (%s)\n", - program_name, strerror(errno)); + program_name, strerror (errno)); ec = 2; goto exit; } @@ -350,56 +370,19 @@ main (int argc, const char **argv) } exit: - poptFreeContext (optCon); - if (opts.target_arg) - { - free (opts.target_arg); - } - if (opts.name_arg) - { - free (opts.name_arg); - } - if (opts.desc_arg) - { - free (opts.desc_arg); - } - if (opts.dir_name_arg) - { - free (opts.dir_name_arg); - } - if (opts.argument_arg) - { - free (opts.argument_arg); - } - if (opts.icon_name_arg) - { - free (opts.icon_name_arg); - } - free (program_name); - return (ec); -} - -static char * -xstrndup (const char *string, size_t n) -{ - char *s = strndup (string, n); - if (!s) - { - fprintf (stderr, "%s: out of memory\n", program_name); - exit(2); - } - return s; + return ec; } static char * -xstrncat (char **dest, const char *add, size_t n) +xstrncat (char **dest, const char *add) { + size_t n = strlen (add); size_t len = strlen (*dest) + n + 1; char *s = (char *) realloc (*dest, len * sizeof (char)); if (!s) { fprintf (stderr, "%s: out of memory\n", program_name); - exit(2); + exit (2); } *dest = s; return strncat (*dest, add, n); @@ -408,20 +391,28 @@ xstrncat (char **dest, const char *add, size_t n) int mkshortcut (optvals opts) { - char* link_name = NULL; - char* exe_name = NULL; - char* dir_name = NULL; - char* desc = NULL; - char *buf_str, *tmp_str, *base_str; + char * link_name = NULL; + WCHAR * exe_name = NULL; + WCHAR * dir_name = NULL; + WCHAR * desc = NULL; + char * buf_str; + char * tmp_str; + char * base_str; int tmp; /* For OLE interface */ LPITEMIDLIST id; HRESULT hres; - IShellLink *shell_link; - IPersistFile *persist_file; - WCHAR widepath[MAX_PATH]; - char link_path[MAX_PATH]; + IShellLinkW * shell_link; + IPersistFile * persist_file; + + exe_name = (WCHAR *) cygwin_create_path (CCP_POSIX_TO_WIN_W, opts.target_arg); + if (!exe_name) + { + fprintf (stderr, "%s: error converting posix path to win32 (%s)\n", + program_name, strerror (errno)); + return 2; + } /* If there's a colon in the TARGET, it should be a URL */ if (strchr (opts.target_arg, ':') != NULL) @@ -432,64 +423,46 @@ mkshortcut (optvals opts) fprintf (stderr, "%s: all paths must be in POSIX format\n", program_name); usage (stderr, program_name); - return (1); + return 1; } - exe_name = xstrndup (opts.target_arg, strlen(opts.target_arg)); - dir_name = xstrndup ("", 0); /* No working dir for URL */ + dir_name = L""; } /* Convert TARGET to win32 path */ else { - buf_str = xstrndup (opts.target_arg, strlen(opts.target_arg)); - exe_name = (char *) cygwin_create_path (CCP_POSIX_TO_WIN_A, - opts.target_arg); - if (!exe_name) - { - fprintf (stderr, "%s: error converting posix path to win32 (%s)\n", - program_name, strerror(errno)); - free (buf_str); - return 2; - } + buf_str = strdup (opts.target_arg); - /* Get a working dir from 'w' option */ if (opts.dir_name_arg != NULL) + /* Get a working dir from 'w' option */ { if (strchr (opts.dir_name_arg, ':') != NULL) { - free (buf_str); - free (exe_name); fprintf (stderr, "%s: all paths must be in POSIX format\n", program_name); usage (stderr, program_name); - return (1); + return 1; } - dir_name = (char *) cygwin_create_path (CCP_POSIX_TO_WIN_A, - opts.dir_name_arg); + dir_name = (WCHAR *) cygwin_create_path (CCP_POSIX_TO_WIN_W, + opts.dir_name_arg); if (!dir_name) { fprintf (stderr, "%s: error converting posix path to win32 (%s)\n", - program_name, strerror(errno)); - free (buf_str); - free (exe_name); + program_name, strerror (errno)); return 2; } } - /* Get a working dir from the exepath */ else + /* Allow dir to be empty (legal in shortcut) */ { - tmp_str = strrchr (exe_name, '\\'); - tmp = strlen (exe_name) - strlen (tmp_str); - dir_name = xstrndup (exe_name, tmp); - dir_name[tmp] = '\0'; + dir_name = L""; } - if (buf_str) free (buf_str); } /* Generate a name for the link if not given */ if (opts.name_arg == NULL) { /* Strip trailing /'s if any */ - buf_str = xstrndup (opts.target_arg, strlen(opts.target_arg)); + buf_str = strdup (opts.target_arg); base_str = buf_str; tmp_str = buf_str; tmp = strlen (buf_str) - 1; @@ -505,8 +478,7 @@ mkshortcut (optvals opts) tmp_str = buf_str + 1; buf_str++; } - link_name = xstrndup (tmp_str, strlen (tmp_str)); - free (base_str); + link_name = strdup (tmp_str); } /* User specified a name, so check it and convert */ else @@ -520,7 +492,7 @@ mkshortcut (optvals opts) "%s: absolute pathnames not allowed with -D/-P\n", program_name); usage (stderr, program_name); - return (1); + return 1; } } /* Sigh. Another W32 path */ @@ -529,14 +501,15 @@ mkshortcut (optvals opts) fprintf (stderr, "%s: all paths must be in POSIX format\n", program_name); usage (stderr, program_name); - return (1); + return 1; } link_name = (char *) cygwin_create_path ( CCP_POSIX_TO_WIN_A | CCP_RELATIVE, opts.name_arg); + // passing multi-byte characters transparently per byte if (!link_name) { fprintf (stderr, "%s: error converting posix path to win32 (%s)\n", - program_name, strerror(errno)); + program_name, strerror (errno)); return 2; } } @@ -546,16 +519,16 @@ mkshortcut (optvals opts) { tmp = strlen (link_name) - 4; if (strncmp (link_name + tmp, ".lnk", 4) != 0) - xstrncat (&link_name, ".lnk", 4); + xstrncat (&link_name, ".lnk"); } else - xstrncat (&link_name, ".lnk", 4); + xstrncat (&link_name, ".lnk"); /* Prepend relative path if necessary */ if (opts.desktop_flag) { char local_buf[MAX_PATH]; - buf_str = xstrndup (link_name, strlen (link_name)); + buf_str = strdup (link_name); if (!opts.allusers_flag) SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); @@ -568,17 +541,15 @@ mkshortcut (optvals opts) SHGetSpecialFolderLocation (NULL, CSIDL_DESKTOPDIRECTORY, &id); SHGetPathFromIDList (id, local_buf); } - free (link_name); - link_name = xstrndup (local_buf, strlen (local_buf)); - xstrncat (&link_name, "\\", 1); - xstrncat (&link_name, buf_str, strlen (buf_str)); - free (buf_str); + link_name = strdup (local_buf); + xstrncat (&link_name, "\\"); + xstrncat (&link_name, buf_str); } if (opts.smprograms_flag) { char local_buf[MAX_PATH]; - buf_str = xstrndup (link_name, strlen (link_name)); + buf_str = strdup (link_name); if (!opts.allusers_flag) SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); @@ -591,36 +562,41 @@ mkshortcut (optvals opts) SHGetSpecialFolderLocation (NULL, CSIDL_PROGRAMS, &id); SHGetPathFromIDList (id, local_buf); } - free (link_name); - link_name = xstrndup (local_buf, strlen (local_buf)); - xstrncat (&link_name, "\\", 1); - xstrncat (&link_name, buf_str, strlen (buf_str)); - free (buf_str); + link_name = strdup (local_buf); + xstrncat (&link_name, "\\"); + xstrncat (&link_name, buf_str); } + /* Make link name Unicode-compliant */ + WCHAR * widename = towcs (link_name); + /* After Windows 7, saving link to relative path fails; work around that */ - hres = GetFullPathName (link_name, sizeof (link_path), link_path, 0); +#ifdef corrupt_memory + WCHAR widepath[MAX_PATH]; + hres = GetFullPathNameW (widename, sizeof (widepath), widepath, NULL); if (hres == 0) { fprintf (stderr, "%s: Could not qualify link name\n", program_name); return 2; } - free (link_name); - link_name = xstrndup (link_path, strlen (link_path)); +#else + WCHAR * widepath = (WCHAR *) cygwin_create_path (CCP_POSIX_TO_WIN_W, link_name); +#endif + link_name = (char *) cygwin_create_path (CCP_WIN_W_TO_POSIX, widepath); /* Setup description text */ if (opts.desc_arg != NULL) { - desc = xstrndup (opts.desc_arg, strlen (opts.desc_arg)); + desc = towcs (opts.desc_arg); } else { /* Put the POSIX path in the "Description", just to be nice */ - desc = (char *) cygwin_create_path (CCP_WIN_A_TO_POSIX, exe_name); + desc = towcs (cygwin_create_path (CCP_WIN_A_TO_POSIX, exe_name)); if (!desc) { fprintf (stderr, "%s: error converting win32 path to posix (%s)\n", - program_name, strerror(errno)); + program_name, strerror (errno)); return 2; } } @@ -631,16 +607,12 @@ mkshortcut (optvals opts) { fprintf (stderr, "%s: Could not initialize OLE interface\n", program_name); - free (link_name); - free (exe_name); - free (dir_name); - free (desc); - return (3); + return 3; } hres = CoCreateInstance (&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, - &IID_IShellLink, (void **) &shell_link); + &IID_IShellLinkW, (void **) &shell_link); if (SUCCEEDED (hres)) { hres = @@ -652,40 +624,22 @@ mkshortcut (optvals opts) shell_link->lpVtbl->SetDescription (shell_link, desc); shell_link->lpVtbl->SetWorkingDirectory (shell_link, dir_name); if (opts.argument_arg) - shell_link->lpVtbl->SetArguments (shell_link, opts.argument_arg); + shell_link->lpVtbl->SetArguments (shell_link, + towcs (opts.argument_arg)); if (opts.icon_flag) shell_link->lpVtbl->SetIconLocation (shell_link, - opts.icon_name_arg, + towcs (opts.icon_name_arg), opts.offset); if (opts.show_flag != SW_SHOWNORMAL) shell_link->lpVtbl->SetShowCmd (shell_link, opts.show_flag); - - /* Make link name Unicode-compliant */ - hres = - MultiByteToWideChar (CP_ACP, 0, link_name, -1, widepath, - MAX_PATH); - if (!SUCCEEDED (hres)) - { - fprintf (stderr, "%s: Unicode translation failed%d\n", - program_name, hres); - free (link_name); - free (exe_name); - free (dir_name); - free (desc); - return (3); - } hres = persist_file->lpVtbl->Save (persist_file, widepath, TRUE); if (!SUCCEEDED (hres)) { fprintf (stderr, "%s: Saving \"%s\" failed; does the target directory exist?\n", program_name, link_name); - free (link_name); - free (exe_name); - free (dir_name); - free (desc); - return (3); + return 3; } persist_file->lpVtbl->Release (persist_file); shell_link->lpVtbl->Release (shell_link); @@ -698,45 +652,32 @@ mkshortcut (optvals opts) if (posixpath && *posixpath) { struct stat statbuf; - if (stat(posixpath, &statbuf)) + if (stat (posixpath, &statbuf)) { fprintf (stderr, "%s: stat \"%s\" failed\n", program_name, posixpath); } - else if (chmod(posixpath, statbuf.st_mode|S_IRUSR|S_IRGRP|S_IROTH)) + else if (chmod (posixpath, statbuf.st_mode|S_IRUSR|S_IRGRP|S_IROTH)) { fprintf (stderr, "%s: chmod \"%s\" failed\n", program_name, posixpath); } } - free(posixpath); } - free (link_name); - free (exe_name); - free (dir_name); - free (desc); - return (0); + return 0; } else { fprintf (stderr, "%s: QueryInterface failed\n", program_name); - free (link_name); - free (exe_name); - free (dir_name); - free (desc); - return (3); + return 3; } } else { fprintf (stderr, "%s: CoCreateInstance failed\n", program_name); - free (link_name); - free (exe_name); - free (dir_name); - free (desc); - return (3); + return 3; } } @@ -760,7 +701,7 @@ printBottomDescription (FILE * f, char *name) "\nNOTE: All filename arguments must be in unix (POSIX) format\n"); } -static +static void printLicense (FILE * f, char *name) { fprintf (f, diff --git a/src/readshortcut/readshortcut.c b/src/readshortcut/readshortcut.c index bfe60ad..9912985 100644 --- a/src/readshortcut/readshortcut.c +++ b/src/readshortcut/readshortcut.c @@ -4,6 +4,8 @@ * Copyright (C) 2003 Rob Siklos * http://www.cygwin.com/ml/cygwin/2003-08/msg00640.html * + * Unicode-enabled by (C) 2015 Thomas Wolff + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or @@ -30,7 +32,7 @@ * * - comment the config.h and common.h includes * - uncomment the stdio and popt.h includes - * - run "gcc readshortcut.c -o readshortcut.exe -lpopt -luuid -lole32" + * - run gcc readshortcut.c -o readshortcut -lpopt -lole32 /usr/lib/w32api/libuuid.a * */ @@ -39,6 +41,7 @@ # include "config.h" #endif #include "common.h" +#include /* moved to common.h */ /* @@ -150,6 +153,8 @@ main (int argc, const char **argv) {NULL, '\0', 0, NULL, 0, NULL, NULL} }; + setlocale (LC_CTYPE, ""); + /* get the program name */ tmp_str = strrchr (argv[0], '/'); if (tmp_str == NULL) @@ -261,11 +266,11 @@ exit: return result; } -static int startsWithDOSEnvVar(const char* string, size_t n) +static int startsWithDOSEnvVar (const char* string, size_t n) { if (n > 2 && string[0] == '%') { - const char *p = strchr(&string[1], '%'); + const char *p = strchr (&string[1], '%'); if (p && (p - string) > 1) return 1; } @@ -276,10 +281,10 @@ int readshortcut (optvals * opts) { HRESULT hres; - IShellLink *shell_link; + IShellLinkW *wshell_link; IPersistFile *persist_file; - char strPath[MAX_PATH]; - char strBuff[BUFF_SIZE]; + char strPath[MAX_PATH * 3]; + char strBuff[BUFF_SIZE * 3]; int iBuff; int result = ERR_NONE; /* the value to return on exit */ @@ -296,7 +301,7 @@ readshortcut (optvals * opts) if (opts->target_fname == NULL) { fprintf (stderr, "%s: memory allocation error\n", program_name); - return (ERR_SYS); + return ERR_SYS; } strcat (opts->target_fname, ".lnk"); } @@ -309,7 +314,7 @@ readshortcut (optvals * opts) if (opts->target_fname == NULL) { fprintf (stderr, "%s: memory allocation error\n", program_name); - return (ERR_SYS); + return ERR_SYS; } strcat (opts->target_fname, ".lnk"); } @@ -326,13 +331,13 @@ readshortcut (optvals * opts) (strlen (opts->target_fname) > 2 && opts->target_fname[0] == '\\' && opts->target_fname[1] == '\\') || startsWithDOSEnvVar (opts->target_fname, strlen (opts->target_fname)))) { - char *strTmpPath = (char *)cygwin_create_path(CCP_POSIX_TO_WIN_A, + char *strTmpPath = (char *)cygwin_create_path (CCP_POSIX_TO_WIN_A, opts->target_fname); if (strTmpPath == NULL) { fprintf (stderr, "%s: error converting target posix path to win32 (%s)\n", - program_name, strerror(errno)); - return (ERR_SYS); + program_name, strerror (errno)); + return ERR_SYS; } free (opts->target_fname); opts->target_fname = strTmpPath; @@ -343,32 +348,32 @@ readshortcut (optvals * opts) { fprintf (stderr, "%s: Could not initialize OLE interface\n", program_name); - return (ERR_WIN); + return ERR_WIN; } /* Get a pointer to the IShellLink interface. */ hres = CoCreateInstance (&CLSID_ShellLink, NULL, CLSCTX_INPROC_SERVER, - &IID_IShellLink, (void **) &shell_link); + &IID_IShellLinkW, (void **) &wshell_link); if (!SUCCEEDED (hres)) { fprintf (stderr, "%s: CoCreateInstance failed\n", program_name); - return (ERR_WIN); + return ERR_WIN; } /* Get a pointer to the IPersistFile interface. */ hres = - shell_link->lpVtbl->QueryInterface (shell_link, &IID_IPersistFile, + wshell_link->lpVtbl->QueryInterface (wshell_link, &IID_IPersistFile, (void **) &persist_file); if (SUCCEEDED (hres)) { WCHAR wsz[MAX_PATH]; + WCHAR ws[BUFF_SIZE]; /* Ensure that the string is Unicode. */ - MultiByteToWideChar (CP_ACP, 0, (LPCSTR) opts->target_fname, -1, wsz, - MAX_PATH); + mbstowcs (wsz, opts->target_fname, sizeof wsz); /* Load the shortcut. */ hres = persist_file->lpVtbl->Load (persist_file, wsz, STGM_READ); @@ -379,33 +384,36 @@ readshortcut (optvals * opts) if (opts->show_all || opts->show_target) { char *s; - shell_link->lpVtbl->GetPath (shell_link, strPath, MAX_PATH, + wshell_link->lpVtbl->GetPath (wshell_link, wsz, sizeof wsz, NULL, (opts->show_raw ? SLGP_RAWPATH : 0)); + wcstombs (strPath, wsz, sizeof strPath); if (opts->show_field_names) { printf ("Target: "); } s = formatPath (strPath, opts->pathType); printf ("%s\n", (s ? s : strPath)); - if (s) free(s); + if (s) free (s); } if (opts->show_all || opts->show_working_dir) { char *s; - shell_link->lpVtbl->GetWorkingDirectory (shell_link, strPath, - MAX_PATH); + wshell_link->lpVtbl->GetWorkingDirectory (wshell_link, wsz, + sizeof wsz); + wcstombs (strPath, wsz, sizeof strPath); if (opts->show_field_names) { printf ("Working Directory: "); } s = formatPath (strPath, opts->pathType); printf ("%s\n", (s ? s : strPath)); - if (s) free(s); + if (s) free (s); } if (opts->show_all || opts->show_args) { - shell_link->lpVtbl->GetArguments (shell_link, strBuff, - BUFF_SIZE); + wshell_link->lpVtbl->GetArguments (wshell_link, ws, + sizeof ws); + wcstombs (strBuff, ws, sizeof strBuff); if (opts->show_field_names) { printf ("Arguments: "); @@ -414,7 +422,7 @@ readshortcut (optvals * opts) } if (opts->show_all || opts->show_showCmd) { - shell_link->lpVtbl->GetShowCmd (shell_link, &iBuff); + wshell_link->lpVtbl->GetShowCmd (wshell_link, &iBuff); if (opts->show_field_names) { printf ("Show Command: "); @@ -436,8 +444,9 @@ readshortcut (optvals * opts) } if (opts->show_all || opts->show_icon || opts->show_icon_offset) { - shell_link->lpVtbl->GetIconLocation (shell_link, strPath, - MAX_PATH, &iBuff); + wshell_link->lpVtbl->GetIconLocation (wshell_link, wsz, + sizeof wsz, &iBuff); + wcstombs (strPath, wsz, sizeof strPath); if (opts->show_all || opts->show_icon) { char *s; @@ -447,7 +456,7 @@ readshortcut (optvals * opts) } s = formatPath (strPath, opts->pathType); printf ("%s\n", (s ? s : strPath)); - if (s) free(s); + if (s) free (s); } if (opts->show_all || opts->show_icon_offset) { @@ -460,8 +469,9 @@ readshortcut (optvals * opts) } if (opts->show_all || opts->show_desc) { - shell_link->lpVtbl->GetDescription (shell_link, strBuff, - BUFF_SIZE); + wshell_link->lpVtbl->GetDescription (wshell_link, ws, + sizeof ws); + wcstombs (strBuff, ws, sizeof strBuff); if (opts->show_field_names) { printf ("Description: "); @@ -486,17 +496,9 @@ readshortcut (optvals * opts) } /* Release the pointer to the IShellLink interface. */ - shell_link->lpVtbl->Release (shell_link); - - return (result); -} + wshell_link->lpVtbl->Release (wshell_link); -static char* xstrndup(const char* string, size_t n) -{ - char *s = strndup (string, n); - if (!s) - fprintf (stderr, "%s: memory allocation error\n", program_name); - return s; + return result; } @@ -506,7 +508,7 @@ formatPath (char *strPath, int format) { if (format == PATH_WIN) { - char *s = strndup (strPath, MAX_PATH); + char *s = strdup (strPath); if (!s) fprintf (stderr, "%s: memory allocation error\n", program_name); return s; @@ -520,14 +522,14 @@ formatPath (char *strPath, int format) * cheat a bit: use relative path conversion. */ cygwin_conv_path_t convType = CCP_WIN_A_TO_POSIX; - if (startsWithDOSEnvVar(strPath, strlen (strPath))) + if (startsWithDOSEnvVar (strPath, strlen (strPath))) convType |= CCP_RELATIVE; - char *s = (char *) cygwin_create_path(convType, strPath); + char *s = (char *) cygwin_create_path (convType, strPath); if (!s) { fprintf (stderr, "%s: error converting win32 path to posix (%s)\n", - program_name, strerror(errno)); + program_name, strerror (errno)); } return s; } diff --git a/src/winln/winln.c b/src/winln/winln.c index f72de87..e8c2c2e 100644 --- a/src/winln/winln.c +++ b/src/winln/winln.c @@ -24,6 +24,7 @@ #define _WIN32_WINNT 0x0600 /* Vista, but will run on XP */ #define UNICODE 1 #define _UNICODE 1 +#define _GNU_SOURCE /* to pull in asprintf() from stdio.h */ #if HAVE_CONFIG_H #include "config.h"