Re: trouble with asprintf

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Darren Salt wrote:
> I demand that Ludwig Nussel may or may not have written...
> 
> [snip]
> > asprintf needs to check for multibyte characters to not cut them in
> > the middle and produce invalid output.
> 
> No - it's encoding-neutral. What you want is your own version which does that

Try the following with 'LANG=C' and 'LANG=de_DE.UTF-8'. You will
notice that in the latter case it will not cut the umlaut.

#define _GNU_SOURCE
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <locale.h>

int main(void)
{
	char* buffer;
	char artist[] = "Haegar";
	int ret;
	setlocale(LC_ALL, "");
	artist[1]=0xc3;
	artist[2]=0xa4;
	ret = asprintf(&buffer,"%.2s\n",artist);
	printf("%d bytes\n", ret);
	printf(buffer);
	free(buffer);
	return 0;
}

cu
Ludwig

-- 
 (o_   Ludwig Nussel
 //\   
 V_/_  http://www.suse.de/
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG Nuernberg)





_______________________________________________
vdr mailing list
vdr@xxxxxxxxxxx
http://www.linuxtv.org/cgi-bin/mailman/listinfo/vdr

[Index of Archives]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Util Linux NG]     [Xfree86]     [Big List of Linux Books]     [Fedora Users]     [Fedora Women]     [ALSA Devel]     [Linux USB]

  Powered by Linux