blob: de96364b19a7bf110644ce31ed0b175cda160901 [file] [log] [blame]
The Android Open Source Project10e23ee2009-03-03 19:30:30 -08001/**
2 * @file op_popt.c
3 * Wrapper for libpopt - always use this rather
4 * than popt.h
5 *
6 * @remark Copyright 2002 OProfile authors
7 * @remark Read the file COPYING
8 *
9 * @author John Levon
10 * @author Philippe Elie
11 */
12
13#include <stdlib.h>
14#include "op_libiberty.h"
15#include "op_popt.h"
16
17poptContext op_poptGetContext(char const * name,
18 int argc, char const ** argv,
19 struct poptOption const * options, int flags)
20{
21 poptContext optcon;
22 int c;
23
24 xmalloc_set_program_name(argv[0]);
25
26#ifdef CONST_POPT
27 optcon = poptGetContext(name, argc, argv, options, flags);
28#else
29 optcon = poptGetContext((char *)name, argc, (char **)argv, options, flags);
30#endif
31
32 c = poptGetNextOpt(optcon);
33
34 if (c < -1) {
35 fprintf(stderr, "%s: %s: %s\n", argv[0],
36 poptBadOption(optcon, POPT_BADOPTION_NOALIAS),
37 poptStrerror(c));
38 poptPrintHelp(optcon, stderr, 0);
39 exit(EXIT_FAILURE);
40 }
41
42 return optcon;
43}