本文整理汇总了C++中xstrerror函数的典型用法代码示例。如果您正苦于以下问题:C++ xstrerror函数的具体用法?C++ xstrerror怎么用?C++ xstrerror使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xstrerror函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: bfd_errmsg
const char *
bfd_errmsg (bfd_error_type error_tag)
{
#ifndef errno
extern int errno;
#endif
if (error_tag == bfd_error_system_call)
return xstrerror (errno);
if (error_tag > bfd_error_invalid_error_code)
error_tag = bfd_error_invalid_error_code; /* sanity check */
return _(bfd_errmsgs [error_tag]);
}
示例2: genkeys
// generate public/private key pair for digital signatures
void genkeys (void)
{
if (open_crypt())
{
if (CryptGenKey (hProv, AT_SIGNATURE,
keylen<<16 | CRYPT_EXPORTABLE, &hKey))
{
// export as C array and binary
export_key (PUBLICKEYBLOB, RSA_PUBLIC_H, RSA_C_ARRAY);
export_key (PUBLICKEYBLOB, RSA_PUBLIC_BIN, RSA_BINARY);
export_key (PRIVATEKEYBLOB, RSA_PRIVATE_H, RSA_C_ARRAY);
export_key (PRIVATEKEYBLOB, RSA_PRIVATE_BIN, RSA_BINARY);
close_key();
} else {
xstrerror ("CryptGenKey(%i)", keylen);
}
close_crypt();
} else {
xstrerror ("CryptAcquireContext()");
}
}
示例3: netdbSaveState
static void
netdbSaveState(void *foo)
{
Logfile *lf;
netdbEntry *n;
net_db_name *x;
struct timeval start = current_time;
int count = 0;
if (strcmp(Config.netdbFilename, "none") == 0)
return;
/*
* This was nicer when we were using stdio, but thanks to
* Solaris bugs, its a bad idea. fopen can fail if more than
* 256 FDs are open.
*/
/*
* unlink() is here because there is currently no way to make
* logfileOpen() use O_TRUNC.
*/
unlink(Config.netdbFilename);
lf = logfileOpen(Config.netdbFilename, 4096, 0);
if (NULL == lf) {
debug(50, 1) ("netdbSaveState: %s: %s\n", Config.netdbFilename, xstrerror());
return;
}
hash_first(addr_table);
while ((n = (netdbEntry *) hash_next(addr_table))) {
if (n->pings_recv == 0)
continue;
logfilePrintf(lf, "%s %d %d %10.5f %10.5f %d %d",
n->network,
n->pings_sent,
n->pings_recv,
n->hops,
n->rtt,
(int) n->next_ping_time,
(int) n->last_use_time);
for (x = n->hosts; x; x = x->next)
logfilePrintf(lf, " %s", hashKeyStr(&x->hash));
logfilePrintf(lf, "\n");
count++;
#undef RBUF_SZ
}
logfileClose(lf);
getCurrentTime();
debug(38, 1) ("NETDB state saved; %d entries, %d msec\n",
count, tvSubMsec(start, current_time));
eventAddIsh("netdbSaveState", netdbSaveState, NULL, 3600.0, 1);
}
示例4: whoisReadReply
static void
whoisReadReply(int fd, void *data)
{
WhoisState *p = data;
StoreEntry *entry = p->entry;
char *buf = memAllocate(MEM_4K_BUF);
MemObject *mem = entry->mem_obj;
int len;
statCounter.syscalls.sock.reads++;
len = FD_READ_METHOD(fd, buf, 4095);
buf[len] = '\0';
debug(75, 3) ("whoisReadReply: FD %d read %d bytes\n", fd, len);
debug(75, 5) ("{%s}\n", buf);
if (len > 0) {
if (0 == mem->inmem_hi) {
http_reply *reply = mem->reply;
storeBuffer(entry);
httpReplySetHeaders(reply, HTTP_OK, "Gatewaying", "text/plain", -1, -1, -1);
httpReplySwapOut(reply, entry);
}
fd_bytes(fd, len, FD_READ);
kb_incr(&statCounter.server.all.kbytes_in, len);
kb_incr(&statCounter.server.http.kbytes_in, len);
storeAppend(entry, buf, len);
storeBufferFlush(entry);
commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read);
} else if (len < 0) {
debug(50, 2) ("whoisReadReply: FD %d: read failure: %s.\n",
fd, xstrerror());
if (ignoreErrno(errno)) {
commSetSelect(fd, COMM_SELECT_READ, whoisReadReply, p, Config.Timeout.read);
} else {
ErrorState *err;
err = errorCon(ERR_READ_ERROR, HTTP_BAD_GATEWAY, p->fwd->request);
err->xerrno = errno;
fwdFail(p->fwd, err);
comm_close(fd);
}
} else {
storeTimestampsSet(entry);
storeBufferFlush(entry);
if (!EBIT_TEST(entry->flags, RELEASE_REQUEST))
storeSetPublicKey(entry);
fwdComplete(p->fwd);
debug(75, 3) ("whoisReadReply: Done: %s\n", storeUrl(entry));
comm_close(fd);
}
memFree(buf, MEM_4K_BUF);
}
示例5: is_dir
/* Return 1 if the file is a directory, 0 if not, -1 on error. */
int is_dir (const char *file)
{
struct stat file_stat;
if (is_url (file))
return 0;
if (stat (file, &file_stat) == -1) {
char *err = xstrerror (errno);
error ("Can't stat %s: %s", file, err);
free (err);
return -1;
}
return S_ISDIR(file_stat.st_mode) ? 1 : 0;
}
示例6: client
// connect to server
void client(args_t *p)
{
spp_ctx c;
int term=0;
do
{
spp_init(&c, SPP_CLIENT);
// create socket
p->s=socket(p->ai_family, SOCK_STREAM, IPPROTO_TCP);
if (p->s!=SOCKET_ERROR)
{
printf ("[ connecting to %s\n", addr2ip(p));
if (connect (p->s, p->ai_addr, p->ai_addrlen)!=SOCKET_ERROR)
{
printf ("[ connected\n");
c.s=p->s;
printf ("[ performing key exchange\n");
if (spp_handshake(&c))
{
term = dispatch(&c);
printf ("[ closing connection\n");
} else xstrerror("");
} else {
xstrerror ("connect");
}
shutdown (p->s, SD_BOTH);
closesocket (p->s);
}
if (!term) {
Sleep (2000); // sleep for 2 seconds, then try again
}
spp_end(&c);
} while (!term);
}
示例7: logfileWriteWrapper
/*
* Aborts with fatal message if write() returns something other
* than its length argument.
*/
static void
logfileWriteWrapper(Logfile * lf, const void *buf, size_t len)
{
l_stdio_t *ll = (l_stdio_t *) lf->data;
size_t s;
s = FD_WRITE_METHOD(ll->fd, (char const *) buf, len);
fd_bytes(ll->fd, s, FD_WRITE);
if (s == len)
return;
if (!lf->flags.fatal)
return;
fatalf("logfileWrite (stdio): %s: %s\n", lf->path, xstrerror());
}
示例8: storeUfsCreate
storeIOState *
storeUfsCreate(SwapDir * SD, StoreEntry * e, STFNCB * file_callback, STIOCB * callback, void *callback_data)
{
storeIOState *sio;
int fd;
int mode = (O_WRONLY | O_CREAT | O_TRUNC | O_BINARY);
char *path;
ufsinfo_t *ufsinfo = (ufsinfo_t *) SD->fsdata;
sfileno filn;
sdirno dirn;
/* Allocate a number */
dirn = SD->index;
filn = storeUfsDirMapBitAllocate(SD);
ufsinfo->suggest = filn + 1;
/* Shouldn't we handle a 'bitmap full' error here? */
path = storeUfsDirFullPath(SD, filn, NULL);
debug(79, 3) ("storeUfsCreate: fileno %08X\n", filn);
fd = file_open(path, mode);
if (fd < 0) {
debug(79, 1) ("storeUfsCreate: Failed to create %s (%s)\n", path, xstrerror());
return NULL;
}
debug(79, 3) ("storeUfsCreate: opened FD %d\n", fd);
CBDATA_INIT_TYPE_FREECB(storeIOState, storeUfsIOFreeEntry);
sio = cbdataAlloc(storeIOState);
sio->fsstate = memPoolAlloc(ufs_state_pool);
sio->swap_filen = filn;
sio->swap_dirn = dirn;
sio->mode = mode;
sio->callback = callback;
sio->callback_data = callback_data;
cbdataLock(callback_data);
sio->e = (StoreEntry *) e;
((ufsstate_t *) (sio->fsstate))->fd = fd;
((ufsstate_t *) (sio->fsstate))->flags.writing = 0;
((ufsstate_t *) (sio->fsstate))->flags.reading = 0;
((ufsstate_t *) (sio->fsstate))->flags.close_request = 0;
store_open_disk_fd++;
ufsinfo->open_files++;
/* now insert into the replacement policy */
storeUfsDirReplAdd(SD, e);
return sio;
}
示例9: a_file_read
void
a_file_read(async_queue_t * q, int fd, void *buf, int req_len, off_t offset,
DRCB * callback, void *data)
{
int slot;
async_queue_entry_t *qe;
assert(q->aq_state == AQ_STATE_SETUP);
assert(offset >= 0);
/* Find a free slot */
slot = a_file_findslot(q);
if (slot < 0) {
/* No free slot? Callback error, and return */
debug(79, 1) ("WARNING: out of aiocb slots!\n");
/* fall back to blocking method */
file_read(fd, buf, req_len, offset, callback, data);
return;
}
/* Mark slot as ours */
qe = &q->aq_queue[slot];
qe->aq_e_state = AQ_ENTRY_USED;
qe->aq_e_callback.read = callback;
qe->aq_e_callback_data = data;
qe->aq_e_type = AQ_ENTRY_READ;
qe->aq_e_free = NULL;
qe->aq_e_buf = buf;
qe->aq_e_fd = fd;
qe->aq_e_aiocb.aio_fildes = fd;
qe->aq_e_aiocb.aio_nbytes = req_len;
qe->aq_e_aiocb.aio_offset = offset;
qe->aq_e_aiocb.aio_buf = buf;
/* Account */
q->aq_numpending++;
/* Lock */
cbdataLock(data);
/* Initiate aio */
if (aio_read(&qe->aq_e_aiocb) < 0) {
debug(79, 1) ("WARNING: aio_read() returned error: %s\n", xstrerror());
/* fall back to blocking method */
file_read(fd, buf, req_len, offset, callback, data);
}
}
示例10: open_tcp
// Resolve host, create socket and event handle associated with it
BOOL open_tcp (void)
{
struct addrinfo *list, *e;
struct addrinfo hints;
BOOL bStatus=FALSE;
WSADATA wsa;
int on=1;
WSAStartup (MAKEWORD (2, 0), &wsa);
ZeroMemory (&hints, sizeof (hints));
hints.ai_family = args.ai_family;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
// get all resolvable addresses for this machine name
if (getaddrinfo (args.address, args.port, &hints, &list) == 0)
{
for (e=list; e!=NULL; e=e->ai_next)
{
if (args.ai_family==AF_INET) {
memcpy (&sin_ipv4, e->ai_addr, e->ai_addrlen);
ai_addr = (SOCKADDR*)&sin_ipv4;
} else {
memcpy (&sin_ipv6, e->ai_addr, e->ai_addrlen);
ai_addr = (SOCKADDR*)&sin_ipv6;
}
ai_addrlen = e->ai_addrlen;
// create socket
s=socket (args.ai_family, SOCK_STREAM, IPPROTO_TCP);
evt[sck_evt = evt_cnt++] = WSACreateEvent();
if (s!=SOCKET_ERROR) {
// ensure we can reuse same port later
setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (char*)&on, sizeof (on));
bStatus=TRUE;
}
break;
}
freeaddrinfo (list);
} else {
xstrerror ("getaddrinfo(%s)", args.address);
}
return bStatus;
}
示例11: assert
static struct value *sys_read_file(struct info *info, struct value *n) {
assert(n->tag == V_STRING);
char *str = NULL;
str = xread_file(n->string->str);
if (str == NULL) {
char error_buf[1024];
const char *errmsg;
errmsg = xstrerror(errno, error_buf, sizeof(error_buf));
struct value *exn = make_exn_value(ref(info),
"reading file %s failed:", n->string->str);
exn_printf_line(exn, "%s", errmsg);
return exn;
}
struct value *v = make_value(V_STRING, ref(info));
v->string = make_string(str);
return v;
}
示例12: logfile_mod_udp_write
static void
logfile_mod_udp_write(Logfile * lf, const char *buf, size_t len)
{
l_udp_t *ll = (l_udp_t *) lf->data;
ssize_t s;
s = write(ll->fd, (char const *) buf, len);
fd_bytes(ll->fd, s, FD_WRITE);
#if 0
if (s < 0) {
debug(1, 1) ("logfile (udp): got errno %d (%s)\n", errno, xstrerror());
}
if (s != len) {
debug(1, 1) ("logfile (udp): len %d, wrote %d\n", len, s);
}
#endif
/* We don't worry about network errors for now */
}
示例13: do_comm_select
static int
do_comm_select(int msec)
{
int num, saved_errno;
struct timeval tv;
fd_set readfds;
fd_set writefds;
fd_set errfds;
int fd;
if (nreadfds + nwritefds == 0) {
assert(shutting_down);
return COMM_SHUTDOWN;
}
memcpy(&readfds, &global_readfds, sizeof(fd_set));
memcpy(&writefds, &global_writefds, sizeof(fd_set));
memcpy(&errfds, &global_writefds, sizeof(fd_set));
tv.tv_sec = msec / 1000;
tv.tv_usec = (msec % 1000) * 1000;
statCounter.syscalls.selects++;
num = select(Biggest_FD + 1, &readfds, &writefds, &errfds, &tv);
saved_errno = errno;
getCurrentTime();
debug(5, 5) ("do_comm_select: %d fds ready\n", num);
if (num < 0) {
if (ignoreErrno(saved_errno))
return COMM_OK;
debug(5, 1) ("comm_select: select failure: %s\n", xstrerror());
return COMM_ERROR;
}
statHistCount(&statCounter.select_fds_hist, num);
if (num == 0)
return COMM_TIMEOUT;
for (fd = 0; fd <= Biggest_FD; fd++) {
int read_event = FD_ISSET(fd, &readfds);
int write_event = FD_ISSET(fd, &writefds) || FD_ISSET(fd, &errfds);
if (read_event || write_event)
comm_call_handlers(fd, read_event, write_event);
}
return COMM_OK;
}
示例14: diskHandleRead
/* Read from FD */
static void
diskHandleRead(int fd, void *data)
{
dread_ctrl *ctrl_dat = data;
fde *F = &fd_table[fd];
int len;
int rc = DISK_OK;
/*
* FD < 0 indicates premature close; we just have to free
* the state data.
*/
if (fd < 0) {
memFree(ctrl_dat, MEM_DREAD_CTRL);
return;
}
if (F->disk.offset != ctrl_dat->file_offset) {
debug(6, 3) ("diskHandleRead: FD %d seeking to offset %d\n",
fd, (int) ctrl_dat->file_offset);
lseek(fd, ctrl_dat->file_offset, SEEK_SET); /* XXX ignore return? */
statCounter.syscalls.disk.seeks++;
F->disk.offset = ctrl_dat->file_offset;
}
errno = 0;
len = FD_READ_METHOD(fd, ctrl_dat->buf, ctrl_dat->req_len);
if (len > 0)
F->disk.offset += len;
statCounter.syscalls.disk.reads++;
fd_bytes(fd, len, FD_READ);
if (len < 0) {
if (ignoreErrno(errno)) {
commSetSelect(fd, COMM_SELECT_READ, diskHandleRead, ctrl_dat, 0);
return;
}
debug(50, 1) ("diskHandleRead: FD %d: %s\n", fd, xstrerror());
len = 0;
rc = DISK_ERROR;
} else if (len == 0) {
rc = DISK_EOF;
}
if (cbdataValid(ctrl_dat->client_data))
ctrl_dat->handler(fd, ctrl_dat->buf, len, rc, ctrl_dat->client_data);
cbdataUnlock(ctrl_dat->client_data);
memFree(ctrl_dat, MEM_DREAD_CTRL);
}
示例15: decoder_error_init
static void *sndfile_open (const char *file)
{
int fd;
struct sndfile_data *data;
data = (struct sndfile_data *)xmalloc (sizeof(struct sndfile_data));
decoder_error_init (&data->error);
memset (&data->snd_info, 0, sizeof(data->snd_info));
data->timing_broken = false;
fd = open (file, O_RDONLY);
if (fd == -1) {
char *err = xstrerror (errno);
decoder_error (&data->error, ERROR_FATAL, 0,
"Can't open file: %s", err);
free (err);
return data;
}
/* sf_open_fd() close()s 'fd' on error and in sf_close(). */
data->sndfile = sf_open_fd (fd, SFM_READ, &data->snd_info, SF_TRUE);
if (!data->sndfile) {
/* FIXME: sf_strerror is not thread safe with NULL argument */
decoder_error (&data->error, ERROR_FATAL, 0,
"Can't open file: %s", sf_strerror(NULL));
return data;
}
/* If the timing is broken, sndfile only decodes up to the broken value. */
data->timing_broken = is_timing_broken (fd, data);
if (data->timing_broken) {
decoder_error (&data->error, ERROR_FATAL, 0,
"File too large for audio format!");
return data;
}
debug ("Opened file %s", file);
debug ("Channels: %d", data->snd_info.channels);
debug ("Format: %08X", data->snd_info.format);
debug ("Sample rate: %d", data->snd_info.samplerate);
return data;
}