Beispiel #1
0
BinaryTables *
read_binary_tables_internal(FILE *fp, unsigned char *str, 
			    D_ReductionCode spec_code, D_ReductionCode final_code) 
{
  BinaryTablesHead tables;
  int i;
  BinaryTables * binary_tables = MALLOC(sizeof(BinaryTables));
  char *tables_buf, *strings_buf;

  read_chk(&tables, sizeof(BinaryTablesHead), 1, fp, &str);

  tables_buf = MALLOC(tables.tables_size + tables.strings_size);
  read_chk(tables_buf, sizeof(char), tables.tables_size, fp, &str);
  strings_buf = tables_buf + tables.tables_size;
  read_chk(strings_buf, sizeof(char), tables.strings_size, fp, &str);

  for (i=0; i<tables.n_relocs; i++) {
    intptr_t offset;
    void **ptr;
    intptr_t *intptr;
    read_chk((void*)&offset, sizeof(intptr_t), 1, fp, &str);
    intptr = (intptr_t*)(tables_buf+offset);
    ptr = (void**)intptr;
    if (*intptr == -1) {
      *ptr = (void*)0;
    } else if (*intptr == -2) {
      *ptr = (void*)spec_code;
    } else if (*intptr == -3) {
      *ptr = (void*)final_code;
    } else {
      *ptr += (intptr_t)tables_buf;
    }
  }
  for (i=0; i<tables.n_strings; i++) {
    intptr_t offset;
    read_chk((void*)&offset, sizeof(intptr_t), 1, fp, &str);
    *(void**)(tables_buf+offset) += (intptr_t)strings_buf;
  }
  if (fp)
    fclose(fp);

  binary_tables->parser_tables_gram = (D_ParserTables*)(tables_buf + tables.d_parser_tables_loc);
  binary_tables->tables = tables_buf;
  return binary_tables;
}
Beispiel #2
0
void handle_input (int socket_fd)
{
  unsigned char ctrl[1];
  char buf[IO_BUF_SIZE];
  ssize_t count;
  while ( 1 )
    {
      // Read from stdin:
      count = read_chk(STDIN_FILENO, buf, IO_BUF_SIZE);

      // Write control byte:
      ctrl[0] = count;
      write_chk(socket_fd, ctrl, 1);

      // Exit loop if end of data is reached:
      if ( count == 0 )
        break;

      // Write to socket_fd:
      write_chk(socket_fd, buf, count);
    }
}