2 * Copyright 1999-2008 by Marco d'Itri <md@linux.it>.
4 * do_nofail and merge_args come from the module-init-tools package.
5 * Copyright 2001 by Rusty Russell.
6 * Copyright 2002, 2003 by Rusty Russell, IBM Corporation.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #define _XOPEN_SOURCE 500
33 /* Application-specific */
36 void *do_nofail(void *ptr
, const char *file
, const int line
)
41 err_quit("Memory allocation failure at %s:%d.", file
, line
);
44 /* Prepend options from a string. */
45 char **merge_args(char *args
, char *argv
[], int *argc
)
47 char *arg
, *argstring
;
48 char **newargs
= NULL
;
49 unsigned int i
, num_env
= 0;
54 argstring
= NOFAIL(strdup(args
));
55 for (arg
= strtok(argstring
, " "); arg
; arg
= strtok(NULL
, " ")) {
57 newargs
= NOFAIL(realloc(newargs
,
58 sizeof(newargs
[0]) * (num_env
+ *argc
+ 1)));
59 newargs
[num_env
] = arg
;
65 /* Append commandline args */
67 for (i
= 1; i
<= *argc
; i
++)
68 newargs
[num_env
+ i
] = argv
[i
];
75 void err_sys(const char *fmt
, ...)
80 vfprintf(stderr
, fmt
, ap
);
81 fprintf(stderr
, ": %s\n", strerror(errno
));
86 void err_quit(const char *fmt
, ...)
91 vfprintf(stderr
, fmt
, ap
);