| if ((f_in = fopen(buf, "rb")) == NULL) | if ((f_in = fopen(buf, "rb")) == NULL) | ||||
| return create_file_error_context(context, errno, buf); | return create_file_error_context(context, errno, buf); | ||||
| if (*ptr != NULL) | |||||
| if (*ptr != NULL) { | |||||
| free(*ptr); | free(*ptr); | ||||
| *ptr = NULL; | |||||
| } | |||||
| if (length == 0) { | |||||
| *ptr = NULL; | |||||
| return 0; | |||||
| } | |||||
| if ((*ptr = malloc(length)) == NULL) { | if ((*ptr = malloc(length)) == NULL) { | ||||
| fclose(f_in); | fclose(f_in); | ||||
| int error = errno; | int error = errno; | ||||
| fclose(f_in); | fclose(f_in); | ||||
| free(*ptr); | free(*ptr); | ||||
| *ptr = NULL; | |||||
| return create_file_error_context(context, error, buf); | return create_file_error_context(context, error, buf); | ||||
| } | } | ||||
| // read the version number and sample rate from the first 8 bytes of phondata | // read the version number and sample rate from the first 8 bytes of phondata | ||||
| version = 0; // bytes 0-3, version number | version = 0; // bytes 0-3, version number | ||||
| rate = 0; // bytes 4-7, sample rate | rate = 0; // bytes 4-7, sample rate | ||||
| for (ix = 0; ix < 4; ix++) { | |||||
| version += (wavefile_data[ix] << (ix*8)); | |||||
| rate += (wavefile_data[ix+4] << (ix*8)); | |||||
| if (wavefile_data) { | |||||
| for (ix = 0; ix < 4; ix++) { | |||||
| version += (wavefile_data[ix] << (ix*8)); | |||||
| rate += (wavefile_data[ix+4] << (ix*8)); | |||||
| } | |||||
| } | } | ||||
| if (version != version_phdata) | if (version != version_phdata) |