[MPlayer-dev-eng] [PATCH] Add mp_strings.c with mp_asprintf function.

Clément Bœsch ubitux at gmail.com
Thu Jan 20 21:25:45 CET 2011


On Tue, Jan 18, 2011 at 09:43:55AM +0100, Diego Biurrun wrote:
> On Wed, Jan 12, 2011 at 11:44:32PM +0100, Clément Bœsch wrote:
> > 
> > I just made a small equivalent to the GNU asprintf function (since I
> > suppose it's not available on all system supported by mplayer) in order to
> > use it in a few places instead of fixed size buffers like BUFLENGTH in
> > some vo (jpeg, png, …) and maybe a few other PATH_MAX we were speaking a
> > while ago.
> 
> The traditional place for this is the osdep/ directory.  You should also
> check in configure for its presence.
> 

I would have done it in case the function were called "asprintf", and as
pointed out on IRC, it would need a configure test, conditionally
compilation, etc. which is a small burden.

So there is a few solutions:
- Keep the current patch untouched
- Make a osdep/asprintf only compiled on non-gnu systems
- Add some ifdef in the function to call local asprintf if GNU system or
  else this code (and put it in osdep/?)
- Use talloc as pointed out previously (it has a talloc_asprintf iirc)

If anyone has opinion on this, please share.

> > --- /dev/null
> > +++ b/mp_strings.c
> > @@ -0,0 +1,49 @@
> > +
> > +#include <stdlib.h>
> > +#include <stdarg.h>
> > +#include <stdio.h>
> > +#include "mp_strings.h"
> 
> nit: It's nice to separate system and local header #include by an empty line.
> 

Fixed locally.

> > --- /dev/null
> > +++ b/mp_strings.h
> > @@ -0,0 +1,26 @@
> > +
> > +#ifndef MP_STRINGS_H
> > +# define MP_STRINGS_H
> > +
> > +int mp_asprintf(char **strp, const char *fmt, ...);
> > +
> > +#endif
> 
>   #ifndef MPLAYER_MP_STRINGS_H
>   #define MPLAYER_MP_STRINGS_H
> 
>   #endif /* MPLAYER_MP_STRINGS_H */
> 

ditto.

-- 
Clément B.


More information about the MPlayer-dev-eng mailing list