Skip to content

Commit

Permalink
Merge pull request #454 from zowe/v2.x/bugfix/xplatform
Browse files Browse the repository at this point in the history
xplatform.loadFileUTF8 returns error for wrong file
  • Loading branch information
JoeNemo authored May 22, 2024
2 parents 9bd6366 + 8b37e05 commit 292082a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Zowe Common C Changelog

## `2.17.0`
- Fixed `xplatform.loadFileUTF8` when trying to open nonexistent file (#454)

## `2.16.0`
- No yaml value converted to null (#442)
- Added `zos.getZosVersion()` and `zos.getEsm()` calls for configmgr QJS (#429)
Expand Down
7 changes: 3 additions & 4 deletions c/embeddedjs.c
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,6 @@ uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename);
/* (filename, ccsid) ccsid -1 implies guess best for platform, 0 implies don't translate */
static JSValue xplatformLoadFileUTF8(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv){
size_t size;
size_t length;
char *buf;

Expand All @@ -626,7 +625,9 @@ static JSValue xplatformLoadFileUTF8(JSContext *ctx, JSValueConst this_val,
JS_ToInt32(ctx, &sourceCCSID, argv[1]);

buf = (char*)js_load_file(ctx, &length, filename);

if (!buf) {
return JS_EXCEPTION;
}
if (sourceCCSID < 0){
char *nativeBuffer = safeMalloc(length+1,"xplatformStringFromBytes");
memcpy(nativeBuffer,buf,length);
Expand Down Expand Up @@ -678,7 +679,6 @@ static int appendToFile(char *filename, const char *data, int length) {
/* (filename, ccsid) ccsid -1 implies guess best for platform, 0 implies don't translate */
static JSValue xplatformAppendFileUTF8(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv){
size_t size;
size_t length;

NATIVE_STR(filename,nativeFilename,0);
Expand Down Expand Up @@ -718,7 +718,6 @@ static JSValue xplatformAppendFileUTF8(JSContext *ctx, JSValueConst this_val,
/* (filename, ccsid) ccsid -1 implies guess best for platform, 0 implies don't translate */
static JSValue xplatformStoreFileUTF8(JSContext *ctx, JSValueConst this_val,
int argc, JSValueConst *argv){
size_t size;
size_t length;

NATIVE_STR(filename,nativeFilename,0);
Expand Down

0 comments on commit 292082a

Please sign in to comment.