void subproc_read(void) { int fd; int i, res; printf("File Reader starting ...\n\n"); fd = open(FNAME, O_RDONLY); if (fd < 0) { err(1, "%s: open", FNAME); } for (i=0; i<TMULT; i++) { res = read(fd, buffer, SectorSize + 1); if (res < 0) { err(1, "%s: read", FNAME); } // yield(); if (res != SectorSize + 1) { errx(1, "%s: read: short count", FNAME); } check_buffer(); } close(fd); printf("File Read exited successfully!\n"); }
int get_next_line(int const fd, char **line) { static char *buffer = NULL; char str[BUFF_SIZE + 1]; int read_bytes; int status; char *tmp; ft_bzero(str, BUFF_SIZE + 1); if (fd < 0 || !line) return (-1); if ((status = check_buffer(&buffer, line))) return (status); while ((read_bytes = read(fd, str, BUFF_SIZE)) > 0) { if ((status = find_new_line(&buffer, line, str))) return (status); tmp = buffer; buffer = buffer ? ft_strjoin(tmp, str) : ft_strdup(str); if (!buffer) return (-1); free(tmp); ft_bzero(str, BUFF_SIZE + 1); } return (recheck_buffer(read_bytes, &buffer, line)); }
static int fcheck_data(int fd, const char *data, int offset, unsigned len) { char buf[4096]; int res; if (lseek(fd, offset, SEEK_SET) == (loff_t) -1) { PERROR("lseek"); return -1; } while (len) { int rdlen = len < sizeof(buf) ? len : sizeof(buf); res = read(fd, buf, rdlen); if (res == -1) { PERROR("read"); return -1; } if (res != rdlen) { ERROR("short read: %u instead of %u", res, rdlen); return -1; } if (check_buffer(buf, data, rdlen) != 0) { return -1; } data += rdlen; len -= rdlen; } return 0; }
/** * reader_thread - per-cpu channel buffer reader */ static void *reader_thread(void *data) { int rc; unsigned long cpu = (unsigned long)data; struct pollfd pollfd; do { pollfd.fd = relay_file[cpu]; pollfd.events = POLLIN; rc = poll(&pollfd, 1, -1); if (rc < 0) { if (errno != EINTR) { printf("poll error: %s\n",strerror(errno)); exit(1); } printf("poll warning: %s\n",strerror(errno)); rc = 0; } pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_mutex_lock(&processing_mutex); processing++; pthread_mutex_unlock(&processing_mutex); check_buffer(cpu); pthread_mutex_lock(&processing_mutex); processing--; pthread_mutex_unlock(&processing_mutex); pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); } while (1); }
char *get_next_line(const int fd) { static char *file_buffer; char *buffer; int ret; if (BUFF_SIZE < 0 || fd < 0) return (NULL); if (!file_buffer) file_buffer = (char*)malloc(1); buffer = (char*)malloc(BUFF_SIZE + 1); if (buffer == NULL || file_buffer == NULL) return (NULL); while (!check_buffer(file_buffer) && (ret = read(fd, buffer, BUFF_SIZE))) { if (ret == -1) return (NULL); buffer[ret] = '\0'; file_buffer = ft_strcat(file_buffer, buffer); if (file_buffer == NULL) return (NULL); } free(buffer); return (gimme_good_line(file_buffer)); }
/// \brief Make this Element with an ASCII string value. /// /// @param data The ASCII string to use as the value. /// /// @param size The number of bytes in the ASCII string. /// /// @return A reference to this Element. Element & Element::makeString(std::uint8_t *data, size_t size) { // GNASH_REPORT_FUNCTION; _type = Element::STRING_AMF0; // If there is an existing string, if (_buffer) { if (_buffer->size() < size) { _buffer->resize(size+1); // add room for the NULL terminator } } else { // Make room for an additional NULL terminator try { check_buffer(size+1); } catch (std::exception& e) { log_error("%s", e.what()); return *this; } } _buffer->clear(); // FIXME: this could be a performance issue _buffer->copy(data, size); // Unlike other buffers, people like to print strings, so we must add // a NULL terminator to the string. When encoding, we are careful to // to adjust the byte count down by one, as the NULL terminator doesn't // get written. // *(_buffer->end() - 1) = 0; _buffer->setSize(size); return *this; }
int my_core(t_shell *shell, t_check *check) { int i; i = 0; signal(SIGINT, signal_sigint); while (i == 0) { my_putstr("$> "); shell->buffer = get_next_line(0); if (shell->buffer == NULL) return (0); else { i = check_buffer(shell, check); free(shell->buffer); } if (i != 0) { if (i == 1) return (0); return (i); } } return (0); }
int main(void) { int offset, matches; char *filePath = "source.sub"; char *destPath = "fixed.sub"; printf("offset --> "); matches = scanf("%d", &offset); check_input(matches); FILE *file = fopen(filePath, "r"); FILE *dest = fopen(destPath, "w"); if (NULL == dest || NULL == file) { kill(NULL); } char buffer[BUFFER_SIZE]; char *timeEnd; char *timeStart; while ((0 == feof(file)) && (0 == ferror(file)) && (0 == ferror(dest))) { size_t readBytes = fread(buffer, 1, BUFFER_SIZE, file); char *substr; substr = strstr(buffer, "-->"); while (NULL != substr) { int check = check_buffer(buffer, substr, readBytes); if (1 == check) { timeEnd = substr + OFFSET_TO_ENDTIME; timeStart = substr - TIME_SIZE -1; char startTime[TIME_SIZE + 1]; strncpy(startTime, timeStart, TIME_SIZE); startTime[TIME_SIZE] = '\0'; char endTime[TIME_SIZE +1]; strncpy(endTime, timeEnd, TIME_SIZE); endTime[TIME_SIZE] = '\0'; change_time(startTime, offset); strncpy(timeStart, startTime, TIME_SIZE); change_time(endTime, offset); strncpy(timeEnd, endTime, TIME_SIZE); } substr = strstr(timeEnd, "-->"); } fwrite(buffer, 1, readBytes, dest); } fclose(file); fclose(dest); return 0; }
PollState HttpServerConnection::readData(char *buf, size_t len) { if (is_websocket) return wsReadData(buf, len); if (state == HttpState::READING_POST_DATA && !buffer_post_data) return got_post_data(buf, len); buffer.append(buf, len); return check_buffer(); }
int add_to_buffer (char** pp, char* str) { size_t len = strlen(str); if (!check_buffer (*pp, len)) return 1; strcpy (*pp, str); (*pp) += len; return 0; }
/// \brief Make this Element a Property with a Movie Clip (SWF data) as the value. /// /// @param data A real pointer to the raw data to use as the value. /// /// @param size The number of bytes to use as the value. /// /// @return A reference to this Element. Element & Element::makeMovieClip(std::uint8_t *indata, size_t size) { // GNASH_REPORT_FUNCTION; _type = Element::MOVIECLIP_AMF0; check_buffer(size); _buffer->copy(indata, size); return *this; }
/** * Sends a data element to the message stream. * @tparam type type of object that is being sent to stream. * @param x actual variable to send to stream. * @returns always returns *this. */ template <class type> log_client& log_client::send_to_stream(type& x) { // make sure buffers initialized check_buffer(); // push element in the message stream (m_buffer->get()->message_buffer()) << x; return *this; }
Datum dbms_pipe_pack_message_timestamp(PG_FUNCTION_ARGS) { TimestampTz dt = PG_GETARG_TIMESTAMPTZ(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_TIMESTAMPTZ, sizeof(dt), &dt, InvalidOid); PG_RETURN_VOID(); }
Datum dbms_pipe_pack_message_bytea(PG_FUNCTION_ARGS) { bytea *data = PG_GETARG_BYTEA_P(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_BYTEA, VARSIZE_ANY_EXHDR(data), VARDATA_ANY(data), InvalidOid); PG_RETURN_VOID(); }
void finalize_quote(void) { check_buffer(); if(current_col_size ==0) *lexical_stack=NULL; else { fix_quote((*lexical_stack)->content); ((cd*)*lexical_stack)->col_tag = QUOTE; } }
Datum dbms_pipe_pack_message_date(PG_FUNCTION_ARGS) { DateADT dt = PG_GETARG_DATEADT(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_DATE, sizeof(dt), &dt, InvalidOid); PG_RETURN_VOID(); }
/** * processes a name space (ns) stream manipulator. * @param _ns new name space to apply * @returns always returns *this **/ log_client& log_client::operator<<(const ns& _ns) { // make sure buffers initialized check_buffer(); // update namespace m_buffer->get()->log_namespace(_ns.log_namespace()); // return the stream return *this; }
/** * processes a log data stream manipulator. * @param _log_data log data to embue this message with. * @returns always returns *this **/ log_client& log_client::operator<<(const log_data& _log_data) { // make sure buffers initialized check_buffer(); // update namespace m_buffer->get()->extended_data(_log_data.key(), _log_data.value()); // return the stream return *this; }
Datum dbms_pipe_pack_message_number(PG_FUNCTION_ARGS) { Numeric num = PG_GETARG_NUMERIC(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_NUMBER, VARSIZE(num) - VARHDRSZ, VARDATA(num), InvalidOid); PG_RETURN_VOID(); }
Datum dbms_pipe_pack_message_text(PG_FUNCTION_ARGS) { text *str = PG_GETARG_TEXT_PP(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); pack_field(output_buffer, IT_VARCHAR, VARSIZE_ANY_EXHDR(str), VARDATA_ANY(str), InvalidOid); PG_RETURN_VOID(); }
/** * Sets the current message category to the specified category. * @param _category category (or entry type) to set this message as. * @returns always returns *this. */ log_client& log_client::create_log_stream(category _category) { // make sure buffers initialized check_buffer(); // set the initial category m_buffer->get()->entry_type(_category); // return the message stream (even though its not entirely what we are currently // working with it is the most relevant, usable std::ostream. return *this; }
static void finalize_flow(EFLOWDESC *ex, void *mdl) { if ((ex->next_seq == 0) && (ex->base_seq == 0)) sort_buffer(ex, mdl); /* didnt receive SYN, so sort the buffer */ else { /* * did receive SYN, so just reassemble as many packets as possible in * the buffer */ check_buffer(ex, mdl); } }
static int write_headers( hnd_t handle, x264_nal_t *p_nal ) { mp4_hnd_t *p_mp4 = handle; GF_AVCConfigSlot *p_slot; int sps_size = p_nal[0].i_payload - 4; int pps_size = p_nal[1].i_payload - 4; int sei_size = p_nal[2].i_payload; uint8_t *sps = p_nal[0].p_payload + 4; uint8_t *pps = p_nal[1].p_payload + 4; uint8_t *sei = p_nal[2].p_payload; // SPS p_mp4->p_config->configurationVersion = 1; p_mp4->p_config->AVCProfileIndication = sps[1]; p_mp4->p_config->profile_compatibility = sps[2]; p_mp4->p_config->AVCLevelIndication = sps[3]; p_slot = malloc( sizeof(GF_AVCConfigSlot) ); if( !p_slot ) return -1; p_slot->size = sps_size; p_slot->data = malloc( p_slot->size ); if( !p_slot->data ) return -1; memcpy( p_slot->data, sps, sps_size ); gf_list_add( p_mp4->p_config->sequenceParameterSets, p_slot ); // PPS p_slot = malloc( sizeof(GF_AVCConfigSlot) ); if( !p_slot ) return -1; p_slot->size = pps_size; p_slot->data = malloc( p_slot->size ); if( !p_slot->data ) return -1; memcpy( p_slot->data, pps, pps_size ); gf_list_add( p_mp4->p_config->pictureParameterSets, p_slot ); gf_isom_avc_config_update( p_mp4->p_file, p_mp4->i_track, 1, p_mp4->p_config ); // SEI if( check_buffer( p_mp4, p_mp4->p_sample->dataLength + sei_size ) ) return -1; memcpy( p_mp4->p_sample->data + p_mp4->p_sample->dataLength, sei, sei_size ); p_mp4->p_sample->dataLength += sei_size; return sei_size + sps_size + pps_size; }
void parse_norm(void) { switch(current_char) { case '\0': break; case '\r': case '\t': case '\v': case '\f': case '\n': case ' ': check_buffer(); break; case ']': case '}': check_buffer(); go_down_level(); break; case '[': check_buffer(); go_up_level(false); break; case '{': check_buffer(); go_up_level(true); break; case '(': on_comment = true; break; case '\"': on_string = true; break; default: add_to_word(); break; } }
/* Reads 'size' bytes from file open as fd into buffer. Returns number of bytes actually read - 0 at end of file, or -1 if file could not be read. fd = 0 reads from the keyboard. */ static int sys_read(int fd, void *buffer, unsigned size, struct intr_frame *f) { /* Cannot read from stdout. */ if (fd == STDOUT_FILENO) sys_exit(ERROR); int bytes; void *buf_iter = pg_round_down(buffer); check_fd(fd); check_buffer(buffer, size); lock_acquire(&secure_file); for (; buf_iter <= buffer + size; buf_iter += PGSIZE) { struct spt_entry *entry = get_spt_entry(&thread_current()->supp_pt, buf_iter); if (entry == NULL && should_stack_grow(buf_iter, f->esp)) { grow_stack(buf_iter); } } /* fd = 0 corresponds to reading from stdin. */ if (fd == STDIN_FILENO) { unsigned i; uint8_t keys[size]; /* Make an array of keys pressed. */ for (i = 0; i < size; i++) { keys[i] = input_getc(); } /* Put these keys pressed into the buffer. */ memcpy(buffer, (const void *) keys, size); /* Must have successfully read all bytes we were told to. */ bytes = size; } else { struct file *f = get_file(fd); if (!f) { lock_release(&secure_file); return ERROR; } bytes = file_read(f, buffer, size); } lock_release(&secure_file); return bytes; }
/// \brief Make this Element be a NULL String type. /// A Null String is a string with a length of zero. The /// data is only one byte, which always has the value of /// zero of course. /// /// @return A reference to this Element. Element & Element::makeNullString() { // GNASH_REPORT_FUNCTION; _type = Element::STRING_AMF0; try { check_buffer(sizeof(std::uint8_t)); } catch (std::exception& e) { log_error("%s", e.what()); return *this; } *(_buffer->reference()) = 0; return *this; }
/// \brief Make this Element a Property with an Object Reference as the value. /// /// @param data A real pointer to the raw data to use as the value. /// /// @param size The number of bytes to use as the value. /// /// @return A reference to this Element. Element & Element::makeReference(std::uint8_t *indata, size_t size) { // GNASH_REPORT_FUNCTION; _type = Element::REFERENCE_AMF0; try { check_buffer(size); } catch (std::exception& e) { log_error("%s", e.what()); return *this; } _buffer->copy(indata, size); return *this; }
Datum dbms_pipe_send_message(PG_FUNCTION_ARGS) { text *pipe_name = NULL; int timeout = ONE_YEAR; int limit = 0; bool valid_limit; int cycle = 0; float8 endtime; if (PG_ARGISNULL(0)) ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("pipe name is NULL"), errdetail("Pipename may not be NULL."))); else pipe_name = PG_GETARG_TEXT_P(0); output_buffer = check_buffer(output_buffer, LOCALMSGSZ); if (!PG_ARGISNULL(1)) timeout = PG_GETARG_INT32(1); if (PG_ARGISNULL(2)) valid_limit = false; else { limit = PG_GETARG_INT32(2); valid_limit = true; } if (input_buffer != NULL) /* XXX Strange? */ { pfree(input_buffer); input_buffer = NULL; } WATCH_PRE(timeout, endtime, cycle); if (add_to_pipe(pipe_name, output_buffer, limit, valid_limit)) break; WATCH_POST(timeout, endtime, cycle); init_buffer(output_buffer, LOCALMSGSZ); PG_RETURN_INT32(RESULT_DATA); }
int main(int argc, char** argv) { MPI_Init(&argc, &argv); // TEST_INIT("goal transform test\n"); GOAL_Init(); const int datasize = 8; char* send_buffer = (char*) malloc(datasize); char* recv_buffer = (char*) malloc(datasize); init_buffer(recv_buffer, datasize); int rank = GOAL_MyRank(); int group_size = GOAL_GroupSize(); // transformation code GOAL_Handle hndl; GOAL_Graph g = GOAL_Create_graph(); // inspector code // builds the schedule to be executed by GOAL GOAL_Send(g, send_buffer, datasize, left_neighbor(rank, group_size)); GOAL_Recv(g, recv_buffer, datasize, right_neighbor(rank, group_size)); GOAL_Schedule sched = GOAL_Compile(g); GOAL_FreeGraph(g); // executor code // executes the earlier schedule built by the inspector for (int i=0; i<T; i++) { // contents of the buffer can change pack_buffer(send_buffer, i, datasize, rank); hndl = GOAL_Run(sched); GOAL_ReuseSchedule(sched); GOAL_Wait(hndl); // verify the contents received check_buffer(recv_buffer, i, datasize, right_neighbor(rank, group_size)); // std::string recv_buff(recv_buffer); // std::cout << "rank: " << rank << ", " << recv_buff.substr(0, datasize) << std::endl; } // std::string recv_buff(recv_buffer); // std::cout << "rank: " << rank << ", " << recv_buff.substr(0, datasize) << std::endl; GOAL_Finalize(); MPI_Finalize(); return 0; }
/// \brief Make this Element with a boolean value. /// /// @param data A boolean to use as the value. /// /// @return A reference to this Element. Element & Element::makeBoolean(bool flag) { // GNASH_REPORT_FUNCTION; _type = Element::BOOLEAN_AMF0; try { check_buffer(1); } catch (std::exception& e) { log_error("%s", e.what()); return *this; } *_buffer = flag; return *this; }