<commit_before>/* write a formatted string into a string buffer. allocate/free memory as needed */
int d_sprintf(char **str, char *format, ...) {
  size_t newSize;
  char *newStr = NULL;
  va_list args;

  #ifndef HAS_VSNPRINTF
    FILE *pFile;
  #endif

  #ifdef HAS_KERNEL_SWI
    int origOutput;
  #endif

  MAC_YIELD

  /* Check sanity of inputs */
  if(str == NULL || format == NULL) {
    return FALSE;
  }

  #if defined(HAS_VSNPRINTF)
    /* get the space needed for the new string */
    va_start(args, format);
    newSize = (size_t)(vsnprintf(NULL, 0, format, args)); /* plus '\0' */
    va_end(args);
  #elif defined(HAS_KERNEL_SWI)
    /* disable output on stdout so that we can get the space needed for the new string without outputting text. */
    /* turn off stdout printing to simulate printing to /dev/null */
    origOutput = _kernel_osbyte(236, 0, 0xFF);
    _kernel_osbyte(3, 14, 0);

    /* get the space needed for the new string */
    va_start(args, format);
    newSize = (size_t)(vfprintf(stdout, format, args)); /* plus '\0' */
    va_end(args);

    /* turn on stdout printing again */
    _kernel_osbyte(3, origOutput, 0);
  #else
    /* open /dev/null so that we can get the space needed for the new string. */
    if((pFile = fopen(devNull, fopen_write)) == NULL) {
      return FALSE;
    }

    /* get the space needed for the new string */
    va_start(args, format);
    newSize = (size_t)(vfprintf(pFile, format, args)); /* plus '\0' */
    va_end(args);

    /* close the file. We don't need to look at the return code as we were writing to /dev/null */
    fclose(pFile);
  #endif

  /* Create a new block of memory with the correct size rather than using realloc */
  /* as any old values could overlap with the format string. quit on failure */
  if((newStr = (char*)malloc(newSize+1)) == NULL) {
    return FALSE;
  }

  /* do the string formatting for real. vsnprintf doesn't seem to be available on Lattice C */
  va_start(args, format);
  vsprintf(newStr, format, args);
  va_end(args);

  /* ensure null termination of the string */
  newStr[newSize] = '\0';

  /* free the old contents of the output if present */
  free(*str);

  /* set the output pointer to the new pointer location */
  *str = newStr;

  /* everything occurred successfully */
  return newSize;
}
<commit_msg>fixed incorrect osbyte number so as to disable spooling<commit_after>/* write a formatted string into a string buffer. allocate/free memory as needed */
int d_sprintf(char **str, char *format, ...) {
  size_t newSize;
  char *newStr = NULL;
  va_list args;

  #ifndef HAS_VSNPRINTF
    FILE *pFile;
  #endif

  #ifdef HAS_KERNEL_SWI
    int origOutput;
  #endif

  MAC_YIELD

  /* Check sanity of inputs */
  if(str == NULL || format == NULL) {
    return FALSE;
  }

  #if defined(HAS_VSNPRINTF)
    /* get the space needed for the new string */
    va_start(args, format);
    newSize = (size_t)(vsnprintf(NULL, 0, format, args)); /* plus '\0' */
    va_end(args);
  #elif defined(HAS_KERNEL_SWI)
    /* disable output on stdout so that we can get the space needed for the new string without outputting text. */
    /* turn off stdout printing to simulate printing to /dev/null */
    origOutput = _kernel_osbyte(236, 0, 0xFF);
    _kernel_osbyte(3, 22, 0);

    /* get the space needed for the new string */
    va_start(args, format);
    newSize = (size_t)(vfprintf(stdout, format, args)); /* plus '\0' */
    va_end(args);

    /* turn on stdout printing again */
    _kernel_osbyte(3, origOutput, 0);
  #else
    /* open /dev/null so that we can get the space needed for the new string. */
    if((pFile = fopen(devNull, fopen_write)) == NULL) {
      return FALSE;
    }

    /* get the space needed for the new string */
    va_start(args, format);
    newSize = (size_t)(vfprintf(pFile, format, args)); /* plus '\0' */
    va_end(args);

    /* close the file. We don't need to look at the return code as we were writing to /dev/null */
    fclose(pFile);
  #endif

  /* Create a new block of memory with the correct size rather than using realloc */
  /* as any old values could overlap with the format string. quit on failure */
  if((newStr = (char*)malloc(newSize+1)) == NULL) {
    return FALSE;
  }

  /* do the string formatting for real. vsnprintf doesn't seem to be available on Lattice C */
  va_start(args, format);
  vsprintf(newStr, format, args);
  va_end(args);

  /* ensure null termination of the string */
  newStr[newSize] = '\0';

  /* free the old contents of the output if present */
  free(*str);

  /* set the output pointer to the new pointer location */
  *str = newStr;

  /* everything occurred successfully */
  return newSize;
}

{'fraction_non_alphanumeric': 0.11797274275979557, 'fraction_numerical': 0.007240204429301534, 'mean_word_length': 2.977138018628281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '303726', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1475, 'n_words': 554}