static int _testRemoveDirectory(void) {
  CharString tempDir = _fileUtilitiesMakeTempDir();
  assert(_fileExists(tempDir->data));
  assert(removeDirectory(tempDir));
  assertFalse(_fileExists(tempDir->data));
  freeCharString(tempDir);
  return 0;
}
const char* HK_CALL hkAssetManagementUtil::getFilePath( hkStringBuf& filename, hkStructureLayout::LayoutRules rules )
{
#ifdef NEED_PLATFORM_SPECIFIC_EXTENSION
	if (! _fileExists( filename ) )
	{
		// Try platform extension
		int extn = filename.lastIndexOf('.');
		if (extn != -1)
		{
			hkStringBuf fe; getFileEnding(fe, rules); 
			filename.insert(extn, fe);
		}
	}
#endif
	
#ifdef HK_DEBUG
	{
		int a0 = filename.lastIndexOf('\\');
		int a1 = filename.lastIndexOf('/');
		int aLen = filename.getLength() - 1; // last index
		int mD0 = a0 >= 0? a0 : 0;
		int mD1 = a1 >= 0? a1 : 0;
		int maxSlash = mD0 > mD1? mD0 : mD1;
		if ( (aLen - maxSlash) > 42 )
		{
			hkStringBuf w;
			w.printf("Your file name [%s] is longer than 42 characters. May have issues on some consoles (like Xbox360).", filename.cString() );
			HK_WARN(0x04324, w.cString() );
		}
	}
#endif
	return filename;
}
static int _testFileExists(void) {
  FILE *fp = fopen(TEST_FILENAME, "w");
  assert(fp != NULL);
  fclose(fp);
  assert(_fileExists(TEST_FILENAME));
  unlink(TEST_FILENAME);
  return 0;
}
////////////////////////////////////////////////////////////////////////////////
//   Writes message to file.
//   Implementation of this function is platform specific
//
//   Note: The current implementation writes the message to the defined file.
//         Will have to be enhanced to support synchronous write operations to
//         the same file.
////////////////////////////////////////////////////////////////////////////////
void TraceFileHandler::handleMessage(
    const char* message,
    Uint32,
    const char* fmt,
    va_list argList)
{
    Uint32 retCode;
    

    if (_configHasChanged)
    {
        _reConfigure();
    }

    if (!_fileHandle)
    {
        // The trace file is not open, which means an earlier fopen() was
        // unsuccessful.  Stop now to avoid logging duplicate error messages.
        return;
    }
  
    AutoMutex writeLock(writeMutex);

    if(!_fileExists(_fileName))
    {
        return;
    }       

        //Move to the End of File
        fseek(_fileHandle,0,SEEK_SET);

        // Write message to file
        fprintf(_fileHandle,"%s", message);
        vfprintf(_fileHandle,fmt,argList);
        retCode = fprintf(_fileHandle,"\n");

        if (retCode < 0)
        {
            // Unable to write message to file
            // Log message
            MessageLoaderParms parm(
                "Common.TraceFileHandlerWindows.UNABLE_TO_WRITE_TRACE_TO_FILE",
                "Unable to write trace message to File $0",
                _fileName);
            _logError(TRCFH_UNABLE_TO_WRITE_TRACE_TO_FILE,parm);
        }
        else
        {
            fflush(_fileHandle);
            // trace message successful written, reset error log messages
            // thus allow writing of errors to log again
            _logErrorBitField = 0;
        }
    
}
Exemple #5
0
char *
buildPath (const char *filename) {
   char *pathptr;             /* pointer to the PATH shell variable    */
   char *path;                /* pointer to the current PATH token     */
   char *buffptr;             /* where we will store the full pathname */
   size_t pathlen;            /* for calculating space for malloc() */
   char delim[2];             /* delimiter for pathnames.           */
                              /*   Assumption:  if a path doesn't   */
                              /*   contain any '/' chars, the       */
                              /*   delimiter is ':'.                */
#ifdef BACKWARDS
	 static char *default_path = "/usr/bin /bin";
   char *path_copy;
#else
	 static char *default_path = "/bin /usr/bin";
#endif

   /*
    * if for some weird and wonderful reason, filename is a full pathname,
    * then just return a pointer to a copy of it.  In this case no test
    * for existence is done.
    */
   if (isRootPath(filename)) {
	   buffptr = (char *) malloc (strlen(filename) + 1);
      if (buffptr == NULL) return NULL;
      strcpy (buffptr,filename);
      return buffptr;
   }

   /* get the value of the PATH shell variable */
   pathptr = getenv ("PATH");
   if (pathptr == NULL || *pathptr == '\0') {
      /* PATH doesn't exist -- use default */
      pathptr = default_path;
   }

   /* define the pathname delimiter */
   (strstr(pathptr,"/") == NULL) ? strcpy (delim, ":") : strcpy (delim, "/");

   /*
    * search paths for filename -- backwards or forwards as appropriate
    */

#ifdef BACKWARDS
   /* make a copy of the path */
   pathlen = strlen(pathptr) + 1;
   if ((path_copy = (char *) malloc((size_t) strlen(pathptr) + 1))==NULL) {
      errno = ENOMEM;
      return NULL;
   }
   strcpy(path_copy,pathptr);
   path = path_copy + pathlen;

   /* look for the file */
   while (path>=path_copy) {
      while ((path>path_copy) && (*path != ' ')) path--;
      if (path>path_copy) {     /* not done parsing $PATH */
         if (_fileExists(filename, path+1)) {    /* found it! */
            path++;
            break;
         } else {               /* not found; terminate string and try again */
            *path = '\0';
         }
      } else {
	      /*
          * at this point, path points to either first listed directory or
          * whitespace; check it
          */
         if (isprint(*path) && _fileExists(filename, path)) {    /* found it! */
            break;
         } else {
         	free(path_copy);		/* not in $PATH; parse failed */
         	errno = ENOENT;
         	return NULL;
         }
      }
   }
#else
   path = strtok (pathptr, " ");
   while (path != NULL) {
      if (_fileExists(filename, path)) break;
      path = strtok (NULL, NULL);
   }

   /* filename not within listed paths */
   if (path == NULL) {
      errno = ENOENT;
      return NULL;
   }
#endif  /* BACKWARDS */


   /* allocate the buffer */
   pathlen = strlen(filename) + strlen(path) + 2;
   if ((buffptr = malloc (pathlen)) == NULL) {
#ifdef BACKWARDS
      free(path_copy);
#endif
      return NULL;
   }

   /* build the full pathname */
   strcpy (buffptr,path);
   strcat (buffptr,delim);
   strcat (buffptr,filename);

#ifdef BACKWARDS
   free(path_copy);
#endif
                  
   return buffptr;
}
static int _testInvalidFileExists(void) {
  assertFalse(_fileExists("invalid"));
  return 0;
}
static int _testNullFileExists(void) {
  assertFalse(_fileExists(NULL));
  return 0;
}