Attempt fix for getCString where internal encoding != external encoding

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@23259 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2006-08-12 04:55:36 +00:00
parent 212c286e3f
commit b553c9a361
2 changed files with 34 additions and 2 deletions

View file

@ -1,3 +1,8 @@
2006-08-12 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSString.m: getCString_c() call getCString_u() to do the
work if external encoding != internal encoding.
2006-08-11 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSTask.m: Fixup for path validation error on mingw32

View file

@ -300,6 +300,12 @@ setup(void)
}
}
/* Predeclare a few functions
*/
static void GSStrWiden(GSStr s);
static void getCString_u(GSStr self, char *buffer, unsigned int maxLength,
NSRange aRange, NSRange *leftoverRange);
/*
* The GSPlaceholderString class is used by the abstract cluster root
* class to provide temporary objects that will be replaced as soon
@ -1585,12 +1591,33 @@ getCharacters_u(GSStr self, unichar *buffer, NSRange aRange)
aRange.length*sizeof(unichar));
}
static inline void
static void
getCString_c(GSStr self, char *buffer, unsigned int maxLength,
NSRange aRange, NSRange *leftoverRange)
{
int len;
/*
* If the internal and external encodings don't match, the simplest
* thing to do is widen the internal data to unicode and use the
* unicode function to get the cString.
*/
if (externalEncoding != internalEncoding)
{
struct {
@defs(GSMutableString)
} o;
memset(&o, '\0', sizeof(o));
o._count = self->_count;
o._capacity = self->_count;
o._contents.c = self->_contents.c;
GSStrWiden((GSStr)&o);
getCString_u((GSStr)&o, buffer, maxLength, aRange, leftoverRange);
NSZoneFree(o._zone, o._contents.u);
return;
}
if (maxLength > self->_count)
{
maxLength = self->_count;
@ -1618,7 +1645,7 @@ getCString_c(GSStr self, char *buffer, unsigned int maxLength,
buffer[len] = '\0';
}
static inline void
static void
getCString_u(GSStr self, char *buffer, unsigned int maxLength,
NSRange aRange, NSRange *leftoverRange)
{