Mercurial > mplayer.hg
comparison parser-cfg.c @ 34172:5761a9a31bcb
Sanitize include option behaviour.
If the file could not be opened/read/processed, print a message and
quit instead of completely silently ignoring it.
author | reimar |
---|---|
date | Tue, 25 Oct 2011 20:45:09 +0000 |
parents | 55abe5125482 |
children | 2d529504ec2d |
comparison
equal
deleted
inserted
replaced
34171:cca4f430b0f4 | 34172:5761a9a31bcb |
---|---|
48 static int recursion_depth = 0; | 48 static int recursion_depth = 0; |
49 | 49 |
50 /// Setup the \ref Config from a config file. | 50 /// Setup the \ref Config from a config file. |
51 /** \param config The config object. | 51 /** \param config The config object. |
52 * \param conffile Path to the config file. | 52 * \param conffile Path to the config file. |
53 * \param silent print message when failing to open file only at verbose level | |
53 * \return 1 on sucess, -1 on error. | 54 * \return 1 on sucess, -1 on error. |
54 */ | 55 */ |
55 int m_config_parse_config_file(m_config_t* config, const char *conffile) | 56 int m_config_parse_config_file(m_config_t* config, const char *conffile, int silent) |
56 { | 57 { |
57 #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num) | 58 #define PRINT_LINENUM mp_msg(MSGT_CFGPARSER,MSGL_V,"%s(%d): ", conffile, line_num) |
58 #define MAX_LINE_LEN 10000 | 59 #define MAX_LINE_LEN 10000 |
59 #define MAX_OPT_LEN 1000 | 60 #define MAX_OPT_LEN 1000 |
60 #define MAX_PARAM_LEN 1500 | 61 #define MAX_PARAM_LEN 1500 |
94 } else | 95 } else |
95 | 96 |
96 mp_msg(MSGT_CFGPARSER,MSGL_V,"\n"); | 97 mp_msg(MSGT_CFGPARSER,MSGL_V,"\n"); |
97 | 98 |
98 if ((fp = fopen(conffile, "r")) == NULL) { | 99 if ((fp = fopen(conffile, "r")) == NULL) { |
99 mp_msg(MSGT_CFGPARSER,MSGL_V,": %s\n", strerror(errno)); | 100 mp_msg(MSGT_CFGPARSER,silent?MSGL_V:MSGL_ERR,"Failed to read %s: %s\n", conffile, strerror(errno)); |
100 free(line); | 101 free(line); |
101 ret = 0; | 102 ret = silent ? 0 : -1; |
102 goto out; | 103 goto out; |
103 } | 104 } |
104 | 105 |
105 while (fgets(line, MAX_LINE_LEN, fp)) { | 106 while (fgets(line, MAX_LINE_LEN, fp)) { |
106 if (errors >= 16) { | 107 if (errors >= 16) { |