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.

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

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.

Lennart

-- 
Lennart Poettering                        Red Hat, Inc.
lennart [at] poettering [dot] net         ICQ# 11060553
http://0pointer.net/lennart/           GnuPG 0x1A015CC4
_______________________________________________
libcanberra-discuss mailing list
[email protected]
https://tango.0pointer.de/mailman/listinfo/libcanberra-discuss

Reply via email to