本文整理汇总了C++中write_error函数的典型用法代码示例。如果您正苦于以下问题:C++ write_error函数的具体用法?C++ write_error怎么用?C++ write_error使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了write_error函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_command_cb
static void
test_command_cb (DBusGProxy *proxy,
char *word[],
char *word_eol[],
guint hook_id,
guint context_id,
gpointer user_data)
{
GError *error = NULL;
if (hook_id == command_id) {
if (!dbus_g_proxy_call (proxy, "Unhook",
&error,
G_TYPE_UINT, hook_id,
G_TYPE_INVALID, G_TYPE_INVALID)) {
write_error ("Failed to complete unhook", &error);
}
/* Now if you write "/test blah" again in the HexChat window
* you'll get a "Unknown command" error message */
g_print ("test command received: %s\n", word_eol[1]);
if (!dbus_g_proxy_call (proxy, "Print",
&error,
G_TYPE_STRING, "test command succeed",
G_TYPE_INVALID,
G_TYPE_INVALID)) {
write_error ("Failed to complete Print", &error);
}
}
}
示例2: net_stream_open
static int net_stream_open(client_t* cl,char* url) {
int file_format=DEMUXER_TYPE_UNKNOWN;
mp_net_stream_opened_t ret;
if(cl->stream) {
if(!write_error(cl->fd,"A stream is currently opened\n"))
return 0;
return 1;
}
mp_msg(MSGT_NETST,MSGL_V,"Open stream %s\n",url);
cl->stream = open_stream(url,NULL,&file_format);
if(!cl->stream) {
if(!write_error(cl->fd,"Open failed\n"))
return 0;
return 1;
}
stream_reset(cl->stream);
stream_seek(cl->stream,cl->stream->start_pos);
ret.file_format = file_format;
ret.flags = cl->stream->flags;
ret.sector_size = cl->stream->sector_size;
ret.start_pos = cl->stream->start_pos;
ret.end_pos = cl->stream->end_pos;
net_stream_opened_2_me(&ret);
if(!write_packet(cl->fd,NET_STREAM_OK,(char*)&ret,sizeof(mp_net_stream_opened_t)))
return 0;
return 1;
}
示例3: net_stream_fill_buffer
static int net_stream_fill_buffer(client_t* cl,uint16_t max_len) {
int r;
mp_net_stream_packet_t *pack;
if(!cl->stream) {
if(!write_error(cl->fd,"No stream is currently opened\n"))
return 0;
return 1;
}
if(max_len == 0) {
if(!write_error(cl->fd,"Fill buffer called with 0 lenght\n"))
return 0;
return 1;
}
pack = malloc(max_len + sizeof(mp_net_stream_packet_t));
pack->cmd = NET_STREAM_OK;
r = stream_read(cl->stream,pack->data,max_len);
pack->len = le2me_16(r + sizeof(mp_net_stream_packet_t));
if(!net_write(cl->fd,(char*)pack,le2me_16(pack->len))) {
free(pack);
return 0;
}
free(pack);
return 1;
}
示例4: assimilate_handler
int assimilate_handler(
WORKUNIT& wu,
std::vector<RESULT>& /*results*/,
RESULT& canonical_result) {
int retval;
char buf[1024];
MapReduceTask* mrt = NULL;
// First time initialization (loads jobtracker state).
// This information is loaded into memory but we only need the output paths
// and wu names. We are not updating the file here.
if(jobtracker_file == NULL) {
// Open jobtracker state file.
jobtracker_file = fopen(jobtracker_file_path, "r+");
if (!jobtracker_file){
sprintf(buf, "Can't jobtracker file (%s).\n", jobtracker_file_path);
return write_error(buf);
}
// Parse jobtracker state file.
retval = parse_jobtracker(jobtracker_file, jobs);
if(retval) {
sprintf(buf, "Error parsing jobtracker file\n");
return write_error(buf);
}
}
retval = boinc_mkdir(config.project_path("sample_results"));
if (retval) return retval;
if (wu.canonical_resultid) {
std::vector<OUTPUT_FILE_INFO> output_files;
const char *copy_path;
get_output_file_infos(canonical_result, output_files);
bool file_copied = false;
// Get the task identified by the work unit name.
mrt = get_task_by_name(jobs, wu.name);
if (mrt == NULL) {
sprintf(buf, "Can't find MapRedureTask %s\n", wu.name);
return write_error(buf);
}
// FIXME - if wu.name contains reduce, also copy to bt new. -> put mrt output task = bt new
retval = boinc_copy(output_files[0].path.c_str() , mrt->getOutputPath().c_str());
if (!retval) { file_copied = true; }
if (!file_copied) {
copy_path = config.project_path("sample_results/%s_%s", wu.name, "no_output_files");
FILE* f = fopen(copy_path, "w");
fclose(f);
}
} else {
sprintf(buf, "%s: 0x%x\n", wu.name, wu.error_mask);
return write_error(buf);
}
return 0;
}
示例5: main
int main(int argc, char **argv) {
const int wfilter = WFILTER;
const int hfilter = HFILTER;
const int wimage = WIMAGE;
const int himage = HIMAGE;
char* filename = TEST_FILENAME;
/* allocate memory space for two input matrices and the result matrix. */
uint64_t* newimg = calloc(wimage*himage, sizeof(uint64_t));
uint16_t* filter = calloc(wfilter*hfilter, sizeof(uint16_t));
uint16_t* image = calloc(wimage*himage+2*PAD_ZERO, sizeof(uint16_t));
image += PAD_ZERO;
srand(time(0));
for (int i = 0; i < wfilter*hfilter; i++) {
filter[i] = rand()%32767;
}
for (int i = 0; i < wimage*himage; i++) {
image[i] = rand()%32767;
}
/* calculate the result matrix */
for (int i = 0; i < wimage; i++)
{
for (int m = 0; m < wfilter; m++)
{
for (int n = 0; n < hfilter; n++)
{
uint64_t scalarF = filter[m*WFILTER+n];
for (int j = 0; j < himage; j++)
{
newimg[i*WIMAGE+j] += scalarF*image[OFFSET+(i-m)*WIMAGE+(j-n)];
}
}
}
}
FILE* file = fopen(filename, "wb");
if (!file) write_error();
if (!fwrite(&wfilter, sizeof(int), 1, file)) write_error();
if (!fwrite(&hfilter, sizeof(int), 1, file)) write_error();
if (!fwrite(&wimage, sizeof(int), 1, file)) write_error();
if (!fwrite(&himage, sizeof(int), 1, file)) write_error();
if (fwrite(newimg, sizeof(uint64_t), wimage*himage, file)<wimage*himage) write_error();
if (fwrite(filter, sizeof(uint16_t), wfilter*hfilter, file)<wfilter*hfilter) write_error();
if (fwrite(image, sizeof(uint16_t), wimage*himage, file)<wimage*himage) write_error();
if (fclose(file)) write_error();
free(image-PAD_ZERO);
free(filter);
free(newimg);
return EXIT_SUCCESS;
}
示例6: while
static struct iflist *positionptr(struct iflist *iflist, const int ifindex)
{
struct iflist *ptmp = iflist;
struct iflist *last = ptmp;
while ((ptmp != NULL) && (ptmp->ifindex != ifindex)) {
last = ptmp;
ptmp = ptmp->next_entry;
}
/* no interface was found, try to create new one */
if (ptmp == NULL) {
struct iflist *itmp = xmallocz(sizeof(struct iflist));
itmp->ifindex = ifindex;
itmp->index = last->index + 1;
int r = dev_get_ifname(ifindex, itmp->ifname);
if (r != 0) {
write_error("Error getting interface name");
return(NULL);
}
/* last can't be NULL otherwise we will have empty iflist */
last->next_entry = itmp;
itmp->prev_entry = last;
itmp->next_entry = NULL;
ptmp = itmp;
}
return(ptmp);
}
示例7: copyfiles_by_name
/* Copy srcFile to destFile */
int copyfiles_by_name(char *srcFile, char *destFile)
{
FILE *f, *g;
int status = 0;
long fileLength;
f = fopen(srcFile, FOPRBIN);
if (f == NULL)
return -1;
g = fopen(destFile, FOPWBIN);
if (g == NULL) {
fclose(f);
return -1;
}
/* Get file length and copy it */
fseek(f, 0L, SEEK_END);
fileLength = ftell(f);
rewind(f);
status = copyfile(f, g, fileLength);
fclose(f);
if (write_error(g))
status = -1;
fclose(g);
return status;
} /* copyfiles_by_name */
示例8: write_directory_file
void
write_directory_file (void)
{
FILE *fp = listed_incremental_stream;
char buf[UINTMAX_STRSIZE_BOUND];
char *s;
if (! fp)
return;
if (fseeko (fp, 0L, SEEK_SET) != 0)
seek_error (listed_incremental_option);
if (sys_truncate (fileno (fp)) != 0)
truncate_error (listed_incremental_option);
fprintf (fp, "%s-%s-%d\n", PACKAGE_NAME, PACKAGE_VERSION,
TAR_INCREMENTAL_VERSION);
s = (TYPE_SIGNED (time_t)
? imaxtostr (start_time.tv_sec, buf)
: umaxtostr (start_time.tv_sec, buf));
fwrite (s, strlen (s) + 1, 1, fp);
s = umaxtostr (start_time.tv_nsec, buf);
fwrite (s, strlen (s) + 1, 1, fp);
if (! ferror (fp) && directory_table)
hash_do_for_each (directory_table, write_directory_file_entry, fp);
if (ferror (fp))
write_error (listed_incremental_option);
if (fclose (fp) != 0)
close_error (listed_incremental_option);
}
示例9: fork_this
int fork_this(char *full_path, char **arg, char **env)
{
int status;
int ch_pid;
int w;
int ret;
init(&ret, &ch_pid, &status);
static_fork(full_path, &ch_pid);
if (ch_pid > 0)
{
if ((w = waitpid(ch_pid, &status, 0)) == -1)
perror_wpid();
}
else if (!ch_pid && full_path)
{
ret = execve(full_path, arg, env);
if (ret == -1)
{
write_error(&full_path);
ft_putendl_fd(full_path, 2);
}
exit(ret);
}
return (status);
}
示例10: mbox_append_lf
static int mbox_append_lf(struct mbox_save_context *ctx)
{
if (o_stream_send(ctx->output, "\n", 1) < 0)
return write_error(ctx);
return 0;
}
示例11: xmlTextWriterWriteFormatAttribute
void xml_writer::attribute(const std::string &name, int value) {
int rc = xmlTextWriterWriteFormatAttribute(
pimpl->writer, BAD_CAST name.c_str(), "%d", value);
if (rc < 0) {
throw write_error("cannot write integer attribute.");
}
}
示例12: readPhantomInput
/* read the data from stdin to the phantom input file */
int readPhantomInput(char *filename)
{
FILE *outFilePtr;
byte buffer[512];
int bytesRead, status = 0;
if (verbose)
fprintf(pgpout, "writing stdin to file %s\n", filename);
if ((outFilePtr = fopen(filename, FOPWBIN)) == NULL)
return -1;
#if defined(MSDOS) || defined(OS2) || defined (WIN32)
/* Under DOS must set input stream to binary mode to avoid data mangling */
setmode(fileno(stdin), O_BINARY);
#endif /* MSDOS || OS2 */
while ((bytesRead = fread(buffer, 1, 512, stdin)) > 0)
if (fwrite(buffer, 1, bytesRead, outFilePtr) != bytesRead) {
status = -1;
break;
}
if (write_error(outFilePtr))
status = -1;
fclose(outFilePtr);
#if defined(MSDOS) || defined(OS2) || defined (WIN32)
setmode(fileno(stdin), O_TEXT); /* Reset stream */
#endif /* MSDOS || OS2 */
return status;
}
示例13: process_connection
static void* process_connection(void *arg) {
struct pollfd fds[2];
char buf[BUF_SIZE];
int i = CLIENT, res;
init_sock(fds[CLIENT].fd = (long) arg);
fds[CLIENT].events = POLLIN | POLLERR | POLLHUP;
fds[SERVER].fd = -1;
fds[SERVER].events = POLLIN | POLLERR | POLLHUP;
fds[SERVER].fd = res = prepare_http(fds[CLIENT].fd, buf);
while (res >= 0) {
i = SERVER;
if (!(res = poll(fds, 2, inactivity_timeout * 1000)))
break;
for (i = 0; res > 0 && i < 2; ++i)
if ((fds[i].revents & POLL_IN))
res = send_data(buf, i, fds + i, fds[i ^ 1].fd);
else if ((fds[i].revents & (POLLERR | POLLHUP)))
res = ERR_IO;
}
if (res < 0 && (i == SERVER || res != ERR_IO))
write_error(buf, fds[CLIENT].fd, res);
if (fds[SERVER].fd >= 0)
close(fds[SERVER].fd);
close(fds[CLIENT].fd);
return NULL;
}
示例14: write_from_line
static int write_from_line(struct mbox_save_context *ctx, time_t received_date,
const char *from_envelope)
{
int ret;
T_BEGIN {
const char *line;
if (from_envelope == NULL) {
struct mail_storage *storage =
&ctx->mbox->storage->storage;
from_envelope =
strchr(storage->user->username, '@') != NULL ?
storage->user->username :
t_strconcat(storage->user->username,
"@", my_hostdomain(), NULL);
} else if (*from_envelope == '\0') {
/* can't write empty envelope */
from_envelope = "MAILER-DAEMON";
}
/* save in local timezone, no matter what it was given with */
line = mbox_from_create(from_envelope, received_date);
if ((ret = o_stream_send_str(ctx->output, line)) < 0)
write_error(ctx);
} T_END;
return ret;
}
示例15: mbox_seek_to_end
static int mbox_seek_to_end(struct mbox_save_context *ctx, uoff_t *offset)
{
struct stat st;
char ch;
int fd;
if (ctx->mbox->mbox_writeonly) {
*offset = 0;
return 0;
}
fd = ctx->mbox->mbox_fd;
if (fstat(fd, &st) < 0)
return mbox_set_syscall_error(ctx->mbox, "fstat()");
ctx->orig_atime = st.st_atime;
*offset = (uoff_t)st.st_size;
if (st.st_size == 0)
return 0;
if (lseek(fd, st.st_size-1, SEEK_SET) < 0)
return mbox_set_syscall_error(ctx->mbox, "lseek()");
if (read(fd, &ch, 1) != 1)
return mbox_set_syscall_error(ctx->mbox, "read()");
if (ch != '\n') {
if (write_full(fd, "\n", 1) < 0)
return write_error(ctx);
*offset += 1;
}
return 0;
}