#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"
#warning VERIFY the version string before each distinct build submission
static const char *sysStrList [] =
{
"1.5.3",
"197.8"
};
static const char *appStrList [] =
{
"Frameworks/DirectoryService.framework/Resources/Plugins",
"DirectoryService",
"Plugins",
"Logs",
"server.log",
"error.log",
"debug.log",
"info.log",
"dsplug",
"DirectoryServices/PlugIns"
};
const char* COSUtils::GetStringFromList ( const uInt32 inListID, const sInt32 inIndex )
{
static const char *_sNoMatch = "<STRING NOT FOUND>";
char *pStr = (char *)_sNoMatch;
switch ( inListID )
{
case kSysStringListID:
if ( (inIndex - 1) < (sInt32)(sizeof (sysStrList) / sizeof( char * )) )
{
pStr = (char *)sysStrList[ inIndex - 1 ];
}
break;
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 ) )
{
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;
}
else
return 0;
}