/** * Handle a call to fclose() made by JavaScript. * * fclose expects 1 parameter: * 0: The index of the file (which is mapped to a FILE*) * on success, fclose returns a result in |output| separated by \1: * 0: "fclose" * 1: the file index * on failure, fclose returns an error string in |output|. * * @param[in] num_params The number of params in |params|. * @param[in] params An array of strings, parameters to this function. * @param[out] output A string to write informational function output to. * @return An errorcode; 0 means success, anything else is a failure. */ int HandleFclose(int num_params, char** params, char** output) { FILE* file; int file_index; const char* file_index_string; int result; if (num_params != 1) { *output = PrintfToNewString("Error: fclose takes 1 parameters."); return 1; } file_index_string = params[0]; file = GetFileFromIndexString(file_index_string, &file_index); if (!file) { *output = PrintfToNewString("Error: Unknown file handle %s.", file_index_string); return 2; } result = fclose(file); if (result) { *output = PrintfToNewString("Error: fclose returned error %d.", result); return 3; } RemoveFileFromMap(file_index); *output = PrintfToNewString("fclose\1%s", file_index_string); return 0; }
/** * Handle a call to fclose() made by JavaScript. * * fclose expects 1 parameter: * 0: The index of the file (which is mapped to a FILE*) * on success, fclose returns a result in |output|: * 0: "fclose" * 1: the file index * on failure, fclose returns an error string in |out_error|. */ int HandleFclose(struct PP_Var params, struct PP_Var* output, const char** out_error) { CHECK_PARAM_COUNT(fclose, 1); PARAM_FILE(0, file); int result = fclose(file); if (result) { *out_error = PrintfToNewString("fclose returned error %d", result); return 1; } RemoveFileFromMap(file_index); CREATE_RESPONSE(fclose); RESPONSE_INT(file_index); return 0; }