wix-on-linux/fake-lib.c
2017-05-18 07:10:17 +01:00

38 lines
845 B
C

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdarg.h>
#include <string.h>
#include <uchar.h>
#include <err.h>
#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;
}