本文整理汇总了C++中firebird::string::printf方法的典型用法代码示例。如果您正苦于以下问题:C++ string::printf方法的具体用法?C++ string::printf怎么用?C++ string::printf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类firebird::string
的用法示例。
在下文中一共展示了string::printf方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createLockDirectory
// create directory for lock files and set appropriate access rights
void createLockDirectory(const char* pathname)
{
static bool errorLogged = false;
DWORD attr = GetFileAttributes(pathname);
DWORD errcode = 0;
if (attr == INVALID_FILE_ATTRIBUTES)
{
errcode = GetLastError();
if (errcode == ERROR_FILE_NOT_FOUND)
{
if (!CreateDirectory(pathname, NULL)) {
errcode = GetLastError();
}
else
{
adjustLockDirectoryAccess(pathname);
attr = GetFileAttributes(pathname);
if (attr == INVALID_FILE_ATTRIBUTES) {
errcode = GetLastError();
}
}
}
}
Firebird::string err;
if (attr == INVALID_FILE_ATTRIBUTES)
{
err.printf("Can't create directory \"%s\". OS errno is %d", pathname, errcode);
if (!errorLogged)
{
errorLogged = true;
gds__log(err.c_str());
}
Firebird::fatal_exception::raise(err.c_str());
}
if (!(attr & FILE_ATTRIBUTE_DIRECTORY))
{
err.printf("Can't create directory \"%s\". File with same name already exists", pathname);
if (!errorLogged)
{
errorLogged = true;
gds__log(err.c_str());
}
Firebird::fatal_exception::raise(err.c_str());
}
if (attr & FILE_ATTRIBUTE_READONLY)
{
err.printf("Can't create directory \"%s\". Readonly directory with same name already exists", pathname);
if (!errorLogged)
{
errorLogged = true;
gds__log(err.c_str());
}
Firebird::fatal_exception::raise(err.c_str());
}
}
示例2: grantRevokeAdmin
void grantRevokeAdmin(Firebird::IUser* user, bool ignoreRevoke = false)
{
if (!user->admin()->entered())
{
return;
}
Firebird::LocalStatus s;
Firebird::CheckStatusWrapper statusWrapper(&s);
Firebird::string userName(user->userName()->get());
prepareName(userName, '"');
Firebird::string sql;
if (user->admin()->get() == 0)
{
Firebird::string userName2(user->userName()->get());
prepareName(userName2, '\'');
Firebird::string selGrantor;
selGrantor.printf("SELECT RDB$GRANTOR FROM RDB$USER_PRIVILEGES "
"WHERE RDB$USER = '%s' AND RDB$RELATION_NAME = '%s' AND RDB$PRIVILEGE = 'M'",
userName2.c_str(), ADMIN_ROLE);
Message out;
Field<Varying> grantor(out, MAX_SQL_IDENTIFIER_SIZE);
Firebird::IResultSet* curs = att->openCursor(&statusWrapper, tra, selGrantor.length(),
selGrantor.c_str(), SQL_DIALECT_V6, NULL, NULL, out.getMetadata(), NULL, 0);
check(&statusWrapper);
bool hasGrant = curs->fetchNext(&statusWrapper, out.getBuffer()) == Firebird::IStatus::RESULT_OK;
curs->close(&statusWrapper);
check(&statusWrapper);
if (hasGrant)
{
selGrantor = grantor;
prepareName(selGrantor, '"');
sql.printf("REVOKE %s FROM \"%s\" GRANTED BY \"%s\"",
ADMIN_ROLE, userName.c_str(), selGrantor.c_str());
}
else
{
if (ignoreRevoke)
return;
// no grant - let engine produce correct error message
sql.printf("REVOKE %s FROM \"%s\"", ADMIN_ROLE, userName.c_str());
}
}
else
{
sql.printf("GRANT %s TO \"%s\"", ADMIN_ROLE, userName.c_str());
}
att->execute(&statusWrapper, tra, sql.length(), sql.c_str(),
SQL_DIALECT_V6, NULL, NULL, NULL, NULL);
check(&statusWrapper);
}
示例3: TracePluginImpl
TracePlugin* FB_CARG TraceFactoryImpl::trace_create(Firebird::IStatus* status, TraceInitInfo* initInfo)
{
Firebird::MasterInterfacePtr master;
const char* dbname = NULL;
try
{
master->upgradeInterface(initInfo, FB_TRACE_INIT_INFO_VERSION, upInfo);
dbname = initInfo->getDatabaseName();
if (!dbname)
dbname = "";
TracePluginConfig config;
TraceCfgReader::readTraceConfiguration(initInfo->getConfigText(), dbname, config);
TraceDatabaseConnection* connection = initInfo->getConnection();
if (connection)
master->upgradeInterface(connection, FB_TRACE_CONNECTION_VERSION, upInfo);
if (!config.enabled ||
(config.connection_id && connection &&
(connection->getConnectionID() != SLONG(config.connection_id))))
{
return NULL; // Plugin is not needed, no error happened.
}
Firebird::AutoPtr<TraceLogWriter, Firebird::SimpleRelease<TraceLogWriter> >
logWriter(initInfo->getLogWriter());
if (logWriter)
config.log_filename = "";
return new TracePluginImpl(config, initInfo); // Everything is ok, we created a plugin
}
catch (Firebird::Exception& ex)
{
// put error into trace log
TraceLogWriter* logWriter = initInfo->getLogWriter();
if (logWriter)
{
master->upgradeInterface(logWriter, FB_TRACE_LOG_WRITER_VERSION, upInfo);
const char* strEx = TracePluginImpl::marshal_exception(ex);
Firebird::string err;
if (dbname)
err.printf("Error creating trace session for database \"%s\":\n%s\n", dbname, strEx);
else
err.printf("Error creating trace session for service manager attachment:\n%s\n", strEx);
logWriter->write(err.c_str(), err.length());
logWriter->release();
}
else
ex.stuffException(status);
}
return NULL;
}
示例4: pagtype
Firebird::string pagtype(UCHAR type)
{
// Print pretty name for database page type
const char* nameArray[pag_max + 1] = {
"purposely undefined",
"database header",
"page inventory",
"transaction inventory",
"pointer",
"data",
"index root",
"index B-tree",
"blob",
"generators",
"SCN inventory"
};
Firebird::string rc;
if (type < FB_NELEM(nameArray))
rc = nameArray[type];
else
rc.printf("unknown (%d)", type);
return rc;
}
示例5: loadModule
ModuleLoader::Module* ModuleLoader::loadModule(ISC_STATUS* status, const Firebird::PathName& modPath)
{
void* module = dlopen(modPath.nullStr(), FB_RTLD_MODE);
if (module == NULL)
{
if (status)
{
status[0] = isc_arg_gds;
status[1] = isc_random;
status[2] = isc_arg_string;
status[3] = (ISC_STATUS) dlerror();
status[4] = isc_arg_end;
}
return 0;
}
#ifdef DEBUG_THREAD_IN_UNLOADED_LIBRARY
Firebird::string command;
command.printf("echo +++ %s +++ >>/tmp/fbmaps;date >> /tmp/fbmaps;cat /proc/%d/maps >>/tmp/fbmaps",
modPath.c_str(), getpid());
system(command.c_str());
#endif
return FB_NEW_POOL(*getDefaultMemoryPool()) DlfcnModule(*getDefaultMemoryPool(), modPath, module);
}
示例6: fb_msg_format
// Lookup and format message. Return as much of formatted string as fits in caller's buffer.
int fb_msg_format(void* handle, USHORT facility, USHORT number, unsigned int bsize, TEXT* buffer,
const MsgFormat::SafeArg& arg)
{
// The field MESSAGES.TEXT is 118 bytes long.
int total_msg = 0;
char msg[120] = "";
const int n = gds__msg_lookup(handle, facility, number, sizeof(msg), msg, NULL);
if (n > 0 && unsigned(n) < sizeof(msg))
{
// Shameful bridge, gds__msg_format emulation for old format messages.
if (strchr(msg, '%'))
{
const TEXT* rep[5];
arg.dump(rep, 5);
total_msg = fb_utils::snprintf(buffer, bsize, msg, rep[0], rep[1], rep[2], rep[3], rep[4]);
}
else
total_msg = MsgPrint(buffer, bsize, msg, arg);
}
else
{
Firebird::string s;
s.printf("can't format message %d:%d -- ", facility, number);
if (n == -1)
s += "message text not found";
else if (n == -2)
{
s += "message file ";
s += fb_utils::getPrefix(Firebird::DirType::FB_DIR_MSG, MSG_FILE).ToString();
s += " not found";
}
else
{
fb_utils::snprintf(buffer, bsize, "message system code %d", n);
s += buffer;
}
total_msg = s.copyTo(buffer, bsize);
}
return (n > 0 ? total_msg : -total_msg);
}
示例7: loadModule
ModuleLoader::Module* ModuleLoader::loadModule(const Firebird::PathName& modPath)
{
void* module = dlopen(modPath.nullStr(), FB_RTLD_MODE);
if (module == NULL)
{
#ifdef DEV_BUILD
// gds__log("loadModule failed loading %s: %s", modPath.c_str(), dlerror());
#endif
return 0;
}
#ifdef DEBUG_THREAD_IN_UNLOADED_LIBRARY
Firebird::string command;
command.printf("echo +++ %s +++ >>/tmp/fbmaps;date >> /tmp/fbmaps;cat /proc/%d/maps >>/tmp/fbmaps",
modPath.c_str(), getpid());
system(command.c_str());
#endif
return FB_NEW_POOL(*getDefaultMemoryPool()) DlfcnModule(module);
}
示例8: adjustLockDirectoryAccess
// allow different users to read\write\delete files in lock directory
// in case of any error just log it and don't stop engine execution
void adjustLockDirectoryAccess(const char* pathname)
{
PSECURITY_DESCRIPTOR pSecDesc = NULL;
PSID pSID_Users = NULL;
PSID pSID_Administrators = NULL;
PACL pNewACL = NULL;
try
{
// We should pass root directory in format "C:\" into GetVolumeInformation().
// In case of pathname is not local folder (i.e. \\share\folder) let
// GetVolumeInformation() return an error.
Firebird::PathName root(pathname);
const Firebird::PathName::size_type pos = root.find(':', 0);
if (pos == 1)
{
root.erase(pos + 1, root.length());
PathUtils::ensureSeparator(root);
}
DWORD fsflags;
if (!GetVolumeInformation(root.c_str(), NULL, 0, NULL, NULL, &fsflags, NULL, 0))
Firebird::system_error::raise("GetVolumeInformation");
if (!(fsflags & FS_PERSISTENT_ACLS))
return;
// Adjust security for our new folder : allow BUILTIN\Users group to
// read\write\delete files
PACL pOldACL = NULL;
if (GetNamedSecurityInfo((LPSTR) pathname,
SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
NULL, NULL, &pOldACL, NULL,
&pSecDesc) != ERROR_SUCCESS)
{
Firebird::system_error::raise("GetNamedSecurityInfo");
}
SID_IDENTIFIER_AUTHORITY sidAuth = SECURITY_NT_AUTHORITY;
if (!AllocateAndInitializeSid(&sidAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_USERS, 0, 0, 0, 0, 0, 0, &pSID_Users))
{
Firebird::system_error::raise("AllocateAndInitializeSid");
}
if (!AllocateAndInitializeSid(&sidAuth, 2, SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS, 0, 0, 0, 0, 0, 0, &pSID_Administrators))
{
Firebird::system_error::raise("AllocateAndInitializeSid");
}
EXPLICIT_ACCESS eas[2];
memset(eas, 0, sizeof(eas));
eas[0].grfAccessPermissions = FILE_GENERIC_READ | FILE_GENERIC_WRITE | DELETE;
eas[0].grfAccessMode = GRANT_ACCESS;
eas[0].grfInheritance = SUB_OBJECTS_ONLY_INHERIT;
eas[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
eas[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
eas[0].Trustee.ptstrName = (LPSTR) pSID_Users;
eas[1].grfAccessPermissions = FILE_GENERIC_READ | FILE_GENERIC_WRITE | DELETE;
eas[1].grfAccessMode = GRANT_ACCESS;
eas[1].grfInheritance = SUB_OBJECTS_ONLY_INHERIT;
eas[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
eas[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
eas[1].Trustee.ptstrName = (LPSTR) pSID_Administrators;
if (SetEntriesInAcl(2, eas, pOldACL, &pNewACL) != ERROR_SUCCESS)
Firebird::system_error::raise("SetEntriesInAcl");
if (SetNamedSecurityInfo((LPSTR) pathname,
SE_FILE_OBJECT, DACL_SECURITY_INFORMATION,
NULL, NULL, pNewACL, NULL) != ERROR_SUCCESS)
{
Firebird::system_error::raise("SetNamedSecurityInfo");
}
}
catch (const Firebird::Exception& ex)
{
Firebird::string str;
str.printf("Error adjusting access rights for folder \"%s\" :", pathname);
iscLogException(str.c_str(), ex);
}
if (pSID_Users) {
FreeSid(pSID_Users);
}
if (pSID_Administrators) {
FreeSid(pSID_Administrators);
}
if (pNewACL) {
LocalFree(pNewACL);
}
if (pSecDesc) {
LocalFree(pSecDesc);
}
//.........这里部分代码省略.........
示例9: EVL_validate
void EVL_validate(thread_db* tdbb, const Item& item, const ItemInfo* itemInfo, dsc* desc, bool null)
{
/**************************************
*
* E V L _ v a l i d a t e
*
**************************************
*
* Functional description
* Validate argument/variable for not null and check constraint
*
**************************************/
if (itemInfo == NULL)
return;
jrd_req* request = tdbb->getRequest();
bool err = false;
if (null && !itemInfo->nullable)
err = true;
const char* value = NULL_STRING_MARK;
VaryStr<128> temp;
MapFieldInfo::ValueType fieldInfo;
if (!err && itemInfo->fullDomain &&
request->getStatement()->mapFieldInfo.get(itemInfo->field, fieldInfo) &&
fieldInfo.validationExpr)
{
if (desc && null)
desc->dsc_flags |= DSC_null;
const bool desc_is_null = !desc || (desc->dsc_flags & DSC_null);
request->req_domain_validation = desc;
const USHORT flags = request->req_flags;
if (!fieldInfo.validationExpr->execute(tdbb, request) && !(request->req_flags & req_null))
{
const USHORT length = desc_is_null ? 0 :
MOV_make_string(desc, ttype_dynamic, &value, &temp, sizeof(temp) - 1);
if (desc_is_null)
value = NULL_STRING_MARK;
else if (!length)
value = "";
else
const_cast<char*>(value)[length] = 0; // safe cast - data is on our local stack
err = true;
}
request->req_flags = flags;
}
Firebird::string s;
if (err)
{
ISC_STATUS status = isc_not_valid_for_var;
const char* arg;
if (item.type == Item::TYPE_CAST)
{
status = isc_not_valid_for;
arg = "CAST";
}
else
{
if (itemInfo->name.isEmpty())
{
int index = item.index + 1;
status = isc_not_valid_for;
if (item.type == Item::TYPE_VARIABLE)
{
const jrd_prc* procedure = request->getStatement()->procedure;
if (procedure)
{
if (index <= int(procedure->getOutputFields().getCount()))
s.printf("output parameter number %d", index);
else
{
s.printf("variable number %d",
index - int(procedure->getOutputFields().getCount()));
}
}
else
s.printf("variable number %d", index);
}
else if (item.type == Item::TYPE_PARAMETER && item.subType == 0)
s.printf("input parameter number %d", (index - 1) / 2 + 1);
else if (item.type == Item::TYPE_PARAMETER && item.subType == 1)
s.printf("output parameter number %d", index);
if (s.isEmpty())
arg = UNKNOWN_STRING_MARK;
else
//.........这里部分代码省略.........
示例10: gsec
//.........这里部分代码省略.........
Firebird::string network_protocol, remote_address;
Firebird::ClumpletWriter tmp(Firebird::ClumpletReader::Tagged, MAX_DPB_SIZE, isc_dpb_version1);
uSvc->fillDpb(tmp);
if (tmp.find(isc_dpb_address_path))
{
Firebird::ClumpletReader address_stack(Firebird::ClumpletReader::UnTagged,
tmp.getBytes(), tmp.getClumpLength());
while (!address_stack.isEof())
{
if (address_stack.getClumpTag() != isc_dpb_address)
{
address_stack.moveNext();
continue;
}
Firebird::ClumpletReader address(Firebird::ClumpletReader::UnTagged,
address_stack.getBytes(), address_stack.getClumpLength());
while (!address.isEof())
{
switch (address.getClumpTag())
{
case isc_dpb_addr_protocol:
address.getString(network_protocol);
break;
case isc_dpb_addr_endpoint:
address.getString(remote_address);
break;
default:
break;
}
address.moveNext();
}
break;
}
}
// Create config to pass -DATABASE parameter value to plugin
Firebird::string databaseText;
databaseText.printf("SecurityDatabase = %s\n", databaseName.c_str());
ConfigFile gsecDatabase(ConfigFile::USE_TEXT, databaseText.c_str());
Firebird::RefPtr<Config> defaultConfig(Config::getDefaultConfig());
Firebird::RefPtr<Config> pseudoConfig(new Config(gsecDatabase, *defaultConfig));
uSvc->checkService();
fb_assert(user_data->dba.entered() || user_data->authenticationBlock.hasData());
if (user_data->dba.entered() || user_data->authenticationBlock.hasData())
{
class GsecInfo : public Firebird::AutoIface<ILogonInfo, FB_AUTH_LOGON_INFO_VERSION>
{
public:
GsecInfo(const char* pDba, const char* pRole,
const char* pProtocol, const char* pAddress,
const UserData::AuthenticationBlock* pAuthBlock)
: dba(pDba), sqlRole(pRole),
protocol(pProtocol), address(pAddress),
authBytes(pAuthBlock->getCount() ? pAuthBlock->begin() : NULL),
authLength(pAuthBlock->getCount())
{ }
// ILogonInfo implementation
const char* FB_CARG name()
{
return dba;
}
const char* FB_CARG role()
{
return sqlRole;
}
const char* FB_CARG networkProtocol()
{
return protocol;
}
const char* FB_CARG remoteAddress()
{
return address;
}
const unsigned char* FB_CARG authBlock(unsigned* length)
{
*length = authLength;
return authBytes;
}
private:
const char* dba;
const char* sqlRole;
const char* protocol;
const char* address;
const unsigned char* authBytes;
unsigned int authLength;
};
示例11: setAttr
static void setAttr(Firebird::string& attr, IIntUserField* field)
{
attr.printf("%d", field->get());
}
示例12: main
int CLIB_ROUTINE main( int argc, char **argv)
{
/**************************************
*
* m a i n
*
**************************************
*
* Functional description
* Install or remove a Firebird service.
*
**************************************/
USHORT sw_command = COMMAND_NONE;
bool sw_version = false;
USHORT sw_startup = STARTUP_AUTO;
USHORT sw_mode = DEFAULT_PRIORITY;
USHORT sw_guardian = NO_GUARDIAN;
USHORT sw_arch = ARCH_SS;
bool sw_interactive = false;
const TEXT* instance = FB_DEFAULT_INSTANCE;
const TEXT* username = NULL;
const TEXT* password = NULL;
// Let's get the root directory from the instance path of this program.
// argv[0] is only _mostly_ guaranteed to give this info,
// so we GetModuleFileName()
TEXT directory[MAXPATHLEN];
const USHORT len = GetModuleFileName(NULL, directory, sizeof(directory));
if (len == 0)
return svc_error(GetLastError(), "GetModuleFileName", NULL);
fb_assert(len <= sizeof(directory));
// Get to the last '\' (this one precedes the filename part). There is
// always one after a call to GetModuleFileName().
TEXT* p = directory + len;
while (p != directory)
{
--p;
if ((*p) == '\\')
break;
}
*p = '\0';
TEXT full_username[128];
TEXT oem_username[128];
TEXT keyb_password[64];
const TEXT* const* const end = argv + argc;
while (++argv < end)
{
if (**argv != '-')
{
int i;
const TEXT* cmd;
for (i = 0; cmd = commands[i].name; i++)
{
const TEXT* q;
for (p = *argv, q = cmd; *p && UPPER(*p) == *q; p++, q++)
;
if (!*p && commands[i].abbrev <= (USHORT) (q - cmd))
break;
}
if (!cmd)
{
printf("Unknown command \"%s\"\n", *argv);
usage_exit();
}
sw_command = commands[i].code;
}
else
{
p = *argv + 1;
switch (UPPER(*p))
{
case 'A':
sw_startup = STARTUP_AUTO;
break;
case 'D':
sw_startup = STARTUP_DEMAND;
break;
/*
case 'R':
sw_mode = NORMAL_PRIORITY;
break;
*/
case 'B':
sw_mode = HIGH_PRIORITY;
break;
case 'Z':
sw_version = true;
break;
//.........这里部分代码省略.........