Remove the dependency on either asprintf or va_copy. This will be included
[dragonfly.git] / lib / libarchive / patches / archive_string_sprintf.c.patch
1 $DragonFly: src/lib/libarchive/patches/Attic/archive_string_sprintf.c.patch,v 1.2 2004/11/14 18:45:55 joerg Exp $
2
3 Index: archive_string_sprintf.c
4 ===================================================================
5 RCS file: /home/ncvs/src/lib/libarchive/archive_string_sprintf.c,v
6 retrieving revision 1.6
7 diff -u -r1.6 archive_string_sprintf.c
8 --- archive_string_sprintf.c    5 Nov 2004 05:32:04 -0000       1.6
9 +++ archive_string_sprintf.c    11 Nov 2004 06:54:41 -0000
10 @@ -46,21 +46,56 @@
11  __archive_string_vsprintf(struct archive_string *as, const char *fmt,
12      va_list ap)
13  {
14 -       size_t l;
15 -       va_list ap1;
16 +       int long_flag, d;
17 +       long l;
18 +       const char *p, *s;
19 +
20 +       __archive_string_ensure(as, 64);
21  
22         if (fmt == NULL) {
23                 as->s[0] = 0;
24                 return;
25         }
26  
27 -       va_copy(ap1, ap);
28 -       l = vsnprintf(as->s, as->buffer_length, fmt, ap);
29 -       /* If output is bigger than the buffer, resize and try again. */
30 -       if (l+1 >= as->buffer_length) {
31 -               __archive_string_ensure(as, l + 1);
32 -               l = vsnprintf(as->s, as->buffer_length, fmt, ap1);
33 +       long_flag = 0;
34 +       for (p = fmt; *p != '\0'; p++) {
35 +               if (*p != '%') {
36 +                       archive_strappend_char(as, *p);
37 +                       continue;
38 +               }
39 +
40 +               p++;
41 +
42 +               switch(*p) {
43 +               case 'l':
44 +                       long_flag = 1;
45 +                       p++;
46 +                       break;
47 +               }
48 +
49 +               switch (*p) {
50 +               case 's':
51 +                       s = va_arg(ap, char *);
52 +                       archive_strcat(as, s);
53 +                       break;
54 +               case 'd':
55 +                       if (long_flag) {
56 +                               l = va_arg(ap, long);
57 +                               __archive_strappend_int(as, l, 10);
58 +                       } else {
59 +                               d = va_arg(ap, int);
60 +                               __archive_strappend_int(as, d, 10);
61 +                       }
62 +                       break;
63 +               case 'o':
64 +                       if (long_flag) {
65 +                               l = va_arg(ap, long);
66 +                               __archive_strappend_int(as, l, 8);
67 +                       } else {
68 +                               d = va_arg(ap, int);
69 +                               __archive_strappend_int(as, d, 8);
70 +                       }
71 +                       break;
72 +               }
73         }
74 -       as->length = l;
75 -       va_end(ap1);
76  }