Mercurial > hg > dmlib
changeset 1523:1750498bc746
Fix a warning in dmWriteDataFile().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 11 May 2018 23:34:48 +0300 |
parents | 0d1cf72fb732 |
children | 532c3ceaec1a |
files | src/dmfile.c |
diffstat | 1 files changed, 10 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/dmfile.c Fri May 11 23:26:24 2018 +0300 +++ b/src/dmfile.c Fri May 11 23:34:48 2018 +0300 @@ -60,23 +60,22 @@ int dmWriteDataFile(FILE *fh, const char *filename, const Uint8 *buf, const size_t bufSize) { - int res; + int res = DMERR_OK; - if (fh == NULL && filename != NULL) + if (fh == NULL && filename != NULL && + (fh = fopen(filename, "wb")) == NULL) { - if ((fh = fopen(filename, "wb")) == NULL) - { - res = dmGetErrno(); - return dmError(res, - "Could not open '%s' for writing: %s.\n", - filename, dmErrorStr(res)); - } + res = dmGetErrno(); + return dmError(res, + "Could not open '%s' for writing: %s.\n", + filename, dmErrorStr(res)); } if (fh == NULL) { - return dmError(DMERR_NULLPTR, + res = dmError(DMERR_NULLPTR, "NULL filename and stream pointers.\n"); + goto error; } if (fwrite(buf, bufSize, 1, fh) != 1) @@ -87,6 +86,7 @@ filename, dmErrorStr(res)); } +error: if (fh != NULL) fclose(fh);