static int read_field(int fd, char **buf, int *from, int *to) { /* is buf set ? */ if (! *buf) { *buf = (char *) malloc(PAM_TIME_BUFLEN); if (! *buf) { _log_err("out of memory"); D(("no memory")); return -1; } *from = *to = 0; fd = open(PAM_TIME_CONF, O_RDONLY); } /* do we have a file open ? return error */ if (fd < 0 && *to <= 0) { _log_err( PAM_TIME_CONF " not opened"); memset(*buf, 0, PAM_TIME_BUFLEN); _pam_drop(*buf); return -1; } /* check if there was a newline last time */ if ((*to > *from) && (*to > 0) && ((*buf)[*from] == '\0')) { /* previous line ended */ (*from)++; (*buf)[0] = '\0'; return fd; } /* ready for more data: first shift the buffer's remaining data */ *to -= *from; shift_bytes(*buf, *from, *to); *from = 0; (*buf)[*to] = '\0'; while (fd >= 0 && *to < PAM_TIME_BUFLEN) { int i; /* now try to fill the remainder of the buffer */ i = read(fd, *to + *buf, PAM_TIME_BUFLEN - *to); if (i < 0) { _log_err("error reading " PAM_TIME_CONF); return -1; } else if (!i) { close(fd); fd = -1; /* end of file reached */ } else *to += i; /* * contract the buffer. Delete any comments, and replace all * multiple spaces with single commas */ i = 0; #ifdef DEBUG_DUMP D(("buffer=<%s>",*buf)); #endif while (i < *to) { if ((*buf)[i] == ',') { int j; for (j=++i; j<*to && (*buf)[j] == ','; ++j); if (j!=i) { shift_bytes(i + (*buf), j-i, (*to) - j); *to -= j-i; } } switch ((*buf)[i]) { int j,c; case '#': for (j=i; j < *to && (c = (*buf)[j]) != '\n'; ++j); if (j >= *to) { (*buf)[*to = ++i] = '\0'; } else if (c == '\n') { shift_bytes(i + (*buf), j-i, (*to) - j); *to -= j-i; ++i; } else { _log_err("internal error in " __FILE__ " at line %d", __LINE__ ); return -1; } break; case '\\': if ((*buf)[i+1] == '\n') { shift_bytes(i + *buf, 2, *to - (i+2)); *to -= 2; } else { ++i; /* we don't escape non-newline characters */ } break; case '!': case ' ': case '\t': if ((*buf)[i] != '!') (*buf)[i] = ','; /* delete any trailing spaces */ for (j=++i; j < *to && ( (c = (*buf)[j]) == ' ' || c == '\t' ); ++j); shift_bytes(i + *buf, j-i, (*to)-j ); *to -= j-i; break; default: ++i; } } } (*buf)[*to] = '\0'; /* now return the next field (set the from/to markers) */ { int i; for (i=0; i<*to; ++i) { switch ((*buf)[i]) { case '#': case '\n': /* end of the line/file */ (*buf)[i] = '\0'; *from = i; return fd; case FIELD_SEPARATOR: /* end of the field */ (*buf)[i] = '\0'; *from = ++i; return fd; } } *from = i; (*buf)[*from] = '\0'; } if (*to <= 0) { D(("[end of text]")); *buf = NULL; } return fd; }
void _reentrant verify_result(){ WORD temp, temp1, i; WORD no_words, rem_bytes; WORD bytes = num_bytes; if (sysaddr_mod != 0){ verify_modulo(); return; } if (start_byte_send != start_byte_receive){ shift_bytes(); // update start_byte_send and start_byte_receive start_byte_send = 0; start_byte_receive = 0; } // If start_byte_receive != 0, we check the first address location if (start_byte_receive != 0) { if (start_byte_receive == 1) { if(bytes == 1) { temp = source_data[0] & 0x00FF00; temp1 = returned_data[0] & 0x00FF00; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; } return; } else if (bytes > 1) { temp = source_data[0] & 0xFFFF00; temp1 = returned_data[0] & 0xFFFF00; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; return; } bytes -= 2; } } if (start_byte_receive == 2) { temp = source_data[0] & 0xFF0000; temp1 = returned_data[0] & 0xFF0000; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; return; } bytes--; } no_words = divide(bytes, 3); rem_bytes = modulus(bytes, 3); for (i=1; i <= no_words; i++){ if(source_data[i] != returned_data[i]){ TEST_FAILED; test_result[j++] = extaddr_lo; return; } } } else { // start_byte_receive = 0 no_words = divide(num_bytes,3); rem_bytes = modulus(num_bytes,3); for (i=0; i<no_words; i++){ if(source_data[i] != returned_data[i]){ TEST_FAILED; test_result[j++] = extaddr_lo; return; } } } if (rem_bytes == 1) { // each mem loc = 3 bytes temp = source_data[i] & 0xFF; temp1 = returned_data[i] & 0xFF; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; } } else if (rem_bytes == 2) { temp = source_data[i] & 0xFFFF; temp1 = returned_data[i] & 0xFFFF; if (temp != temp1) { TEST_FAILED; test_result[j++] = extaddr_lo; } } }