annotate mp_strings.c @ 35924:d16e3d64b946

build: whitespace cosmetics; add two more section comments
author diego
date Tue, 19 Mar 2013 16:50:29 +0000
parents 2ef9298a81e7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32883
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
1 /*
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
2 * Strings utilities
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
3 *
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
4 * This file is part of MPlayer.
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
5 *
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
9 * (at your option) any later version.
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
10 *
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
14 * GNU General Public License for more details.
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
15 *
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License along
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
19 */
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
20
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
21 #include <stdlib.h>
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
22 #include <stdarg.h>
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
23 #include <stdio.h>
32949
ca6dcdb31fa1 Cosmetics: add empty line between system and local headers and remove pointless
cboesch
parents: 32883
diff changeset
24
32883
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
25 #include "mp_strings.h"
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
26
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
27 char *mp_asprintf(const char *fmt, ...)
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
28 {
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
29 char *p = NULL;
33597
2ef9298a81e7 Avoid va_copy, it is not generally available
reimar
parents: 32949
diff changeset
30 va_list va;
32883
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
31 int len;
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
32
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
33 va_start(va, fmt);
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
34 len = vsnprintf(NULL, 0, fmt, va);
33597
2ef9298a81e7 Avoid va_copy, it is not generally available
reimar
parents: 32949
diff changeset
35 va_end(va);
32883
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
36 if (len < 0)
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
37 goto end;
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
38
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
39 p = malloc(len + 1);
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
40 if (!p)
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
41 goto end;
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
42
33597
2ef9298a81e7 Avoid va_copy, it is not generally available
reimar
parents: 32949
diff changeset
43 va_start(va, fmt);
2ef9298a81e7 Avoid va_copy, it is not generally available
reimar
parents: 32949
diff changeset
44 len = vsnprintf(p, len + 1, fmt, va);
2ef9298a81e7 Avoid va_copy, it is not generally available
reimar
parents: 32949
diff changeset
45 va_end(va);
32883
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
46 if (len < 0)
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
47 free(p), p = NULL;
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
48
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
49 end:
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
50 return p;
fa04e96e6177 Add mp_strings.c with mp_asprintf function.
cboesch
parents:
diff changeset
51 }