2 * Copyright © 2006 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or (at
7 * your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
22 git_system (char *command
)
26 /* printf ("\t%s\n", command); */
28 ret
= system (command
);
30 fprintf (stderr
, "%s failed\n", command
);
37 git_system_to_string (char *command
)
43 f
= popen (command
, "r");
45 fprintf (stderr
, "%s: %s\n", command
, strerror (errno
));
48 if (fgets (buf
, sizeof (buf
), f
) == NULL
) {
49 fprintf (stderr
, "%s: %s\n", command
, strerror (errno
));
53 while (getc (f
) != EOF
)
56 nl
= strchr (buf
, '\n');
63 git_string_to_system (char *command
, char *string
)
67 f
= popen (command
, "w");
69 fprintf (stderr
, "%s: %s\n", command
, strerror (errno
));
72 if (fputs (string
, f
) == EOF
) {
73 fprintf (stderr
, "%s: %s\n", command
, strerror (errno
));
82 git_format_command (const char *fmt
, ...)
84 /* Guess we need no more than 100 bytes. */
89 if ((p
= malloc (size
)) == NULL
)
93 /* Try to print in the allocated space. */
95 n
= vsnprintf (p
, size
, fmt
, ap
);
97 /* If that worked, return the string. */
98 if (n
> -1 && n
< size
)
100 /* Else try again with more space. */
101 if (n
> -1) /* glibc 2.1 */
102 size
= n
+1; /* precisely what is needed */
104 size
*= 2; /* twice the old size */
105 if ((np
= realloc (p
, size
)) == NULL
) {