Browse Source

Return nil in function_read_file if not found

As with `function_load`, this must return nil for the rest to work.
(Otherwise noone can detect if the file is not present or empty.)
Lucas Stadler 9 years ago
parent
commit
f4911b3598
1 changed files with 8 additions and 6 deletions
  1. 8 6
      c/ton/main.c

+ 8 - 6
c/ton/main.c

94
		snprintf(full_path, 150, "%s/%s", "out", path);
94
		snprintf(full_path, 150, "%s/%s", "out", path);
95
95
96
		char *contents = get_contents(full_path);
96
		char *contents = get_contents(full_path);
97
		JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
98
		free(contents);
97
		if (contents != NULL) {
98
			JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
99
			free(contents);
99
100
100
		JSValueRef res[2];
101
		res[0] = JSValueMakeString(ctx, contents_str);
102
		res[1] = JSValueMakeNumber(ctx, 0);
103
		return JSObjectMakeArray(ctx, 2, res, NULL);
101
			JSValueRef res[2];
102
			res[0] = JSValueMakeString(ctx, contents_str);
103
			res[1] = JSValueMakeNumber(ctx, 0);
104
			return JSObjectMakeArray(ctx, 2, res, NULL);
105
		}
104
	}
106
	}
105
107
106
	return JSValueMakeNull(ctx);
108
	return JSValueMakeNull(ctx);