Просмотр исходного кода

Return nil in function_load if file is not present

The other file-opening functions might have similar behaviour, and still
need to be checked.
Lucas Stadler лет назад: 9
Родитель
Сommit
5cb9cba628
1 измененных файлов с 9 добавлено и 3 удалено
  1. 9 3
      c/ton/main.c

+ 9 - 3
c/ton/main.c

117
		// TODO: should not load from here?
117
		// TODO: should not load from here?
118
		snprintf(full_path, 150, "%s/%s", "out", path);
118
		snprintf(full_path, 150, "%s/%s", "out", path);
119
119
120
		JSValueRef contents_val = NULL;
121
120
		char *contents = get_contents(full_path);
122
		char *contents = get_contents(full_path);
121
		JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
122
		free(contents);
123
		if (contents != NULL) {
124
			JSStringRef contents_str = JSStringCreateWithUTF8CString(contents);
125
			free(contents);
126
127
			contents_val = JSValueMakeString(ctx, contents_str);
128
		}
123
129
124
		JSValueRef res[2];
130
		JSValueRef res[2];
125
		res[0] = JSValueMakeString(ctx, contents_str);
131
		res[0] = contents_val;
126
		res[1] = JSValueMakeNumber(ctx, 0);
132
		res[1] = JSValueMakeNumber(ctx, 0);
127
		return JSObjectMakeArray(ctx, 2, res, NULL);
133
		return JSObjectMakeArray(ctx, 2, res, NULL);
128
	}
134
	}