本文整理汇总了C++中MapError函数的典型用法代码示例。如果您正苦于以下问题:C++ MapError函数的具体用法?C++ MapError怎么用?C++ MapError使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MapError函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: name
int CEnvironment::setenv(const wchar_t* aName, const wchar_t* aValue, int aReplace, int& anErrno)
{
TPtrC16 name((TText16*)aName);
TUint freeSlot=iCount;
TEnvVar* ep=iVars;
for (TUint i=0; i<iCount; ++i,++ep)
{
if (ep->NotEmpty())
{
const TDesC16* existing=ep->Match(name);
if (existing)
{
TInt err=KErrNone;
if (aReplace)
ep->SetValue(aValue);
return MapError(err,anErrno);
}
}
else
freeSlot=i;
}
if (freeSlot==iCount)
{
// no free slots, time to grow the array
ep=(TEnvVar*)User::ReAlloc(iVars,(iCount+1)*sizeof(TEnvVar));
if (ep==0)
return KErrNoMemory;
iVars=ep;
++iCount;
}
TRAPD(ret,iVars[freeSlot].ConstructL(name,aValue));
return MapError(ret,anErrno);
}
示例2: RWTryLockWrite
rwlock_error_t RWTryLockWrite(rwlock_t *RWLock)
{
if (!RWLock) return RW_LOCK_ERROR_INVALID;
#if RW_LOCK_USES_POSIX_LOCKS
int err;
if ((err = pthread_mutex_trylock(&RWLock->monitorLock)))
{
if (RWLock->destroyed) return RW_LOCK_ERROR_INVALID;
return MapError(err);
}
if (!RWLock->destroyed)
{
pthread_t Self = pthread_self();
if (RWLock->writerThread != Self)
{
if ((err = pthread_mutex_trylock(&RWLock->lock)))
{
pthread_mutex_unlock(&RWLock->monitorLock);
if (RWLock->destroyed) return RW_LOCK_ERROR_INVALID;
return MapError(err);
}
RWLock->writerThread = Self;
}
RWLock->lockCount++;
}
pthread_mutex_unlock(&RWLock->monitorLock);
#endif
return RW_LOCK_SUCCESS; //lies when no locks are supported
}
示例3: get_string
STDMETHODIMP CDisk::put_comment(BSTR newVal)
{
char *buf;
dsk_err_t err;
buf = get_string(newVal);
if (!buf) return MapError(DSK_ERR_NOMEM);
err = dsk_set_comment(m_driver, buf);
dsk_free(buf);
return MapError(err);
}
示例4: NPT_SetMemory
/*----------------------------------------------------------------------
| NPT_Zip::Deflate
+---------------------------------------------------------------------*/
NPT_Result
NPT_Zip::Deflate(const NPT_DataBuffer& in,
NPT_DataBuffer& out,
int compression_level,
Format format /* = ZLIB */)
{
// default return state
out.SetDataSize(0);
// check parameters
if (compression_level < NPT_ZIP_COMPRESSION_LEVEL_DEFAULT ||
compression_level > NPT_ZIP_COMPRESSION_LEVEL_MAX) {
return NPT_ERROR_INVALID_PARAMETERS;
}
// setup the stream
z_stream stream;
NPT_SetMemory(&stream, 0, sizeof(stream));
stream.next_in = (Bytef*)in.GetData();
stream.avail_in = (uInt)in.GetDataSize();
// setup the memory functions
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
// initialize the compressor
int err = deflateInit2(&stream,
compression_level,
Z_DEFLATED,
15 + (format == GZIP ? 16 : 0),
8,
Z_DEFAULT_STRATEGY);
if (err != Z_OK) return MapError(err);
// reserve an output buffer known to be large enough
out.Reserve(deflateBound(&stream, stream.avail_in) + (format==GZIP?10:0));
stream.next_out = out.UseData();
stream.avail_out = out.GetBufferSize();
// decompress
err = deflate(&stream, Z_FINISH);
if (err != Z_STREAM_END) {
deflateEnd(&stream);
return MapError(err);
}
// update the output size
out.SetDataSize(stream.total_out);
// cleanup
err = deflateEnd(&stream);
return MapError(err);
}
示例5: NPT_CHECK_WARNING
/*----------------------------------------------------------------------
| NPT_Zip::Inflate
+---------------------------------------------------------------------*/
NPT_Result
NPT_Zip::Inflate(const NPT_DataBuffer& in,
NPT_DataBuffer& out,
bool raw)
{
// assume an output buffer twice the size of the input plus a bit
NPT_CHECK_WARNING(out.Reserve(32+2*in.GetDataSize()));
// setup the stream
z_stream stream;
stream.next_in = (Bytef*)in.GetData();
stream.avail_in = (uInt)in.GetDataSize();
stream.next_out = out.UseData();
stream.avail_out = (uInt)out.GetBufferSize();
// setup the memory functions
stream.zalloc = (alloc_func)0;
stream.zfree = (free_func)0;
stream.opaque = (voidpf)0;
// initialize the decompressor
int err = inflateInit2(&stream, raw?-15:15+32); // 15 = default window bits, +32 = automatic header
if (err != Z_OK) return MapError(err);
// decompress until the end
do {
err = inflate(&stream, Z_SYNC_FLUSH);
if (err == Z_STREAM_END || err == Z_OK || err == Z_BUF_ERROR) {
out.SetDataSize((NPT_Size)stream.total_out);
if ((err == Z_OK && stream.avail_out == 0) || err == Z_BUF_ERROR) {
// grow the output buffer
out.Reserve(out.GetBufferSize()*2);
stream.next_out = out.UseData()+stream.total_out;
stream.avail_out = out.GetBufferSize()-(NPT_Size)stream.total_out;
}
}
} while (err == Z_OK);
// check for errors
if (err != Z_STREAM_END) {
inflateEnd(&stream);
return MapError(err);
}
// cleanup
err = inflateEnd(&stream);
return MapError(err);
}
示例6: gethostname
/**
Get the internet name of this host. Actually this will always return a null
string with TCPIP 030 and onwards because the "name" of a mobile host
isn't really very meaningful - in practice the IP address is chosen dynamically
once you start doing real networking, at which time the ISP can resolve the
IP address into a name of some sort if you really want.
@return
@param name
@param size
*/
EXPORT_C int gethostname (char *name, size_t size)
{
int* perrno=__errno();
RSocketServ ss;
TInt err=ss.Connect(1);
if (err==KErrNone)
{
RHostResolver r;
err=r.Open(ss, AF_INET, KProtocolInetUdp);
if (err==KErrNone)
{
TBuf<128> hostname;
err=r.GetHostName(hostname);
if (err==KErrNone)
{
if (size>(size_t)hostname.Length())
{
TPtr8 retval((TText8*)name,size);
retval.Copy(hostname);
retval.PtrZ();
}
else
err=ENAMETOOLONG;
}
r.Close();
}
ss.Close();
}
return MapError(err,*perrno);
}
示例7: RWLockDestroy
rwlock_error_t RWLockDestroy(rwlock_t *RWLock)
{
if (!RWLock) return RW_LOCK_ERROR_INVALID;
#if RW_LOCK_USES_POSIX_LOCKS
//don't care about most fails
int err;
if ((err = pthread_mutex_lock(&RWLock->monitorLock)))
{
if (RWLock->destroyed) return RW_LOCK_ERROR_INVALID;
return MapError(err);
}
RWLock->destroyed = TRUE;
//wait and let any locks get finished up
pthread_mutex_unlock(&RWLock->monitorLock);
pthread_mutex_lock(&RWLock->lock);
pthread_mutex_lock(&RWLock->monitorLock);
pthread_mutex_unlock(&RWLock->lock);
pthread_mutex_destroy(&RWLock->lock);
pthread_mutex_unlock(&RWLock->monitorLock);
pthread_mutex_destroy(&RWLock->monitorLock);
#endif
return RW_LOCK_SUCCESS; //lies when no locks are supported
}
示例8: RWUnlockRead
rwlock_error_t RWUnlockRead(rwlock_t *RWLock)
{
if (!RWLock) return RW_LOCK_ERROR_INVALID;
#if RW_LOCK_USES_POSIX_LOCKS
int err;
if ((err = pthread_mutex_lock(&RWLock->monitorLock)))
{
if (RWLock->destroyed) return RW_LOCK_ERROR_INVALID;
return MapError(err);
}
rwlock_error_t Error = RW_LOCK_SUCCESS;
//if (!RWLock->destroyed)
{
if ((!RWLock->writerThread) || (RWLock->writerThread == pthread_self()))
{
if (!--RWLock->lockCount)
{
RWLock->writerThread = NULL;
pthread_mutex_unlock(&RWLock->lock);
}
}
else Error = RW_LOCK_ERROR_INVALID;
}
//else Error = RW_LOCK_ERROR_INVALID;
pthread_mutex_unlock(&RWLock->monitorLock);
return Error;
#endif
return RW_LOCK_SUCCESS; //lies when no locks are supported
}
示例9: dsk_get_retry
STDMETHODIMP CDisk::get_retries(short *pVal)
{
unsigned r;
dsk_err_t err = dsk_get_retry(m_driver, &r);
*pVal = r;
return MapError(err);
}
示例10: g_to_dg
STDMETHODIMP CDisk::ltrkid(IGeometry *g, long track, short *count, VARIANT *buffer)
{
DSK_GEOMETRY geom;
DSK_FORMAT *fmt;
unsigned char *buf;
dsk_err_t err;
dsk_psect_t n, acount = 0;
HRESULT hr;
g_to_dg(g, &geom);
err = dsk_ltrackids(m_driver, &geom, track, &acount, &fmt);
if (acount)
{
if (count) *count = acount;
buf = new unsigned char[4 * acount];
for (n = 0; n < acount; n++)
{
buf[n*4 ] = fmt[n].fmt_cylinder;
buf[n*4+1] = fmt[n].fmt_head;
buf[n*4+2] = fmt[n].fmt_sector;
buf[n*4+3] = dsk_get_psh(fmt[n].fmt_secsize);
}
hr = PutBuffer(buf, buffer, 4 * acount, err);
delete buf;
return hr;
}
return MapError(err);
}
示例11: MapError
STDMETHODIMP CGeometry::pt2lt(long cyl, short head, long *lsect)
{
dsk_ltrack_t lt;
HRESULT hr = MapError(dg_pt2lt(&m_g, cyl, head, <));
*lsect = lt;
return hr;
}
示例12: FindFirstFileW
/*----------------------------------------------------------------------
| NPT_File::ListDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::ListDir(const char* path,
NPT_List<NPT_String>& entries,
NPT_Ordinal start /* = 0 */,
NPT_Cardinal max /* = 0 */)
{
NPT_WIN32_USE_CHAR_CONVERSION;
// default return value
entries.Clear();
// check the arguments
if (path == NULL || path[0] == '\0') return NPT_ERROR_INVALID_PARAMETERS;
// construct a path name with a \* wildcard at the end
NPT_String path_pattern = path;
if (path_pattern.EndsWith("\\") || path_pattern.EndsWith("/")) {
path_pattern += "*";
} else {
path_pattern += "\\*";
}
// list the entries
WIN32_FIND_DATAW find_data;
HANDLE find_handle = FindFirstFileW(NPT_WIN32_A2W(path_pattern.GetChars()), &find_data);
if (find_handle == INVALID_HANDLE_VALUE) return MapError(GetLastError());
NPT_Cardinal count = 0;
do {
if (NPT_File_ProcessFindData(&find_data)) {
// continue if we still have entries to skip
if (start > 0) {
--start;
continue;
}
entries.Add(NPT_WIN32_W2A(find_data.cFileName));
// stop when we have reached the maximum requested
if (max && ++count == max) return NPT_SUCCESS;
}
} while (FindNextFileW(find_handle, &find_data));
DWORD last_error = GetLastError();
FindClose(find_handle);
if (last_error != ERROR_NO_MORE_FILES) return MapError(last_error);
return NPT_SUCCESS;
}
示例13: dsk_get_comment
STDMETHODIMP CDisk::get_comment(BSTR *pVal)
{
char *cmt = NULL;
dsk_err_t err = dsk_get_comment(m_driver, &cmt);
if (cmt) *pVal = ret_string(cmt);
return MapError(err);
}
示例14: RemoveDirectoryW
/*----------------------------------------------------------------------
| NPT_File::RemoveDir
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::RemoveDir(const char* path)
{
NPT_WIN32_USE_CHAR_CONVERSION;
BOOL result = RemoveDirectoryW(NPT_WIN32_A2W(path));
if (result == 0) {
return MapError(GetLastError());
}
return NPT_SUCCESS;
}
示例15: MoveFileW
/*----------------------------------------------------------------------
| NPT_File::Rename
+---------------------------------------------------------------------*/
NPT_Result
NPT_File::Rename(const char* from_path, const char* to_path)
{
NPT_WIN32_USE_CHAR_CONVERSION;
BOOL result = MoveFileW(NPT_WIN32_A2W(from_path), NPT_WIN32_A2W(to_path));
if (result == 0) {
return MapError(GetLastError());
}
return NPT_SUCCESS;
}