CASA/c_adlib/ad_ff/native/Common.cpp

116 lines
2.4 KiB
C++
Raw Normal View History

2006-03-10 19:39:22 +01:00
/***********************************************************************
*
* Copyright (C) 2005-2006 Novell, Inc. All Rights Reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; version 2.1
* of the License.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, Novell, Inc.
*
* To contact Novell about this file by physical or electronic mail,
* you may find current contact information at www.novell.com.
*
***********************************************************************/
2006-02-28 12:17:08 +01:00
#include "FirefoxPasswordManager.h"
#include "Common.h"
char lastErrorMesg[10000];
void PrintMessage( int level, char *mesg , ...)
{
va_list vl;
va_start( vl , mesg );
vsprintf( lastErrorMesg , mesg , vl );
va_end( vl );
// if we are not debugging then print DEBUG level messages
#ifdef DEBUG
printf("%s", lastErrorMesg );
#else
2006-03-09 05:45:36 +01:00
if( level != MESG_DEBUG )
{
//printf("%s", lastErrorMesg );
}
2006-02-28 12:17:08 +01:00
#endif
}
/**
* Converts given string to lower case....
*
*/
void StrLwr(char *str)
{
int n=strlen(str);
for(int i=0; i<n; i++)
{
if( str[i] >=65 && str[i]<=90 )
str[i]+=32;
}
}
/**
* Checks if specified directory exists
*
* return MC_TRUE if directory exists else MC_FALSE
*
*/
int IsDirectoryExists( char *path )
{
if( path == NULL )
return 0;
#ifdef WIN32
DWORD attr = GetFileAttributes(path);
if( (attr == -1) || !(attr & FILE_ATTRIBUTE_DIRECTORY ) )
{
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
return 0;
}
return 1;
#else
char *program = (char*) malloc(strlen(path)+20);
if( program == NULL )
return 0;
strcpy(program, "test -d ");
strcat(program, path);
int result= system(program);
free(program);
if( result != 0 )
{
PrintMessage(MESG_ERROR, "\n IsDirectoryExists : Directory does not exist : [%s] ", path);
return 0;
}
return 1;
#endif
}