Esempio n. 1
0
static int swap(VideoFrame *frame, int datasize, int offset, int shift)
{
    int i, j;
    int oldoffset;
    int newoffset;
    unsigned char *temp = malloc(datasize);
    if (temp == NULL)
    {
        fprintf(stderr, "Couldn't allocate memory for temp\n");
        return 0;
    }
    for (i = 0, j = (frame->height - 1); i < frame->height / 2; i++, j--)
    {
        newoffset = i * datasize + offset;
        if (shift)
            newoffset += datasize;
        oldoffset = j * datasize + offset;
        if (!shift || i != frame->height - 1)
        {
            memcpy(temp, frame->buf + newoffset,
                   datasize); // new -> temp
            reverse_memcpy(frame->buf + newoffset, frame->buf + oldoffset,
                           datasize); // old -> new
            reverse_memcpy(frame->buf + oldoffset, temp,
                           datasize); // temp -> old
        }
    }
    if (temp)
        free(temp);

    return 1;
}
Esempio n. 2
0
void convert_message_to_raw_message(unsigned char *out, const message_ctx *in){

    out[0] = in->tag;
    reverse_memcpy(out+1,&(in->seq_number), 4);
    out[5] = in->length;
    memcpy(out+6,in->data,in->length);
};
Esempio n. 3
0
DMString& DMString::operator+(int number) {

	int targetLength = numberToString(number, number_string_buffer);

	if (this->max_length < this->used_length + targetLength) {
		this->resize(this->used_length + targetLength); //synchronous
	}

	reverse_memcpy(this->char_string + this->used_length, number_string_buffer, targetLength);
	this->used_length = this->used_length + targetLength;

	return *this;
}
void UDPtrans::sendPacket(int x, int y, int v)
{
    int z = 0;
    byte IdVision = 100;
    byte packetlength = 26;

    std::time_t timestamp = std::time(nullptr);

    const byte* xBytes = reinterpret_cast<const byte*>(&x);
    const byte* yBytes = reinterpret_cast<const byte*>(&y);
    const byte* vBytes = reinterpret_cast<const byte*>(&v);
    const byte* zBytes = reinterpret_cast<const byte*>(&z);
    const byte* lenBytes = reinterpret_cast<const byte*>(&packetlength);
    const byte* idBytes = reinterpret_cast<const byte*>(&IdVision);
    const byte* timeBytes = reinterpret_cast<const byte*>(&timestamp);

    char* buff;
    int a = 26;

    buff = new char[a];

    memcpy(buff, lenBytes, 1);
    memcpy(buff + 1, idBytes, 1);
    reverse_memcpy(buff + 2, timeBytes, 8);
    reverse_memcpy(buff + 10, xBytes, 4);
    reverse_memcpy(buff + 14, yBytes, 4);
    reverse_memcpy(buff + 18, zBytes, 4);
    reverse_memcpy(buff + 22, vBytes, 4);

    //send the message
    if (sendto(s, buff, 26, 0, (struct sockaddr *) &si_other, slen) == SOCKET_ERROR)
    {
        printf("sendto() failed with error code : %d", WSAGetLastError());
        exit(EXIT_FAILURE);
    }
}
Esempio n. 5
0
void DMString::format(char * char_string, int targetLength) {

	if (char_string == NULL) {
		return;
	}

	int first_CHAR_AT = -1;
	int second_CHAR_AT = -1;
	for (int i = 0; i < this->used_length; i++) {
		if (*(this->char_string + i) == CHAR_AT) {
			if (first_CHAR_AT == -1) {
				first_CHAR_AT = i;
			} else {
				second_CHAR_AT = i;
				break;
			}
		}
	}

	if (first_CHAR_AT == -1 || second_CHAR_AT == -1) {
		*this * char_string;
		return;
	}

	int formatLength = second_CHAR_AT - first_CHAR_AT + 1;

	if (this->max_length < this->used_length + targetLength - formatLength) {
		this->resize(this->used_length + targetLength - formatLength); //synchronous
	}

	if (formatLength > targetLength) {
		obverse_memcpy_slow(this->char_string + first_CHAR_AT + targetLength, this->char_string + second_CHAR_AT + 1, this->used_length - second_CHAR_AT - 1);

	} else if (formatLength < targetLength) {
		reverse_memcpy(this->char_string + first_CHAR_AT + targetLength, this->char_string + second_CHAR_AT + 1, this->used_length - second_CHAR_AT - 1);
	}

	memcpy(this->char_string + first_CHAR_AT, char_string, targetLength);
	this->used_length = this->used_length + targetLength - formatLength;

	return;
}
static void
unformatted_backspace (st_parameter_filepos *fpp, gfc_unit *u)
{
  gfc_offset m, slen;
  GFC_INTEGER_4 m4;
  GFC_INTEGER_8 m8;
  ssize_t length;
  int continued;
  char p[sizeof (GFC_INTEGER_8)];

  if (compile_options.record_marker == 0)
    length = sizeof (GFC_INTEGER_4);
  else
    length = compile_options.record_marker;

  do
    {
      slen = - (gfc_offset) length;
      if (sseek (u->s, slen, SEEK_CUR) < 0)
        goto io_error;
      if (sread (u->s, p, length) != length)
        goto io_error;

      /* Only GFC_CONVERT_NATIVE and GFC_CONVERT_SWAP are valid here.  */
      if (likely (u->flags.convert == GFC_CONVERT_NATIVE))
	{
	  switch (length)
	    {
	    case sizeof(GFC_INTEGER_4):
	      memcpy (&m4, p, sizeof (m4));
	      m = m4;
	      break;

	    case sizeof(GFC_INTEGER_8):
	      memcpy (&m8, p, sizeof (m8));
	      m = m8;
	      break;

	    default:
	      runtime_error ("Illegal value for record marker");
	      break;
	    }
	}
      else
	{
	  switch (length)
	    {
	    case sizeof(GFC_INTEGER_4):
	      reverse_memcpy (&m4, p, sizeof (m4));
	      m = m4;
	      break;

	    case sizeof(GFC_INTEGER_8):
	      reverse_memcpy (&m8, p, sizeof (m8));
	      m = m8;
	      break;

	    default:
	      runtime_error ("Illegal value for record marker");
	      break;
	    }

	}

      continued = m < 0;
      if (continued)
	m = -m;

      if (sseek (u->s, -m -2 * length, SEEK_CUR) < 0)
	goto io_error;
    } while (continued);

  u->last_record--;
  return;

 io_error:
  generate_error (&fpp->common, LIBERROR_OS, NULL);
}