Exemple #1
0
int config_parse_cmd(server *srv, config_t *context, const char *cmd) {
    tokenizer_t t;
    int ret;
    buffer *source;
    buffer *out;
    char *oldpwd;

    if (NULL == (oldpwd = getCWD())) {
        log_error_write(srv, __FILE__, __LINE__, "s",
                        "cannot get cwd", strerror(errno));
        return -1;
    }

    source = buffer_init_string(cmd);
    out = buffer_init();

    if (!buffer_is_empty(context->basedir)) {
        chdir(context->basedir->ptr);
    }

    if (0 != proc_open_buffer(cmd, NULL, out, NULL)) {
        log_error_write(srv, __FILE__, __LINE__, "sbss",
                        "opening", source, "failed:", strerror(errno));
        ret = -1;
    } else {
        tokenizer_init(&t, source, out->ptr, out->used);
        ret = config_parse(srv, context, &t);
    }

    buffer_free(source);
    buffer_free(out);
    chdir(oldpwd);
    free(oldpwd);
    return ret;
}
SWIGEXPORT jstring JNICALL Java_org_scilab_modules_commons_CommonFileUtilsJNI_getCWD(JNIEnv *jenv, jclass jcls) {
  jstring jresult = 0 ;
  char *result = 0 ;
  
  (void)jenv;
  (void)jcls;
  result = (char *)getCWD();
  {
    if (result != NULL)
    {
      jresult = (*jenv)->NewStringUTF(jenv, (const char *)result);
      FREE(result);
      result = NULL;
    }       
  }
  return jresult;
}