本文整理汇总了C++中wperror函数的典型用法代码示例。如果您正苦于以下问题:C++ wperror函数的具体用法?C++ wperror怎么用?C++ wperror使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wperror函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: exec_write_and_exit
// Called in a forked child
static void exec_write_and_exit(int fd, const char *buff, size_t count, int status)
{
if (write_loop(fd, buff, count) == -1)
{
debug(0, WRITE_ERROR);
wperror(L"write");
exit_without_destructors(status);
}
exit_without_destructors(status);
}
示例2: terminal_return_from_job
/// Returns control of the terminal to the shell, and saves the terminal attribute state to the job,
/// so that we can restore the terminal ownership to the job at a later time.
static bool terminal_return_from_job(job_t *j) {
errno = 0;
if (j->pgid == 0) {
debug(2, "terminal_return_from_job() returning early due to no process group");
return true;
}
signal_block();
if (tcsetpgrp(STDIN_FILENO, getpgrp()) == -1) {
if (errno == ENOTTY) redirect_tty_output();
debug(1, _(L"Could not return shell to foreground"));
wperror(L"tcsetpgrp");
signal_unblock();
return false;
}
// Save jobs terminal modes.
if (tcgetattr(STDIN_FILENO, &j->tmodes)) {
if (errno == EIO) redirect_tty_output();
debug(1, _(L"Could not return shell to foreground"));
wperror(L"tcgetattr");
signal_unblock();
return false;
}
// Disabling this per
// https://github.com/adityagodbole/fish-shell/commit/9d229cd18c3e5c25a8bd37e9ddd3b67ddc2d1b72 On
// Linux, 'cd . ; ftp' prevents you from typing into the ftp prompt. See
// https://github.com/fish-shell/fish-shell/issues/121
#if 0
// Restore the shell's terminal modes.
if (tcsetattr(STDIN_FILENO, TCSADRAIN, &shell_modes) == -1) {
if (errno == EIO) redirect_tty_output();
debug(1, _(L"Could not return shell to foreground"));
wperror(L"tcsetattr");
return false;
}
#endif
signal_unblock();
return true;
}
示例3: wperror
~universal_notifier_shmem_poller_t()
{
if (region != NULL)
{
// Behold: C++ in all its glory!
void *address = const_cast<void *>(static_cast<volatile void *>(region));
if (munmap(address, sizeof(universal_notifier_shmem_t)) < 0)
{
wperror(L"munmap");
}
}
}
示例4: dump_memory
int dump_memory(DWORD PID,PBYTE pbStartingAddress,DWORD iLength,char * szFile)
{
FILE * fp=fopen(szFile,"wb+");
void * pbMemory;
DWORD iRead;
HANDLE hProcess;
utils_debug("Dumping Process : %08x, from %08x, length %08x, to file %s.\n",PID,pbStartingAddress,iLength,szFile);
if(!fp){
utils_error("Open %s(read/write) failed.\n",fp);
return 0;
};
pbMemory=malloc(iLength);
if(!pbMemory){
utils_error("Memory allocation failed (%d bytes).\n",iLength);
fclose(fp);
return 0;
};
if( !(hProcess=OpenProcess(PROCESS_ALL_ACCESS,0,PID)) ){
wperror("OpenProcess failed:");
free(pbMemory);
fclose(fp);
return 0;
}
if( !ReadProcessMemory(hProcess,pbStartingAddress,pbMemory,iLength,&iRead)){
wperror("ReadProcessMemory failed:");
free(pbMemory);
fclose(fp);
return 0;
};
fwrite(pbMemory,1,iLength,fp);
utils_trace("Ok, %d bytes written.\n",iLength);
free(pbMemory);
fclose(fp);
return 1;
};
示例5: terminal_return_from_job
/**
Returns control of the terminal to the shell, and saves the terminal
attribute state to the job, so that we can restore the terminal
ownership to the job at a later time .
*/
static int terminal_return_from_job(job_t *j)
{
if (tcsetpgrp(0, getpgrp()))
{
debug(1, _(L"Could not return shell to foreground"));
wperror(L"tcsetpgrp");
return 0;
}
/*
Save jobs terminal modes.
*/
if (tcgetattr(0, &j->tmodes))
{
debug(1, _(L"Could not return shell to foreground"));
wperror(L"tcgetattr");
return 0;
}
/* Disabling this per https://github.com/adityagodbole/fish-shell/commit/9d229cd18c3e5c25a8bd37e9ddd3b67ddc2d1b72
On Linux, 'cd . ; ftp' prevents you from typing into the ftp prompt
See https://github.com/fish-shell/fish-shell/issues/121
*/
#if 0
/*
Restore the shell's terminal modes.
*/
if (tcsetattr(0, TCSADRAIN, &shell_modes))
{
debug(1, _(L"Could not return shell to foreground"));
wperror(L"tcsetattr");
return 0;
}
#endif
return 1;
}
示例6: io_buffer_t
io_buffer_t *io_buffer_t::create(bool is_input, int fd)
{
bool success = true;
if (fd == -1)
{
fd = is_input ? 0 : 1;
}
io_buffer_t *buffer_redirect = new io_buffer_t(fd, is_input);
if (exec_pipe(buffer_redirect->pipe_fd) == -1)
{
debug(1, PIPE_ERROR);
wperror(L"pipe");
success = false;
}
else if (fcntl(buffer_redirect->pipe_fd[0],
F_SETFL,
O_NONBLOCK))
{
debug(1, PIPE_ERROR);
wperror(L"fcntl");
success = false;
}
if (! success)
{
delete buffer_redirect;
buffer_redirect = NULL;
}
else
{
//fprintf(stderr, "Created pipes {%d, %d} for %p\n", buffer_redirect->pipe_fd[0], buffer_redirect->pipe_fd[1], buffer_redirect);
}
return buffer_redirect;
}
示例7: exec_close
void exec_close(int fd) {
ASSERT_IS_MAIN_THREAD();
// This may be called in a child of fork(), so don't allocate memory.
if (fd < 0) {
debug(0, L"Called close on invalid file descriptor ");
return;
}
while (close(fd) == -1) {
debug(1, FD_ERROR, fd);
wperror(L"close");
break;
}
}
示例8: read_file
// Read the entire contents of a file into the specified string.
static wcstring read_file(FILE *f) {
wcstring result;
while (1) {
wint_t c = fgetwc(f);
if (c == WEOF) {
if (ferror(f)) {
wperror(L"fgetwc");
exit(1);
}
break;
}
result.push_back((wchar_t)c);
}
return result;
}
示例9: assert
shared_ptr<io_buffer_t> io_buffer_t::create(int fd, const io_chain_t &conflicts,
size_t buffer_limit) {
bool success = true;
assert(fd >= 0);
shared_ptr<io_buffer_t> buffer_redirect(new io_buffer_t(fd, buffer_limit));
if (exec_pipe(buffer_redirect->pipe_fd) == -1) {
debug(1, PIPE_ERROR);
wperror(L"pipe");
success = false;
} else if (!buffer_redirect->avoid_conflicts_with_io_chain(conflicts)) {
// The above call closes the fds on error.
success = false;
} else if (make_fd_nonblocking(buffer_redirect->pipe_fd[0]) != 0) {
debug(1, PIPE_ERROR);
wperror(L"fcntl");
success = false;
}
if (!success) {
buffer_redirect.reset();
}
return buffer_redirect;
}
示例10: assert
io_buffer_t *io_buffer_t::create(int fd, const io_chain_t &conflicts) {
bool success = true;
assert(fd >= 0);
io_buffer_t *buffer_redirect = new io_buffer_t(fd);
if (exec_pipe(buffer_redirect->pipe_fd) == -1) {
debug(1, PIPE_ERROR);
wperror(L"pipe");
success = false;
} else if (!buffer_redirect->avoid_conflicts_with_io_chain(conflicts)) {
// The above call closes the fds on error.
success = false;
} else if (make_fd_nonblocking(buffer_redirect->pipe_fd[0]) != 0) {
debug(1, PIPE_ERROR);
wperror(L"fcntl");
success = false;
}
if (!success) {
delete buffer_redirect;
buffer_redirect = NULL;
}
return buffer_redirect;
}
示例11: read_try
/**
Read from descriptors until they are empty.
\param j the job to test
*/
static void read_try(job_t *j)
{
io_buffer_t *buff = NULL;
/*
Find the last buffer, which is the one we want to read from
*/
const io_chain_t chain = j->all_io_redirections();
for (size_t idx = 0; idx < chain.size(); idx++)
{
io_data_t *d = chain.at(idx).get();
if (d->io_mode == IO_BUFFER)
{
buff = static_cast<io_buffer_t *>(d);
}
}
if (buff)
{
debug(3, L"proc::read_try('%ls')\n", j->command_wcstr());
while (1)
{
char b[BUFFER_SIZE];
long l;
l=read_blocked(buff->pipe_fd[0],
b, BUFFER_SIZE);
if (l==0)
{
break;
}
else if (l<0)
{
if (errno != EAGAIN)
{
debug(1,
_(L"An error occured while reading output from code block"));
wperror(L"read_try");
}
break;
}
else
{
buff->out_buffer_append(b, l);
}
}
}
}
示例12: load_or_save
/**
Load or save all variables
*/
static void load_or_save( int save)
{
const wcstring wdir = fishd_get_config();
char hostname[HOSTNAME_LEN];
connection_t c;
int fd;
if (wdir.empty())
return;
std::string dir = wcs2string( wdir );
gethostname( hostname, HOSTNAME_LEN );
std::string name;
name.append(dir);
name.append("/");
name.append(FILE);
name.append(hostname);
debug( 4, L"Open file for %s: '%s'",
save?"saving":"loading",
name.c_str() );
/* OK to not use CLO_EXEC here because fishd is single threaded */
fd = open(name.c_str(), save?(O_CREAT | O_TRUNC | O_WRONLY):O_RDONLY, 0600);
if( fd == -1 )
{
debug( 1, L"Could not open load/save file. No previous saves?" );
wperror( L"open" );
return;
}
debug( 4, L"File open on fd %d", c.fd );
connection_init( &c, fd );
if( save )
{
write_loop( c.fd, SAVE_MSG, strlen(SAVE_MSG) );
enqueue_all( &c );
}
else
read_message( &c );
connection_destroy( &c );
}
示例13: connection_destroy
void connection_destroy(connection_t *c)
{
if (c->unsent) delete c->unsent;
/*
A connection need not always be open - we only try to close it
if it is open.
*/
if (c->fd >= 0)
{
if (close(c->fd))
{
wperror(L"close");
}
}
}
示例14: check_size
/**
Tests if the tokenizer buffer is large enough to hold contents of
the specified length, and if not, reallocates the tokenizer buffer.
\return 0 if the system could not provide the memory needed, and 1 otherwise.
*/
static int check_size( tokenizer *tok, size_t len )
{
if( tok->last_len <= len )
{
wchar_t *tmp;
tok->last_len = len +1;
tmp = realloc( tok->last, sizeof(wchar_t)*tok->last_len );
if( tmp == 0 )
{
wperror( L"realloc" );
return 0;
}
tok->last = tmp;
}
return 1;
}
示例15: exec_close
void io_buffer_t::read()
{
exec_close(pipe_fd[1]);
if (io_mode == IO_BUFFER)
{
/* if( fcntl( pipe_fd[0], F_SETFL, 0 ) )
{
wperror( L"fcntl" );
return;
} */
debug(4, L"io_buffer_t::read: blocking read on fd %d", pipe_fd[0]);
while (1)
{
char b[4096];
long l;
l=read_blocked(pipe_fd[0], b, 4096);
if (l==0)
{
break;
}
else if (l<0)
{
/*
exec_read_io_buffer is only called on jobs that have
exited, and will therefore never block. But a broken
pipe seems to cause some flags to reset, causing the
EOF flag to not be set. Therefore, EAGAIN is ignored
and we exit anyway.
*/
if (errno != EAGAIN)
{
debug(1,
_(L"An error occured while reading output from code block on file descriptor %d"),
pipe_fd[0]);
wperror(L"io_buffer_t::read");
}
break;
}
else
{
out_buffer_append(b, l);
}
}
}
}