From 39faf94ea2fa54f6791641142ad03e7e4f884a69 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 18 May 2017 07:14:27 +0100 Subject: Move the char16 functions into their own file. This completes the removal of the monolithic fake-lib.[ch]. --- Makefile.am | 8 ++++---- configure.ac | 2 +- fake-lib.c | 38 -------------------------------------- fake-lib.h | 5 ----- fake-msi.c | 2 +- fake-winterop.c | 2 +- md5.c | 2 +- uchars.c | 29 +++++++++++++++++++++++++++++ uchars.h | 6 ++++++ version.c | 2 +- 10 files changed, 44 insertions(+), 52 deletions(-) delete mode 100644 fake-lib.c delete mode 100644 fake-lib.h create mode 100644 uchars.c create mode 100644 uchars.h diff --git a/Makefile.am b/Makefile.am index 806366a..b23c901 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,11 +4,11 @@ ACLOCAL_AMFLAGS = -I m4 lib_LTLIBRARIES = libwinterop.so.la libmsi.so.la libpreload.la -libwinterop_so_la_SOURCES = fake-winterop.c fake-lib.c fake-lib.h \ -memory.c memory.h dupstr.c dupstr.h subproc.c subproc.h +libwinterop_so_la_SOURCES = fake-winterop.c memory.c memory.h \ +dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h -libmsi_so_la_SOURCES = fake-msi.c fake-lib.c fake-lib.h md5.c \ -memory.c memory.h version.c dupstr.c dupstr.h subproc.c subproc.h +libmsi_so_la_SOURCES = fake-msi.c md5.c memory.c memory.h version.c \ +dupstr.c dupstr.h subproc.c subproc.h uchars.c uchars.h libpreload_la_SOURCES = preload.c libpreload_la_LDFLAGS = -ldl diff --git a/configure.ac b/configure.ac index a5986be..6b657b6 100644 --- a/configure.ac +++ b/configure.ac @@ -1,7 +1,7 @@ # autoconf input for Wix Linux shim. AC_INIT([wix-linux-shim], [NOVERSION], [anakin@pobox.com]) -AC_CONFIG_SRCDIR([fake-lib.h]) +AC_CONFIG_SRCDIR([makecab.py]) AC_CONFIG_MACRO_DIRS([m4]) AM_INIT_AUTOMAKE(foreign) diff --git a/fake-lib.c b/fake-lib.c deleted file mode 100644 index e2bc364..0000000 --- a/fake-lib.c +++ /dev/null @@ -1,38 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "memory.h" -#include "fake-lib.h" - -char *ascii(const char16_t *wstr, bool translate_slashes) -{ - size_t len = 0; - for (const char16_t *wp = wstr; *wp; wp++) - len++; - char *ret = malloc(len + 1); - char *p = ret; - for (const char16_t *wp = wstr; *wp; wp++) - *p++ = (*wp == '\\' && translate_slashes ? '/' : - *wp < 0x80 ? *wp : - '?'); - *p = '\0'; - return ret; -} - -void c16cpy(char16_t *out, uint32_t *outsize, char *s) -{ - uint32_t retlen = 0; - while (retlen < *outsize) { - char16_t c = (out[retlen] = (unsigned char)*s++); - if (!c) - break; - retlen++; - } - *outsize = retlen; -} diff --git a/fake-lib.h b/fake-lib.h deleted file mode 100644 index 5ae4a91..0000000 --- a/fake-lib.h +++ /dev/null @@ -1,5 +0,0 @@ -#include -#include - -char *ascii(const char16_t *wstr, bool translate_slashes); -void c16cpy(char16_t *out, uint32_t *outsize, char *s); diff --git a/fake-msi.c b/fake-msi.c index 0600671..7bdcdc6 100644 --- a/fake-msi.c +++ b/fake-msi.c @@ -17,7 +17,7 @@ #include "memory.h" #include "dupstr.h" #include "subproc.h" -#include "fake-lib.h" +#include "uchars.h" typedef struct MsiTypePrefix { enum { MAIN, VIEW, RECORD } type; diff --git a/fake-winterop.c b/fake-winterop.c index 1b439fe..d238784 100644 --- a/fake-winterop.c +++ b/fake-winterop.c @@ -14,7 +14,7 @@ #include "memory.h" #include "dupstr.h" #include "subproc.h" -#include "fake-lib.h" +#include "uchars.h" uint32_t HashPublicKeyInfo(void *pCertContext, void *rgbSubjectKeyIdentifier, diff --git a/md5.c b/md5.c index 4074716..71dfc9b 100644 --- a/md5.c +++ b/md5.c @@ -20,7 +20,7 @@ #include #include "memory.h" -#include "fake-lib.h" +#include "uchars.h" /* ---------------------------------------------------------------------- * Core MD5 algorithm: processes 16-word blocks into a message digest. diff --git a/uchars.c b/uchars.c new file mode 100644 index 0000000..5f09f60 --- /dev/null +++ b/uchars.c @@ -0,0 +1,29 @@ +#include "memory.h" +#include "uchars.h" + +char *ascii(const char16_t *wstr, bool translate_slashes) +{ + size_t len = 0; + for (const char16_t *wp = wstr; *wp; wp++) + len++; + char *ret = snewn(len + 1, char); + char *p = ret; + for (const char16_t *wp = wstr; *wp; wp++) + *p++ = (*wp == '\\' && translate_slashes ? '/' : + *wp < 0x80 ? *wp : + '?'); + *p = '\0'; + return ret; +} + +void c16cpy(char16_t *out, uint32_t *outsize, char *s) +{ + uint32_t retlen = 0; + while (retlen < *outsize) { + char16_t c = (out[retlen] = (unsigned char)*s++); + if (!c) + break; + retlen++; + } + *outsize = retlen; +} diff --git a/uchars.h b/uchars.h new file mode 100644 index 0000000..6e68e7c --- /dev/null +++ b/uchars.h @@ -0,0 +1,6 @@ +#include +#include +#include + +char *ascii(const char16_t *wstr, bool translate_slashes); +void c16cpy(char16_t *out, uint32_t *outsize, char *s); diff --git a/version.c b/version.c index c8d4991..2ba7372 100644 --- a/version.c +++ b/version.c @@ -10,7 +10,7 @@ #include #include "memory.h" -#include "fake-lib.h" +#include "uchars.h" uint32_t MsiGetFileVersionW(const char16_t *filename, char16_t *version, uint32_t *version_size, -- cgit v1.2.3-55-g6feb