Newer
Older
va_list ap;
int result;
va_start( ap, format);
result = vfprintf( stderr, format, ap);
va_end( ap);
return result;
}
void __attribute__((format(printf,1,2))) fatalerror( const char *format, ...)
{
va_list ap;
va_start( ap, format);
vfprintf( stderr, format, ap);
va_end( ap);
myexit(1);
}
void fatalperror( const char *string)
{
perror( string);
myexit( 1);
}
int __attribute__((format(printf,1,2))) say( const char *format, ...)
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
{
va_list ap;
int result;
va_start( ap, format);
result = vfprintf( stdout, format, ap);
va_end( ap);
return result;
}
char *malloccopy( char *string)
{
char *result;
result = malloc( strlen( string) + 1);
if (result != NULL)
strcpy( result, string);
return result;
}
char *mallocconcat( char *one, char *two)
{
char *result;
result = malloc( strlen( one) + strlen( two) + 1);
if (result != NULL)
{
strcpy( result, one);
strcat( result, two);
}
return result;
}
double double2db( double value)
{
if (value < 0)
value = -value;
return 6.0 * log( value / 32767) / log( 2);
}
void readawaysamples( FILE *input, size_t size)
{
short *buffer;
int samplesread, count;
buffer = malloc( sizeof( *buffer) * BUFFSIZE);
if (buffer == NULL) fatalperror("Couldn't allocate buffer");
while (size > 0)
{
if (size > BUFFSIZE)
count = BUFFSIZE;
else
count = size;
samplesread = fread( buffer, sizeof(*buffer), count, input);
if (ferror( input) != 0)
fatalperror("Error reading input file");
size -= samplesread;
}
free( buffer);
}