<commit_before>/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "iohelp.h"
#include "exceptions.h"
#include "procimpl.h"

#include "jclglob.h"

/**
  * Create a System Process with the specified
  * environment and arguments 
  */
jlongArray JNICALL
Java_org_apache_harmony_luni_internal_process_SystemProcess_createImpl (JNIEnv * env, jclass clazz,
            jobject recv,
            jobjectArray arg1,
            jobjectArray arg2,
            jbyteArray dir)
{
  jbyteArray envString;
  jlongArray pVals = NULL;
  jlong npVals[4];
  char *envArray[256];
  char *command[256];
  int i, retVal;
  IDATA pHandle, inHandle, outHandle, errHandle;
  int envLength, commandLineLength, len;
  char *workingDir = NULL;
  PORT_ACCESS_FROM_ENV (env);

  /* validate sizes */
  commandLineLength = (*env)->GetArrayLength (env, arg1);
  envLength = (*env)->GetArrayLength (env, arg2);
  if (commandLineLength >= 255)
    {
      throwJavaIoIOException(env, "Too many arguments");
      return NULL;
    }
  if (envLength >= 255)
    {
      throwJavaIoIOException(env, "Too many environment arguments");
      return NULL;
    }

  memset (command, 0, sizeof (command));
  memset (envArray, 0, sizeof (envArray));

  /* Get the command string and arguments */
  /* convert java.lang.String into C char* */
  for (i = commandLineLength; --i >= 0;)
    {
      jbyteArray element = (*env)->GetObjectArrayElement (env, arg1, i);
      len = (*env)->GetArrayLength (env, element);
      command[i] = jclmem_allocate_memory (env, len + 1);
      if (command[i] == NULL)
        {
          throwNewOutOfMemoryError (env, "");
          goto failed;
        }
      (*env)->GetByteArrayRegion (env, element, 0, len, command[i]);
      command[i][len] = 0;
    }
  if (envLength)
    for (i = 0; i < envLength; i++)
      {
        envString = (*env)->GetObjectArrayElement (env, arg2, i);
        len = (*env)->GetArrayLength (env, envString);
        envArray[i] = jclmem_allocate_memory (env, len + 1);
        if (envArray[i] == NULL)
          {
            throwNewOutOfMemoryError (env, "");
            goto failed;
          }
        (*env)->GetByteArrayRegion (env, envString, 0, len, envArray[i]);
        envArray[i][len] = 0;
      }
  /* NULL terminate for UNIX (does work on windows too; in fact, it doesn't care) */
  command[commandLineLength] = NULL;
  envArray[envLength] = NULL;

  if (dir != NULL)
    {
      jsize dirLength = (*env)->GetArrayLength (env, dir);

      workingDir = jclmem_allocate_memory (env, dirLength + 1);
      if (workingDir)
        {
          (*env)->GetByteArrayRegion (env, dir, 0, dirLength,
            (jbyte *) workingDir);
          workingDir[dirLength] = '\0';
        }
    }

  /*
   *  now call execProgram.  Any non-zero return code 
   *  indicates some kind of failure
   */
   
  retVal = execProgram (env, recv,
      command, commandLineLength, envArray, envLength,
      workingDir, &pHandle, &inHandle, &outHandle,
      &errHandle);

  if (workingDir)
    {
      jclmem_free_memory (env, workingDir);
    }

  if (retVal)
    {
        char errMsg[256];
    	jclass exClass;

        /* Failed to exec program */
        
        switch(retVal) {
        case 1001 :
            sprintf(errMsg, "Unable to start program : %s", "fork() failed with errno = EOMEM");
            break;
        case 1002 : 
            sprintf(errMsg, "Unable to start program : %s", "fork() failed with errno = EAGAIN");
            break;
        default:
            sprintf(errMsg, "Unable to start program : %s", "unknown");
            break;
        }

        throwJavaIoIOException(env, errMsg);
        goto failed;
    }<commit_msg>Fixed another windows warning.<commit_after>/* Copyright 1998, 2005 The Apache Software Foundation or its licensors, as applicable
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "iohelp.h"
#include "exceptions.h"
#include "procimpl.h"

#include "jclglob.h"

/**
  * Create a System Process with the specified
  * environment and arguments 
  */
jlongArray JNICALL
Java_org_apache_harmony_luni_internal_process_SystemProcess_createImpl (JNIEnv * env, jclass clazz,
            jobject recv,
            jobjectArray arg1,
            jobjectArray arg2,
            jbyteArray dir)
{
  jbyteArray envString;
  jlongArray pVals = NULL;
  jlong npVals[4];
  char *envArray[256];
  char *command[256];
  int i, retVal;
  IDATA pHandle, inHandle, outHandle, errHandle;
  int envLength, commandLineLength, len;
  char *workingDir = NULL;
  PORT_ACCESS_FROM_ENV (env);

  /* validate sizes */
  commandLineLength = (*env)->GetArrayLength (env, arg1);
  envLength = (*env)->GetArrayLength (env, arg2);
  if (commandLineLength >= 255)
    {
      throwJavaIoIOException(env, "Too many arguments");
      return NULL;
    }
  if (envLength >= 255)
    {
      throwJavaIoIOException(env, "Too many environment arguments");
      return NULL;
    }

  memset (command, 0, sizeof (command));
  memset (envArray, 0, sizeof (envArray));

  /* Get the command string and arguments */
  /* convert java.lang.String into C char* */
  for (i = commandLineLength; --i >= 0;)
    {
      jbyteArray element = (*env)->GetObjectArrayElement (env, arg1, i);
      len = (*env)->GetArrayLength (env, element);
      command[i] = jclmem_allocate_memory (env, len + 1);
      if (command[i] == NULL)
        {
          throwNewOutOfMemoryError (env, "");
          goto failed;
        }
      (*env)->GetByteArrayRegion (env, element, 0, len, command[i]);
      command[i][len] = 0;
    }
  if (envLength)
    for (i = 0; i < envLength; i++)
      {
        envString = (*env)->GetObjectArrayElement (env, arg2, i);
        len = (*env)->GetArrayLength (env, envString);
        envArray[i] = jclmem_allocate_memory (env, len + 1);
        if (envArray[i] == NULL)
          {
            throwNewOutOfMemoryError (env, "");
            goto failed;
          }
        (*env)->GetByteArrayRegion (env, envString, 0, len, envArray[i]);
        envArray[i][len] = 0;
      }
  /* NULL terminate for UNIX (does work on windows too; in fact, it doesn't care) */
  command[commandLineLength] = NULL;
  envArray[envLength] = NULL;

  if (dir != NULL)
    {
      jsize dirLength = (*env)->GetArrayLength (env, dir);

      workingDir = jclmem_allocate_memory (env, dirLength + 1);
      if (workingDir)
        {
          (*env)->GetByteArrayRegion (env, dir, 0, dirLength,
            (jbyte *) workingDir);
          workingDir[dirLength] = '\0';
        }
    }

  /*
   *  now call execProgram.  Any non-zero return code 
   *  indicates some kind of failure
   */
   
  retVal = execProgram (env, recv,
      command, commandLineLength, envArray, envLength,
      workingDir, &pHandle, &inHandle, &outHandle,
      &errHandle);

  if (workingDir)
    {
      jclmem_free_memory (env, workingDir);
    }

  if (retVal)
    {
        char errMsg[256];

        /* Failed to exec program */
        
        switch(retVal) {
        case 1001 :
            sprintf(errMsg, "Unable to start program : %s", "fork() failed with errno = EOMEM");
            break;
        case 1002 : 
            sprintf(errMsg, "Unable to start program : %s", "fork() failed with errno = EAGAIN");
            break;
        default:
            sprintf(errMsg, "Unable to start program : %s", "unknown");
            break;
        }

        throwJavaIoIOException(env, errMsg);
        goto failed;
    }
{'fraction_non_alphanumeric': 0.11579683131407269, 'fraction_numerical': 0.012814538676607642, 'mean_word_length': 2.5651993355481726, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '670129', 'n_tokens_mistral': 2710, 'n_tokens_neox': 2588, 'n_words': 797}