Fix the return of get_ticket
Showing
1 changed file
with
10 additions
and
13 deletions
... | @@ -253,7 +253,7 @@ static int | ... | @@ -253,7 +253,7 @@ static int |
253 | get_ticket (mu_url_t url, const char *user, const char *filename, | 253 | get_ticket (mu_url_t url, const char *user, const char *filename, |
254 | mu_url_t * ticket) | 254 | mu_url_t * ticket) |
255 | { | 255 | { |
256 | int err = 0; | 256 | int status = MU_ERR_NOENT; |
257 | FILE *fp = NULL; | 257 | FILE *fp = NULL; |
258 | size_t buflen = 128; | 258 | size_t buflen = 128; |
259 | char *buf = NULL; | 259 | char *buf = NULL; |
... | @@ -279,7 +279,8 @@ get_ticket (mu_url_t url, const char *user, const char *filename, | ... | @@ -279,7 +279,8 @@ get_ticket (mu_url_t url, const char *user, const char *filename, |
279 | char *ptr = buf; | 279 | char *ptr = buf; |
280 | int len = 0; | 280 | int len = 0; |
281 | mu_url_t u = NULL; | 281 | mu_url_t u = NULL; |
282 | 282 | int err; | |
283 | |||
283 | /* fgets: | 284 | /* fgets: |
284 | 1) return true, read some data | 285 | 1) return true, read some data |
285 | 1a) read a newline, so break | 286 | 1a) read a newline, so break |
... | @@ -310,26 +311,21 @@ get_ticket (mu_url_t url, const char *user, const char *filename, | ... | @@ -310,26 +311,21 @@ get_ticket (mu_url_t url, const char *user, const char *filename, |
310 | 311 | ||
311 | /* Truncate a trailing newline. */ | 312 | /* Truncate a trailing newline. */ |
312 | if (len && buf[len - 1] == '\n') | 313 | if (len && buf[len - 1] == '\n') |
313 | buf[len - 1] = 0; | 314 | buf[--len] = 0; |
314 | 315 | ||
315 | /* Skip leading spaces. */ | 316 | /* Skip leading spaces. */ |
316 | ptr = buf; | 317 | ptr = buf; |
317 | while (isspace (*ptr)) | 318 | while (isspace (*ptr)) |
318 | ptr++; | 319 | ptr++; |
319 | 320 | ||
320 | /* Skip comments. */ | 321 | /* Skip empty lines and comments. */ |
321 | if (*ptr == '#') | 322 | if (!*ptr || *ptr == '#') |
322 | continue; | ||
323 | |||
324 | /* Skip empty lines. */ | ||
325 | if ((len = strlen (ptr)) == 0) | ||
326 | continue; | 323 | continue; |
327 | 324 | ||
328 | if ((err = mu_url_create (&u, ptr)) != 0) | 325 | if ((err = mu_url_create (&u, ptr)) != 0) |
329 | { | 326 | { |
330 | free (buf); | 327 | status = err; |
331 | fclose (fp); | 328 | break; |
332 | return err; | ||
333 | } | 329 | } |
334 | if ((err = mu_url_parse (u)) != 0) | 330 | if ((err = mu_url_parse (u)) != 0) |
335 | { | 331 | { |
... | @@ -361,13 +357,14 @@ get_ticket (mu_url_t url, const char *user, const char *filename, | ... | @@ -361,13 +357,14 @@ get_ticket (mu_url_t url, const char *user, const char *filename, |
361 | /* Looks like a match! */ | 357 | /* Looks like a match! */ |
362 | *ticket = u; | 358 | *ticket = u; |
363 | u = NULL; | 359 | u = NULL; |
360 | status = 0; | ||
364 | break; | 361 | break; |
365 | } | 362 | } |
366 | 363 | ||
367 | fclose (fp); | 364 | fclose (fp); |
368 | free (buf); | 365 | free (buf); |
369 | 366 | ||
370 | return 0; | 367 | return status; |
371 | } | 368 | } |
372 | 369 | ||
373 | static int | 370 | static int | ... | ... |
-
Please register or sign in to post a comment