本文整理汇总了C++中string_t::ptr方法的典型用法代码示例。如果您正苦于以下问题:C++ string_t::ptr方法的具体用法?C++ string_t::ptr怎么用?C++ string_t::ptr使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类string_t
的用法示例。
在下文中一共展示了string_t::ptr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exception_sys_t
file_t::file_t(char const *name, string_t const &header) :
ref_cnt(0), fd(-1), used(false), id() {
if(config::check)
return;
fd = ::open(name, O_WRONLY | O_APPEND | O_CREAT, 0644);
if(fd < 0)
throw exception_sys_t(log::error, errno, "open (%s): %m", name);
fd_guard_t guard(fd);
id = id_t(fd, used);
if(!id)
throw exception_sys_t(log::error, errno, "fstat (%s): %m", name);
if(::flock(fd, LOCK_SH | LOCK_NB) < 0)
throw exception_sys_t(log::error, errno, "flock (%s): %m", name);
if(header) {
if(::write(fd, header.ptr(), header.size()) < 0)
throw exception_sys_t(log::error, errno, "write (%s): %m", name);
}
guard.relax();
}
示例2: check
void handler_t::check() {
file_t *tmp = NULL;
bool skip_file_check = false;
{
spinlock_guard_t guard(spinlock);
if(old) {
if(old->ref_cnt)
skip_file_check = true;
else {
tmp = old;
old = NULL;
}
}
}
if(tmp) { delete tmp; tmp = NULL; }
if(skip_file_check) return;
struct stat st;
if(::stat(filename_z.ptr(), &st) == 0) {
if(id_t(st) == current->id) // Don't need lock
return;
}
else {
if(errno != ENOENT)
log_error("stat: (%s) %m", filename_z.ptr());
}
tmp = new file_t(filename_z.ptr(), header);
{
spinlock_guard_t guard(spinlock);
if(!old) {
old = current;
current = tmp;
tmp = NULL;
}
if(!old->ref_cnt) {
tmp = old;
old = NULL;
}
}
if(tmp) { delete tmp; tmp = NULL; }
}
示例3: mime_type_need_charset
// ugly function #1
static bool mime_type_need_charset(string_t const &mtype) {
char const *p = mtype.ptr();
return (
mtype.size() >= 5 &&
p[0] == 't' && p[1] == 'e' && p[2] == 'x' && p[3] == 't' && p[4] == '/'
);
}
示例4: mime_type_compare
// ugly function #2
static bool mime_type_compare(string_t const &m1, string_t const &m2) {
char const *b1 = m1.ptr();
size_t m1_len = m1.size();
char const *p1 = (char const *)memchr(b1, '/', m1_len);
char const *b2 = m2.ptr();
size_t m2_len = m2.size();
char const *p2 = (char const *)memchr(b2, '/', m2_len);
if(!p2) return true;
if(!p1) return false;
size_t l1 = p1 - b1;
size_t l2 = p2 - b2;
bool x1 = (l1 >= 2 && b1[0] == 'x' && b1[1] == '-');
bool x2 = (l2 >= 2 && b2[0] == 'x' && b2[1] == '-');
if(x2 && !x1) return true;
if(!x2 && x1) return false;
size_t k1 = m1_len - l1;
size_t k2 = m2_len - l2;
x1 = (k1 >= 3 && p1[1] == 'x' && p1[2] == '-');
x2 = (k2 >= 3 && p2[1] == 'x' && p2[2] == '-');
if(x2 && !x1) return true;
if(!x2 && x1) return false;
if(l1 < l2) return true;
if(l2 < l1) return false;
if(m1_len < m2_len) return true;
return false;
}
示例5: handler_t
inline handler_t(string_t const &filename, string_t const &_header) :
filename_z(string_t::ctor_t(filename.size() + 1)(filename)('\0')),
header(_header), current(NULL), old(NULL), stat() {
current = new file_t(filename_z.ptr(), header);
}