Exemple #1
0
/**
 * Handle a call to opendir() made by JavaScript.
 *
 * opendir expects 1 parameter:
 *   0: The name of the directory
 * on success, opendir returns a result in |output| separated by \1:
 *   0: "opendir"
 *   1: the directory name
 *   2: the index of the directory
 * on failure, opendir 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 HandleOpendir(int num_params, char** params, char** output) {
#if defined(WIN32)
  *output = PrintfToNewString("Error: Win32 does not support opendir.");
  return 1;
#else
  DIR* dir;
  int dir_index;
  const char* dirname;

  if (num_params != 1) {
    *output = PrintfToNewString("Error: opendir takes 1 parameter.");
    return 1;
  }

  dirname = params[0];

  dir = opendir(dirname);
  if (!dir) {
    *output = PrintfToNewString("Error: opendir returned a NULL DIR*.");
    return 2;
  }

  dir_index = AddDirToMap(dir);
  if (dir_index == -1) {
    *output = PrintfToNewString(
        "Error: Example only allows %d open dir handles.", MAX_OPEN_DIRS);
    return 3;
  }

  *output = PrintfToNewString("opendir\1%s\1%d", dirname, dir_index);
  return 0;
#endif
}
Exemple #2
0
/**
 * Handle a call to opendir() made by JavaScript.
 *
 * opendir expects 1 parameter:
 *   0: The name of the directory
 * on success, opendir returns a result in |output|:
 *   0: "opendir"
 *   1: the directory name
 *   2: the index of the directory
 * on failure, opendir returns an error string in |out_error|.
 */
int HandleOpendir(struct PP_Var params,
                  struct PP_Var* output,
                  const char** out_error) {
#if defined(WIN32)
  *out_error = PrintfToNewString("Win32 does not support opendir");
  return 1;
#else
  CHECK_PARAM_COUNT(opendir, 1);
  PARAM_STRING(0, dirname);

  DIR* dir = opendir(dirname);

  if (!dir) {
    *out_error = PrintfToNewString("opendir returned a NULL DIR*");
    return 1;
  }

  int dir_index = AddDirToMap(dir);
  if (dir_index == -1) {
    *out_error = PrintfToNewString("Example only allows %d open dir handles",
                                   MAX_OPEN_DIRS);
    return 1;
  }

  CREATE_RESPONSE(opendir);
  RESPONSE_STRING(dirname);
  RESPONSE_INT(dir_index);
  return 0;
#endif
}