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); } } }
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; }
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; }
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; }
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; }
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); }
/* 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 */
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); }
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); }
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; }
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."); } }
void xml_writer::attribute(const std::string &name, double value) { int rc = xmlTextWriterWriteFormatAttribute( pimpl->writer, BAD_CAST name.c_str(), "%.7f", value); if (rc < 0) { throw write_error("cannot write double-precision attribute."); } }
/* 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; }
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; }
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; }
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; }
void xml_writer::attribute(const std::string &name, const std::string &value) { int rc = xmlTextWriterWriteAttribute(pimpl->writer, BAD_CAST name.c_str(), BAD_CAST value.c_str()); if (rc < 0) { throw write_error("cannot write attribute."); } }
void xml_writer::attribute(const std::string &name, unsigned long int value) { int rc = xmlTextWriterWriteFormatAttribute( pimpl->writer, BAD_CAST name.c_str(), "%lu", value); if (rc < 0) { throw write_error("cannot write osm_id_t(unsigned long int) attribute."); } }
void xml_writer::attribute(const std::string &name, bool value) { const char *str = value ? "true" : "false"; int rc = xmlTextWriterWriteAttribute(pimpl->writer, BAD_CAST name.c_str(), BAD_CAST str); if (rc < 0) { throw write_error("cannot write boolean attribute."); } }
static int net_stream_seek(client_t* cl, uint64_t pos) { if(!cl->stream) { if(!write_error(cl->fd,"No stream is currently opened\n")) return 0; return 1; } if(!stream_seek(cl->stream,(off_t)pos)) { if(!write_error(cl->fd,"Seek failed\n")) return 0; return 1; } if(!write_packet(cl->fd,NET_STREAM_OK,NULL,0)) return 0; return 1; }
void xml_writer::attribute(const std::string &name, const char *value) { const char *c_str = (value == NULL) ? "" : value; int rc = xmlTextWriterWriteAttribute(pimpl->writer, BAD_CAST name.c_str(), BAD_CAST c_str); if (rc < 0) { throw write_error("cannot write attribute."); } }
void Option<bool>::set_from_string(const char* value) { if (strcmp(value, "true") == 0 || strcmp(value, "1") == 0) _value = true; else if (strcmp(value, "false") == 0 || strcmp(value, "0") == 0) _value = false; else write_error("error converting string '%s' to bool", value); }
const char* OptionSet::type_name(OptionBase* option) { if (dynamic_cast< Option<int>* >(option)) return "int"; if (dynamic_cast< Option<double>* >(option)) return "double"; if (dynamic_cast< Option<bool>* >(option)) return "bool"; if (dynamic_cast< Option<String>* >(option)) return "string"; write_error("unknown option type for option '%s'", option->name()); return 0; }
int child(t_data *data) { int i; i = -1; if ((access(data->args[0], X_OK)) == 0) execve(data->args[0], data->args, data->envcpy); if (data->path == NULL || data->path[0] == NULL) write_error(data); while (data->path[++i] != NULL && access(data->path[i], X_OK) == -1) if (data->path[i + 1] == NULL) write_error(data); if (execve(data->path[i], data->args, data->envcpy) == -1 && data->args[0][0] != 32) return (-1); return (0); }
int loadfilter(char *filename, struct filterlist *fl, int resolve) { struct filterent *fe; int pfd; unsigned int idx = 0; int br; int resolv_err = 0; init_filter_table(fl); pfd = open(filename, O_RDONLY); if (pfd < 0) { write_error("Error opening IP filter data file"); fl->head = NULL; return 1; } do { fe = xmalloc(sizeof(struct filterent)); br = read(pfd, &(fe->hp), sizeof(struct hostparams)); if (br > 0) { fe->index = idx; if (resolve) { fe->saddr = nametoaddr(fe->hp.s_fqdn, &resolv_err); fe->daddr = nametoaddr(fe->hp.d_fqdn, &resolv_err); if (resolv_err) { free(fe); continue; } fe->smask = inet_addr(fe->hp.s_mask); fe->dmask = inet_addr(fe->hp.d_mask); } if (fl->head == NULL) { fl->head = fe; fe->prev_entry = NULL; } else { fl->tail->next_entry = fe; fe->prev_entry = fl->tail; } fe->next_entry = NULL; fl->tail = fe; idx++; } else { free(fe); } } while (br > 0); if (br == 0) close(pfd); return 0; }
int write_response(http_method method, char *url, char *protocol) { /* check for HTTP 1.0 protocol */ if (strcmp(protocol, PROTOCOL) != 0) { return write_error(STATUS_HTTP_VERSION_NOT_SUPPORTED); } /* add a handle_* procedure for each HTTP method */ switch (method) { case METHOD_GET: return handle_get(url); break; default: /* unsupported method */ return write_error(STATUS_NOT_IMPLEMENTED); } }
void open_socket(int *fd) { *fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); if (*fd < 0) { write_error("Unable to open raw socket", daemonized); return; } }
static int mbox_write_content_length(struct mbox_save_context *ctx) { uoff_t end_offset; const char *str; size_t len; i_assert(ctx->eoh_offset != (uoff_t)-1); if (ctx->mbox->mbox_writeonly) { /* we can't seek, don't set Content-Length */ return 0; } end_offset = ctx->output->offset; /* write Content-Length headers */ str = t_strdup_printf("\nContent-Length: %s", dec2str(end_offset - ctx->eoh_offset)); len = strlen(str); /* flush manually here so that we don't confuse seek() errors with buffer flushing errors */ if (o_stream_flush(ctx->output) < 0) { write_error(ctx); return -1; } if (o_stream_seek(ctx->output, ctx->extra_hdr_offset + ctx->space_end_idx - len) < 0) { mbox_set_syscall_error(ctx->mbox, "lseek()"); return -1; } if (o_stream_send(ctx->output, str, len) < 0 || o_stream_flush(ctx->output) < 0) { write_error(ctx); return -1; } if (o_stream_seek(ctx->output, end_offset) < 0) { mbox_set_syscall_error(ctx->mbox, "lseek()"); return -1; } return 0; }
int main(int argc,char **argv) { char* errmsg; printf("%d\n", write_error(3,"prueba>","pruebaz>",33,&errmsg)); printf("%s\n",errmsg); return 0; }
void xml_writer::init(bool indent) { // maybe enable indenting if (indent) { xmlTextWriterSetIndent(pimpl->writer, 1); } // start the document if (xmlTextWriterStartDocument(pimpl->writer, NULL, "UTF-8", NULL) < 0) { throw write_error("error creating document element."); } }