/* ----------------------------- MNI Header ----------------------------------- @NAME : acr_test_byte_ordering @INPUT : afp @OUTPUT : (none) @RETURNS : status. @DESCRIPTION: Tests input for byte ordering to use. @METHOD : @GLOBALS : @CALLS : @CREATED : November 10, 1993 (Peter Neelin) @MODIFIED : ---------------------------------------------------------------------------- */ Acr_Status acr_test_byte_ordering(Acr_File *afp) { int ch, i, buflen; unsigned char buffer[2*ACR_SIZEOF_SHORT+ACR_SIZEOF_LONG]; long data_length; buflen = sizeof(buffer)/sizeof(buffer[0]); /* Read in group id, element id and length of data, get length of data */ for (i=0; i < buflen; i++) { ch = acr_getc(afp); if (ch == EOF) { if (i == 0) return ACR_END_OF_INPUT; else return ACR_PROTOCOL_ERROR; } buffer[i] = ch; } /* Test data length (the first element should be a group length). Try non-vax ordering first. */ (void) acr_set_vax_byte_ordering(FALSE); acr_get_long(1, &buffer[4], &data_length); /* If that doesn't work, set it to vax ordering. */ if (data_length != ACR_SIZEOF_LONG) { (void) acr_set_vax_byte_ordering(TRUE); acr_get_long(1, &buffer[4], &data_length); } /* Put the characters back */ for (i=buflen-1; i >=0; i--) { if (acr_ungetc((int) buffer[i],afp) == EOF) { return ACR_PROTOCOL_ERROR; } } if (data_length != ACR_SIZEOF_LONG) { return ACR_PROTOCOL_ERROR; } else { return ACR_OK; } }
/* ----------------------------- MNI Header ----------------------------------- @NAME : acr_unget_buffer @INPUT : afp nbytes_to_unget buffer @OUTPUT : (none) @RETURNS : Unget status. @DESCRIPTION: Puts a buffer of data back into the input stream. @METHOD : @GLOBALS : @CALLS : @CREATED : February 12, 1997 (Peter Neelin) @MODIFIED : ---------------------------------------------------------------------------- */ Acr_Status acr_unget_buffer(Acr_File *afp, unsigned char buffer[], long nbytes_to_unget) { long i; for (i=nbytes_to_unget-1; i >= 0; i--) { if (acr_ungetc((int) buffer[i], afp) == EOF) { break; } } /* Return the status */ if (i >= 0) { return ACR_IO_ERROR; } else { return ACR_OK; } }