revert between 56095 -> 55830 in arch
[AROS.git] / rom / filesys / CDVDFS / src / charset.c
blob263a5a0cff9a3ff444a5adf41e93a3bb6ecdd770
1 #include <dos/dosextens.h>
2 #include <dos/dostags.h>
3 #include <proto/codesets.h>
4 #include <proto/dos.h>
5 #include <proto/exec.h>
6 #include <ctype.h>
7 #include <stdlib.h>
8 #include <string.h>
10 #include "debug.h"
11 #include "globals.h"
12 #include "charset.h"
13 #include "aros_stuff.h"
15 void InitCharset(struct CDVDBase *global)
17 if (!CodesetsBase)
19 CodesetsBase = OpenLibrary("codesets.library", 0);
20 BUG(dbprintf(global, "[CDVDFS] CodesetsBase 0x%p\n", CodesetsBase));
22 if (CodesetsBase)
24 global->uniCodeset = CodesetsFindA("UTF-16", NULL);
25 BUG(dbprintf(global, "[CDVDFS] Unicode codeset: 0x%p\n", global->uniCodeset));
30 int UTF16ToSystem(struct CDVDBase *global, char *from, char *to, unsigned char len)
32 ULONG l = -1;
34 if (global->uniCodeset)
36 char *str;
37 struct TagItem tags[5];
40 * I have to fill in tags in this weird way because otherwise
41 * MorphOS gcc v2.95.3 generates memcpy() call here, and we have
42 * no global SysBase variable.
43 * And i can't use -lcodesets because it also requires global
44 * CodesetsBase.
45 * Please don't change this.
47 tags[0].ti_Tag = CSA_SourceCodeset;
48 tags[0].ti_Data = (IPTR)global->uniCodeset;
49 tags[1].ti_Tag = CSA_Source;
50 tags[1].ti_Data = (IPTR)from;
51 tags[2].ti_Tag = CSA_SourceLen;
52 tags[2].ti_Data = len;
53 tags[3].ti_Tag = CSA_DestLenPtr;
54 tags[3].ti_Data = (IPTR)&l;
55 tags[4].ti_Tag = TAG_DONE;
58 * Unfortunately codesets.library does not allow
59 * to specify CSA_Dest and CSA_DestLen to
60 * CodesetsConvertA(), so we have to do this copy-deallocate
61 * operation.
63 str = CodesetsConvertStrA(tags);
64 if (str)
66 CopyMem(str, to, l);
67 CodesetsFreeA(str, NULL);
71 return l;