/** * Handle a call to closedir() made by JavaScript. * * closedir expects 1 parameter: * 0: The index of the directory (which is mapped to a DIR*) * on success, closedir returns a result in |output| separated by \1: * 0: "closedir" * 1: the name of the directory * on failure, closedir 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 HandleClosedir(int num_params, char** params, char** output) { #if defined(WIN32) *output = PrintfToNewString("Error: Win32 does not support closedir."); return 1; #else DIR* dir; int dir_index; const char* dir_index_string; int result; if (num_params != 1) { *output = PrintfToNewString("Error: closedir takes 1 parameters."); return 1; } dir_index_string = params[0]; dir = GetDirFromIndexString(dir_index_string, &dir_index); if (!dir) { *output = PrintfToNewString("Error: Unknown dir handle %s.", dir_index_string); return 2; } result = closedir(dir); if (result) { *output = PrintfToNewString("Error: closedir returned error %d.", result); return 3; } RemoveDirFromMap(dir_index); *output = PrintfToNewString("closedir\1%s", dir_index_string); return 0; #endif }
/** * Handle a call to closedir() made by JavaScript. * * closedir expects 1 parameter: * 0: The index of the directory (which is mapped to a DIR*) * on success, closedir returns a result in |output|: * 0: "closedir" * 1: the name of the directory * on failure, closedir returns an error string in |out_error|. */ int HandleClosedir(struct PP_Var params, struct PP_Var* output, const char** out_error) { #if defined(WIN32) *out_error = PrintfToNewString("Win32 does not support closedir"); return 1; #else CHECK_PARAM_COUNT(closedir, 1); PARAM_DIR(0, dir); int result = closedir(dir); if (result) { *out_error = PrintfToNewString("closedir returned error %d", result); return 1; } RemoveDirFromMap(dir_index); CREATE_RESPONSE(closedir); RESPONSE_INT(dir_index); return 0; #endif }