本文整理汇总了C++中SystemError函数的典型用法代码示例。如果您正苦于以下问题:C++ SystemError函数的具体用法?C++ SystemError怎么用?C++ SystemError使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SystemError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GMC_DCL
GMC_DCL(tp_FilHdr, OrigFilHdr)
{
tp_LocElm LocElm, LastLocElm;
tps_FileName DestFileName;
LocElm = NIL;
if (!IsSource(DestFilHdr)) {
SystemError("Destination of copy must be a source file or directory.\n");
goto done; }/*if*/;
FilHdr_HostFN(DestFileName, DestFilHdr, FALSE);
if (!IsDirectory_FileName(DestFileName)) {
if (IsList(OrigFilHdr)) {
SystemError("List objects can only be copied to directories.\n");
goto done; }/*if*/;
LocElm = Make_CopyLocElm(OrigFilHdr, DestFilHdr, FilHdr);
goto done; }/*if*/;
LastLocElm = NIL;
Get_CopyList(&LocElm, &LastLocElm, OrigFilHdr, DestFilHdr, FilHdr);
Clr_UnionFlags(OrigFilHdr);
done:;
Set_LocElm(FilHdr, LocElm);
}/*Exec_CopyCmd*/
示例2: while
void Socket::socket_receive(char *buff,
size_t sz,
char *delim,
size_t sz_delim)
{
size_t read = 0;
size_t total = 0;
char *pos = NULL;
bool received_delim = false;
bool continue_recv = (total < sz);
while (continue_recv){
pos = buff + total;
try{
read = recv(this->fd, pos, SIZE_RECEIVE, MSG_NOSIGNAL);
if (read < 0){
std::string error_desc = MSG_ERROR_RECV;
error_desc += MSG_FD + this->fd;
error_desc += strerror(errno);
throw SystemError(error_desc, __FILE__, __LINE__);
}
total += read;
//if (total >= sz_delim){
received_delim = (strncmp(delim, pos - sz_delim + 1, sz_delim) != 0);
//}
continue_recv = (received_delim) && (total < sz);
}catch(std::exception &e){
std::string error_desc = MSG_ERROR_RECV;
error_desc += MSG_FD + this->fd;
error_desc += strerror(errno);
throw SystemError(error_desc, __FILE__, __LINE__);
}
}
}
示例3: SensorDriver
TpSensorDriver::TpSensorDriver(std::string path)
: SensorDriver(path)
{
std::ifstream f(path_);
try {
f.exceptions(f.failbit | f.badbit);
int tmp;
unsigned int count = 0;
string skip;
skip.resize(skip_prefix_.size());
f.exceptions(f.badbit);
f.getline(&*skip.begin(), skip_prefix_.size()+1);
f.clear(f.rdstate() & ~f.failbit);
if (skip == skip_prefix_)
skip_bytes_ = f.tellg();
else
throw SystemError(path_ + ": Unknown file format.");
while (!(f.eof() || f.fail())) {
f >> tmp;
if (!f.fail())
++count;
}
set_num_temps(count);
} catch (std::ios_base::failure &e) {
string msg = std::strerror(errno);
throw SystemError(MSG_SENSOR_INIT(path_) + msg);
}
}
示例4: GetCurrentProcessId
PipeImpl::PipeImpl()
{
std::stringstream ss;
ss<<"\\\\.\\pipe\\pt-" << GetCurrentProcessId() << '-' << _nameId;
DWORD pflags = PIPE_ACCESS_DUPLEX;
DWORD access = GENERIC_WRITE;
DWORD share = 0;
DWORD create = OPEN_EXISTING;
DWORD flags = 0;
flags = FILE_FLAG_OVERLAPPED;
pflags |= FILE_FLAG_OVERLAPPED;
HANDLE inputHandle = ::CreateNamedPipe(ss.str().c_str(),
pflags,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE | PIPE_WAIT,
1,
256,
256,
1000,
NULL );
if (inputHandle == INVALID_HANDLE_VALUE)
throw SystemError("Could not create named pipe");
HANDLE outputHandle = ::CreateFile(ss.str().c_str(), access, share, NULL, create, flags, NULL);
if(outputHandle == INVALID_HANDLE_VALUE)
throw SystemError("Could not open file handle");
_out.open(inputHandle);
_in.open(outputHandle);
InterlockedIncrement(&_nameId);
}
示例5: strerror
void AtasmartSensorDriver::read_temps() const
{
SkBool disk_sleeping = false;
if (unlikely(dnd_disk && (sk_disk_check_sleep_mode(disk_, &disk_sleeping) < 0))) {
string msg = strerror(errno);
throw SystemError("sk_disk_check_sleep_mode(" + path_ + "): " + msg);
}
if (unlikely(disk_sleeping)) {
temp_state.add_temp(0);
}
else {
uint64_t mKelvin;
double tmp;
if (unlikely(sk_disk_smart_read_data(disk_) < 0)) {
string msg = strerror(errno);
throw SystemError("sk_disk_smart_read_data(" + path_ + "): " + msg);
}
if (unlikely(sk_disk_smart_get_temperature(disk_, &mKelvin)) < 0) {
string msg = strerror(errno);
throw SystemError("sk_disk_smart_get_temperature(" + path_ + "): " + msg);
}
tmp = mKelvin / 1000.0f;
tmp -= 273.15f;
if (unlikely(tmp > std::numeric_limits<int>::max() || tmp < std::numeric_limits<int>::min())) {
throw SystemError(MSG_T_GET(path_) + std::to_string(tmp) + " isn't a valid temperature.");
}
temp_state.add_temp(tmp);
}
}
示例6: FanDriver
TpFanDriver::TpFanDriver(const std::string &path)
: FanDriver(path, 120)
{
bool ctrl_supported = false;
std::fstream f(path_);
try {
f.exceptions(f.failbit | f.badbit);
std::string line;
line.resize(256);
f.exceptions(f.badbit);
while ( f.getline(&*line.begin(), 255)) {
if (line.rfind("level:") != string::npos) {
// remember initial level, restore it in d'tor
initial_state_ = line.substr(line.find_last_of(" \t") + 1);
}
else if (line.rfind("commands:") != std::string::npos && line.rfind("level <level>") != std::string::npos) {
ctrl_supported = true;
}
}
} catch (std::ios_base::failure &e) {
string msg = std::strerror(errno);
throw SystemError(MSG_FAN_INIT(path_) + msg);
}
if (!ctrl_supported) throw SystemError(MSG_FAN_MODOPTS);
}
示例7: InitNetworkSystem
/////////////////////
// Initializes network
bool InitNetworkSystem() {
curl_global_init(CURL_GLOBAL_ALL);
nlSystemUseChangeLock.startWriteAccess();
bNetworkInited = false;
if(!nlInit()) {
SystemError("nlInit failed");
nlSystemUseChangeLock.endWriteAccess();
return false;
}
if(!nlSelectNetwork(NL_IP)) {
SystemError("could not select IP-based network");
nlSystemUseChangeLock.endWriteAccess();
return false;
}
bNetworkInited = true;
dnsCache = new ThreadVar<dnsCacheT>();
#ifndef WIN32
//sigignore(SIGPIPE);
signal(SIGPIPE, sigpipe_handler);
#endif
nlSystemUseChangeLock.endWriteAccess();
return true;
}
示例8: env
inline void
env(const Bytes& variable, const Bytes& value)
{
Bytes xvalue = env(variable);
char* varbuffer = variable.nullstr();
char* valbuffer = value.nullstr();
char* xvalbuffer = xvalue.nullstr();
#if (QUIRINUS_FEATURE_POSIX)
int state = 0;
state = ::setenv(varbuffer, valbuffer, true);
if (state)
{
state = static_cast<int>(errno);
::setenv(varbuffer, xvalbuffer, true);
throw SystemError(state);
}
#else
DWORD state = 0;
state = ::SetEnvironmentVariableA(varbuffer, valbuffer);
state = ((!state) ? ::GetLastError() : 0);
if (state)
{
state = ::GetLastError();
::SetEnvironmentVariableA(varbuffer, xvalbuffer);
throw SystemError(state);
}
#endif
delete[] varbuffer;
delete[] valbuffer;
delete[] xvalbuffer;
}
示例9: SetThreadAffinityMask
ClockImpl::ClockImpl()
{
//DWORD procAffinity;
//DWORD sysAffinity;
DWORD_PTR cpuMask = 0x01;
#ifndef _WIN32_WCE
// HANDLE currentProcessHandle = GetCurrentProcess();
// if( ! GetProcessAffinityMask( currentProcessHandle, &procAffinity, &sysAffinity ))
// throw SystemError( PT_ERROR_MSG("GetProcessAffinityMask failed") );
// if( ! SetProcessAffinityMask( currentProcessHandle, 0x01 ) )
// throw SystemError( PT_ERROR_MSG("SetProcessAffinityMask failed") );
DWORD_PTR threadAffinity = SetThreadAffinityMask( GetCurrentThread(), cpuMask );
if( ! threadAffinity )
throw SystemError( PT_ERROR_MSG("SetProcessAffinityMask failed") );
#endif
if( ! QueryPerformanceFrequency( &_frequency ) )
throw SystemError( PT_ERROR_MSG("QueryPerformanceFrequency failed") );
#ifndef _WIN32_WCE
// if( ! SetProcessAffinityMask( currentProcessHandle, procAffinity ) )
// throw SystemError( PT_ERROR_MSG("SetProcessAffinityMask failed") );
if( ! SetThreadAffinityMask( GetCurrentThread(), threadAffinity ) )
throw SystemError( PT_ERROR_MSG("SetProcessAffinityMask failed") );
#endif
}
示例10: SystemError
SessionKey::SessionKey()
{
// acquire cryptographic provider
if (!CryptAcquireContextA(&m_provider.get_ref(), 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
throw SystemError(GetLastError());
// generate session key
if (!CryptGenKey(m_provider.get(), CALG_RC2, 0, &m_key.get_ref()))
throw SystemError(GetLastError());
}
示例11: fd
TcpStream TcpStream::connect(const Ipv6Address& address)
{
Descriptor fd(socket(AF_INET6, SOCK_STREAM, 0));
if (fd < 0)
{
throw SystemError("IPv6 socket error");
}
if (::connect(fd, address.address(), address.length()) < 0)
{
throw SystemError("IPv6 connect error");
}
return TcpStream(std::move(fd));
}
示例12: SystemError
// static
TimePoint Clock::Now() {
LARGE_INTEGER freq;
if (QueryPerformanceFrequency(&freq) == 0) {
throw SystemError("QueryPerformanceFrequency");
}
double ns_per_tick = 1E+9 / freq.QuadPart;
LARGE_INTEGER count;
if (QueryPerformanceCounter(&count) == 0) {
throw SystemError("QueryPerformanceCounter");
}
return Nanoseconds(ns_per_tick * count.QuadPart);
}
示例13: Init_Env
void
Init_Env(GMC_ARG_VOID)
{
tps_FileName FileName;
boolean Abort;
size_t sz;
OdinDirName = GetEnv("ODINCACHE");
FORBIDDEN(OdinDirName == NIL);
if (!IsDirectory_FileName(OdinDirName)) {
SystemError("Odin root <%s> does not exist.\n", OdinDirName);
FATALERROR("");}/*if*/;
if (OdinDirName[0] != '/') {
SystemError("Odin cache pathname <%s> must be absolute.\n", OdinDirName);
FATALERROR("");}/*if*/;
Set_ModeMask(OdinDirName);
sz = snprintf(FileName, MAX_FileName, "%s/FILES", OdinDirName);
if (sz >= MAX_FileName) {
(void)fprintf(stderr, "File name too long (MAX_FileName=%d): %s/FILES\n",
MAX_FileName, OdinDirName);
exit(1); }/*if*/;
CacheDirName = Malloc_Str(FileName);
MakeDirFile(&Abort, CacheDirName);
if (Abort) FATALERROR("cannot create odin FILES directory");
sz = snprintf(FileName, MAX_FileName, "%s/JOBS", OdinDirName);
if (sz >= MAX_FileName) {
(void)fprintf(stderr, "File name too long (MAX_FileName=%d): %s/JOBS\n",
MAX_FileName, OdinDirName);
exit(1); }/*if*/;
JobsDirName = Malloc_Str(FileName);
MakeDirFile(&Abort, JobsDirName);
if (Abort) FATALERROR("cannot create odin JOBS directory");
sz = snprintf(FileName, MAX_FileName, "%s/ENV", OdinDirName);
if (sz >= MAX_FileName) {
(void)fprintf(stderr, "File name too long (MAX_FileName=%d): %s/ENV\n",
MAX_FileName, OdinDirName);
exit(1); }/*if*/;
Read_Env(FileName);
DumpCore = (GetEnv("DUMPCORE") != NIL);
RBS_Cmd = GetEnv("ODIN_RBSCMD");
FORBIDDEN(RBS_Cmd == NIL);
ShortCacheNameFlag = (GetEnv("ODIN_SHORTNAMES") != NIL);
LocalIPCFlag = (GetEnv("ODIN_LOCALIPC") != NIL);
}/*Init_Env*/
示例14: _LoadPythonDLL
BOOL _LoadPythonDLL(HMODULE hmod)
{
HRSRC hrsrc;
char *pBaseAddress;
int size;
if (!dirname[0])
calc_dirname(hmod);
// Try to locate pythonxy.dll as resource in the exe
hrsrc = FindResource(hmod, MAKEINTRESOURCE(1), PYTHONDLL);
if (hrsrc) {
HGLOBAL hgbl = LoadResource(hmod, hrsrc);
if (!_load_python(PYTHONDLL, LockResource(hgbl))) {
SystemError(GetLastError(), "Could not load python dll");
return FALSE;
}
// dprintf("Loaded pythondll as RESOURCE\n");
return TRUE;
}
// try to load pythonxy.dll as bytes at the start of the zipfile
pBaseAddress = MapExistingFile(libfilename, &size);
if (pBaseAddress) {
int res = 0;
if (0 == strncmp(pBaseAddress, "<pythondll>", 11))
res = _load_python(PYTHONDLL, pBaseAddress + 11 + sizeof(int));
UnmapViewOfFile(pBaseAddress);
if (res) {
// dprintf("Loaded pythondll as <pythondll> from %s\n", libfilename);
return TRUE;
}
}
// try to load pythonxy.dll from the file system
{
char buffer[_MAX_PATH + _MAX_FNAME + _MAX_EXT];
snprintf(buffer, sizeof(buffer), "%s\\%s", dirname, PYTHONDLL);
if (!_load_python(buffer, NULL)) {
SystemError(GetLastError(), "LoadLibrary(pythondll) failed");
SystemError(0, buffer);
return FALSE;
}
// dprintf("Loaded pythondll from file %s\n", buffer);
}
return TRUE;
}
示例15: GMC_DCL
GMC_DCL(tp_FilPrm, FilPrm)
{
tp_FilHdr ValFilHdr;
tp_FilTyp FilTyp;
tp_DrvPth DrvPth, DrvPthElm;
tp_PrmTypLst PrmTypLst;
Writeln(FilDsc, "*?* Possible Parameters :");
Clr_PrmTypMarks();
if (FilPrm == RootFilPrm) {
SetFilHdr_PrmTypMarks(FilHdr);
WriteMarkedPrmTyps(FilDsc);
return; }/*if*/;
ValFilHdr = LocHdr_FilHdr(FilPVal_LocHdr(FilPrm_FilPVal(FilPrm)));
FilTyp = FTName_FilTyp(FilHdr_Ident(ValFilHdr));
Ret_FilHdr(ValFilHdr);
if (FilTyp == ERROR) {
return; }/*if*/;
if (FilHdr_FilTyp(FilHdr) != FilTyp) {
DrvPth = Get_DrvPth(FilHdr, FilTyp);
if (DrvPth == ERROR) {
SystemError("Cannot derive to <%s>\n", FilTyp_FTName(FilTyp));
return; }/*if*/;
for (DrvPthElm = DrvPth;
DrvPthElm != NIL;
DrvPthElm = DrvPth_Next(DrvPthElm)) {
if (DrvPth_DPType(DrvPthElm) == DPT_Drv) {
PrmTypLst = DrvPth_PrmTypLst(DrvPthElm);
SetPrmTypLst_Marks(PrmTypLst); }/*if*/; }/*for*/;
Ret_DrvPth(DrvPth); }/*if*/;
WriteMarkedPrmTyps(FilDsc);
}/*WritePrmHelp*/