#include <string.h>
#include <fcntl.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <unistd.h>
#include <syslog.h>
#include "COSUtils.h"
static const char *appStrList [] =
{
"Frameworks/DirectoryService.framework/Resources/Plugins",
"DirectoryService",
"Plugins",
"Logs",
"server.log",
"error.log",
"debug.log",
"info.log",
"dsplug",
"DirectoryServices/PlugIns",
"DirectoryService/Local"
};
const char* COSUtils::GetStringFromList ( const UInt32 inListID, const SInt32 inIndex )
{
static const char *_sNoMatch = "<STRING NOT FOUND>";
char *pStr = (char *)_sNoMatch;
switch ( inListID )
{
case kAppStringsListID:
if ( (inIndex - 1) < (SInt32)(sizeof (appStrList) / sizeof( char * )) )
{
pStr = (char *)appStrList[ inIndex - 1 ];
}
break;
default:
break;
}
return( pStr );
}
int dsTouch( const char* path )
{
int fd = -1;
int status = 0;
if ( path )
{
fd = open( path, O_NOFOLLOW | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR );
if ( fd >= 0 )
{
if ( close( fd ) )
status = errno;
}
else
{
status = errno;
syslog( LOG_ALERT, "WARNING - dsTouch: file was asked to be opened <%s>: (%s)\n", path, strerror(errno) );
}
}
else
status = EINVAL;
return status;
}
int dsRemove( const char* path )
{
if ( unlink( path ) )
{
if ( errno != ENOENT ) {
syslog( LOG_ALERT, "WARNING - dsRemove: file was asked to be deleted that should be zero length but isn't! <%s> (%s)\n", path, strerror(errno) );
return errno;
}
}
return 0;
}