On Wed, Aug 13, 2008 at 02:19:16PM +0200, Lennart Poettering wrote:
> On Wed, 13.08.08 00:14, Daniel Macks ([EMAIL PROTECTED]) wrote:
>
> > strndup() is a GNU extension, not a standard part of unix-ish systems:
> > OS X, in particular, doesn't have it. I was able use the external
> > publib suite of string functions, but had to hack the #include and
> > -lpub for compiling src/sound-theme-spec.c. Would be great if
> > libcanberra used a more standard function, or had some sort of
> > emulation or internal implementation here. It appears that publib has
> > a BSDish license, so could just import its strndup() function.
>
> Patches always welcome!
>
> I already expected this problem, so to make porting of libcanberra
> easy we make use of strdup/strndup only through
> ca_strdup/ca_strndup. They are right now implemented as a macro, but
> implementing them as a proper function in malloc.c for those systems
> which need it is very simple.
Ah yes, now I see...I hadn't looked into the code beyond "didn't
compile due to missing symbol, link ext lib and now it does".
> Since strndup/strdup is trivial to implement I don't really see any
> reason why we should be linking against any further external library,
> or even copy from another source. Something like this should suffice:
>
> #ifndef HAVE_STRNDUP
> char *ca_strndup(const char *t, size_t n) {
> size_t l = strlen(t);
> char *r;
>
> if (l > n)
> l = n;
>
> if (!(r = ca_malloc(l+1)))
> return NULL;
>
> memcpy(r, t, l);
> r[l] = 0;
> return r;
> }
> #endif
Looks great thanks!
> Again, patches welcome.
>
> Please understand that portability patches have to come from *you*
> since I don't run all those exotic operating systems. I will make sure
> it it is easy to port things as far as I can oversee what problems
> there will be, but that's as far as I will do the porting for you.
Sounds fine to me.
dan
--
Daniel Macks
[EMAIL PROTECTED]
http://www.netspace.org/~dmacks
_______________________________________________
libcanberra-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/libcanberra-discuss