<commit_before>/*
  Copyright 2010 University Corporation for Atmospheric
  Research/Unidata. See COPYRIGHT file for more info.

  This file defines the file create and open functions.
*/

#include "ncdispatch.h"

static int nc_initialized = 0;

static int
NC_check_file_type(const char *path, int use_parallel, void *mpi_info,
                   int *cdf, int *hdf)
{
   char magic[MAGIC_NUMBER_LEN];

   *hdf = 0; *cdf = 0;

   /* Get the 4-byte magic from the beginning of the file. Don't use posix
    * for parallel, use the MPI functions instead. */
#ifdef USE_PARALLEL_MPIO
   if (use_parallel)
   {
      MPI_File fh;
      MPI_Status status;
      int retval;
      MPI_Comm comm = 0;
      MPI_Info info = 0;

      if(mpi_info != NULL) {
      comm = ((NC_MPI_INFO*)mpi_info)->comm;
      info = ((NC_MPI_INFO*)mpi_info)->info;
      }
      if((retval = MPI_File_open(comm, (char *)path, MPI_MODE_RDONLY,info,
                                 &fh)) != MPI_SUCCESS)
        return NC_EPARINIT;
      if((retval = MPI_File_read(fh, magic, MAGIC_NUMBER_LEN, MPI_CHAR,
                                 &status)) != MPI_SUCCESS)
        return NC_EPARINIT;
      if((retval = MPI_File_close(&fh)) != MPI_SUCCESS)
        return NC_EPARINIT;
   } else
#endif /* USE_PARALLEL */
   {
      FILE *fp;
      int i;

      if (!(fp = fopen(path, "r")))
        return errno;
      i = fread(magic, MAGIC_NUMBER_LEN, 1, fp);
      fclose(fp);
      if(i != 1)
        return errno;
   }

   /* Ignore the first byte for HDF */
   if(magic[1] == 'H' && magic[2] == 'D' && magic[3] == 'F')
      *hdf = 5;
   else if(magic[0] == '\016' && magic[1] == '\003'
           && magic[2] == '\023' && magic[3] == '\001')
      *hdf = 4;
   else if(magic[0] == 'C' && magic[1] == 'D' && magic[2] == 'F')
   {
      if(magic[3] == '\001')
        *cdf = 1;
      else if(magic[3] == '\002')
        *cdf = 2;
   }

   return NC_NOERR;
}<commit_msg>Handle case of null filename.<commit_after>/*
  Copyright 2010 University Corporation for Atmospheric
  Research/Unidata. See COPYRIGHT file for more info.

  This file defines the file create and open functions.
*/

#include "ncdispatch.h"

static int nc_initialized = 0;

static int
NC_check_file_type(const char *path, int use_parallel, void *mpi_info,
                   int *cdf, int *hdf)
{
   char magic[MAGIC_NUMBER_LEN];

   *hdf = 0; *cdf = 0;

   /* Get the 4-byte magic from the beginning of the file. Don't use posix
    * for parallel, use the MPI functions instead. */
#ifdef USE_PARALLEL_MPIO
   if (use_parallel)
   {
      MPI_File fh;
      MPI_Status status;
      int retval;
      MPI_Comm comm = 0;
      MPI_Info info = 0;

      if(mpi_info != NULL) {
      comm = ((NC_MPI_INFO*)mpi_info)->comm;
      info = ((NC_MPI_INFO*)mpi_info)->info;
      }
      if((retval = MPI_File_open(comm, (char *)path, MPI_MODE_RDONLY,info,
                                 &fh)) != MPI_SUCCESS)
        return NC_EPARINIT;
      if((retval = MPI_File_read(fh, magic, MAGIC_NUMBER_LEN, MPI_CHAR,
                                 &status)) != MPI_SUCCESS)
        return NC_EPARINIT;
      if((retval = MPI_File_close(&fh)) != MPI_SUCCESS)
        return NC_EPARINIT;
   } else
#endif /* USE_PARALLEL */
   {
      FILE *fp;
      int i;

      if (!path)
        return 0;
      if (!(fp = fopen(path, "r")))
        return errno;
      i = fread(magic, MAGIC_NUMBER_LEN, 1, fp);
      fclose(fp);
      if(i != 1)
        return errno;
   }

   /* Ignore the first byte for HDF */
   if(magic[1] == 'H' && magic[2] == 'D' && magic[3] == 'F')
      *hdf = 5;
   else if(magic[0] == '\016' && magic[1] == '\003'
           && magic[2] == '\023' && magic[3] == '\001')
      *hdf = 4;
   else if(magic[0] == 'C' && magic[1] == 'D' && magic[2] == 'F')
   {
      if(magic[3] == '\001')
        *cdf = 1;
      else if(magic[3] == '\002')
        *cdf = 2;
   }

   return NC_NOERR;
}
{'fraction_non_alphanumeric': 0.14693149987267634, 'fraction_numerical': 0.023682200152788387, 'mean_word_length': 2.1626409017713364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1351717', 'n_tokens_mistral': 1525, 'n_tokens_neox': 1402, 'n_words': 366}