Ignore:
Timestamp:
Apr 11, 2015, 10:51:59 AM (6 years ago)
Author:
mikedld
Message:

#5908: Check for tr_loadFile return value instead of errno in tr_variantFromFile

Seems like there could be a defect in uClibc making errno not
thread-local. Don't rely on errno value but check function return value
instead which is a better failure indicator.

Return errors from tr_loadFile and tr_variantFromFile via tr_error.
Fix tr_sessionLoadSettings to not fail on Windows if settings.json
does not exist.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/variant.c

    r14428 r14491  
    12191219***/
    12201220
    1221 int
     1221bool
    12221222tr_variantFromFile (tr_variant      * setme,
    12231223                    tr_variant_fmt    fmt,
    1224                     const char      * filename)
    1225 {
    1226   int err;
     1224                    const char      * filename,
     1225                    tr_error       ** error)
     1226{
     1227  bool ret = false;
     1228  uint8_t * buf;
    12271229  size_t buflen;
    1228   uint8_t * buf;
    1229   const int old_errno = errno;
    1230 
    1231   errno = 0;
    1232   buf = tr_loadFile (filename, &buflen);
    1233 
    1234   if (errno)
    1235     err = errno;
    1236   else
    1237     err = tr_variantFromBuf (setme, fmt, buf, buflen, filename, NULL);
    1238 
    1239   tr_free (buf);
    1240   errno = old_errno;
    1241   return err;
     1230
     1231  buf = tr_loadFile (filename, &buflen, error);
     1232  if (buf != NULL)
     1233    {
     1234      if (tr_variantFromBuf (setme, fmt, buf, buflen, filename, NULL) == 0)
     1235        ret = true;
     1236      else
     1237        tr_error_set_literal (error, 0, _("Unable to parse file content"));
     1238
     1239      tr_free (buf);
     1240    }
     1241
     1242  return ret;
    12421243}
    12431244
Note: See TracChangeset for help on using the changeset viewer.