int fb_cd(const char *newdir){
	if(strlen(newdir)>=256)return ERROR_FILENAME_TOO_LONG;
	if(fsaccess_IsDirPresent( newdir )==0)return ERROR_NOT_A_DIRECTORY;

	char *cd =currentDirectory;
	while((*cd++ = *newdir++));
	return 0;
}
示例#2
0
文件: datalog.c 项目: Mazetti/asf
/*!
 * \brief Open the current log file.
 *
 * \return the file descriptor or -1 if open failed.
 */
static int prv_xopen_current_logfile( void )
{
   int       fd_current_logfile;
   struct tm *pxDate;


   // TRACE_COM2( "open logfile begin==%d", xcptime_LocalTime );

   while( 1 )
   {
      fd_current_logfile = -1; // Init to default value.

      /* Open the log file. */
      if( '\0' != *acLogFileName )
      {   // If we have an active current log file, simply open it in append mode.
         fd_current_logfile = open( acLogFileName, O_APPEND );

         // Check if the max file size has been reached.
         if( -1 != fd_current_logfile )
         {
            if( DATALOG_LOGFILE_MAXSIZE <= fsaccess_file_get_size( fd_current_logfile ) )
            {   // The current log file has reached the max size.
               // Get the current time in the "YYYYMMDDHHMMSSMS" string format.
               v_cptime_GetDateInFatStringFormat( pcTempoDate );
               // Set the file date.
               nav_file_dateset( (FS_STRING)pcTempoDate, FS_DATE_LAST_WRITE );
               close( fd_current_logfile ); // Close the file.
               *acLogFileName = '\0';       // Reset the current log file name.
               continue; // Do another loop to create/open a new file.
            }
         }
         else
         {  // The file has been removed.
            *acLogFileName = '\0'; // Reset the current log file name.
            continue;              // Do another loop to create/open a new file.
         }
      }
      else
      {   // Create a new log file.
         // Get the broken-down representation of the current date.
         pxDate = gmtime( &xcptime_LocalTime );

         // Build the filename: mmddyy_hhmm.log
         // WARNING: pxDate->tm_year == number of years since 1900.
         // For years >= 2000, we'll display the last 2 digits only.
         if( pxDate->tm_year >= 100 )
            pxDate->tm_year -= 100;

         sprintf( acLogFileName, "%s/%.2d%.2d%.2d_%.2d%.2d.log",
                  pcStringCurrentLogDirectoryName, pxDate->tm_mon +1, pxDate->tm_mday,
                  pxDate->tm_year, pxDate->tm_hour, pxDate->tm_min );

         NAKED_TRACE_COM2( "Creating log file %s", acLogFileName );

         // Create the log file only if the /LOG directory exists.
         if( true == fsaccess_IsDirPresent( (const char *)pcStringCurrentLogDirectoryName ) )
         {     // The LOG/ directory exists.
            // Create and open the file.
            // if the file already exists, then the file size is reset.
            fd_current_logfile = open( acLogFileName, (O_CREAT|O_WRONLY) );
            // previous file is closed, send a mail
            if ( *acPreviousLogFileName != '\0' )
            {
               // post alarm to SMTP task
               v_SMTP_Post(acPreviousLogFileName, acPreviousLogFileName);
            }
            strncpy(acPreviousLogFileName, acLogFileName, strlen(acLogFileName));
         }
      }
      if( -1 == fd_current_logfile )
      {   // The open failed. We're not in maintenance mode.
         // Just remove the oldest log file: TODO
         NAKED_TRACE_COM2( "Failed opening the current log file %s", acLogFileName );
         /*########### TEMPORARY #############*/
         break;
         /*###################################*/
      }
      else break;
   }

   return( fd_current_logfile );
}