Add missing range checks so we won't overflow the buffers, thanks to Erik Auerswald...
[mplayer/greg.git] / subopt-helper.h
blob37ea6d6790bfe98c7a73813ce3d2f5f1d08733f2
1 #ifndef SUBOPT_HELPER_H
2 #define SUBOPT_HELPER_H
4 /**
5 * \file subopt-helper.h
7 * \brief Datatype and functions declarations for usage
8 * of the suboption parser.
12 #define OPT_ARG_BOOL 0
13 #define OPT_ARG_INT 1
14 #define OPT_ARG_STR 2
15 #define OPT_ARG_MSTRZ 3 ///< A malloced, zero terminated string, use free()!
17 typedef int (*opt_test_f)(void *);
19 /** simple structure for defining the option name, type and storage location */
20 typedef struct opt_s
22 char * name; ///< string that identifies the option
23 int type; ///< option type as defined in subopt-helper.h
24 void * valp; ///< pointer to the mem where the value should be stored
25 opt_test_f test; ///< argument test func ( optional )
26 int set; ///< Is set internally by the parser if the option was found.
27 ///< Don't use it at initialization of your opts, it will be
28 ///< overriden anyway!
29 } opt_t;
31 /** parses the string for the options specified in opt */
32 int subopt_parse( char const * const str, opt_t * opts );
35 /*------------------ arg specific types and declaration -------------------*/
36 typedef struct strarg_s
38 int len; ///< length of the string determined by the parser
39 char const * str; ///< pointer to position inside the parse string
40 } strarg_t;
43 int int_non_neg( int * i );
44 int int_pos( int * i );
46 int strargcmp(strarg_t *arg, char *str);
47 int strargcasecmp(strarg_t *arg, char *str);
49 #endif