History

Fix read and write return types: now st_size_t, like the size inputs.

To support this change, turn on lots more compiler warnings, and fix all the warnings generated.

rrt committed 19 years ago

Commit 4d743c41 parent ce1f8f393 files · +875 −1236Browse files

Showing the changes to src/misc.c (1 of 93 files). Show all

Unified · Split

src/misc.c+58−21
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #include <math.h>
1616 #include <stdio.h>
1717 #include <stdlib.h>
18+#include <stddef.h>
1819 #include <time.h>
1920 #include <string.h>
2021 #include <ctype.h>
@@ -83,16 +84,16 @@ static const char writerr[] = "Error writing sample file. You are probably out · 62 unmodified lines
8384 * Returns number of elements read, not bytes read.
8485 */
8586
86−st_ssize_t st_readbuf(ft_t ft, void *buf, size_t size, st_size_t len)
87+size_t st_readbuf(ft_t ft, void *buf, size_t size, st_size_t len)
8788 {
8889 return fread(buf, size, len, ft->fp);
8990 }
9091
9192 /* Write a buffer of data of length len and each element is size bytes.
92− * Returns number of elements writen, not bytes writen.
93+ * Returns number of elements writen, not bytes written.
9394 */
9495
95−st_ssize_t st_writebuf(ft_t ft, void const *buf, size_t size, st_size_t len)
96+size_t st_writebuf(ft_t ft, void const *buf, size_t size, st_size_t len)
9697 {
9798 return fwrite(buf, size, len, ft->fp);
9899 }
@@ -157,13 +158,11 @@ int st_reads(ft_t ft, char *c, st_size_t len) · 58 unmodified lines
157158 return (ST_EOF);
158159 }
159160 if (in == 0 || in == '\n')
160− {
161161 break;
162− }
163162
164163 *sc = in;
165164 sc++;
166− } while (sc - c < len);
165+ } while (sc - c < (ptrdiff_t)len);
167166 *sc = 0;
168167 return(ST_SUCCESS);
169168 }
@@ -306,7 +305,7 @@ int st_writedf(ft_t ft, double d) · 136 unmodified lines
306305 }
307306
308307 /* generic swap routine. Swap l and place in to f (datatype length = n) */
309−void st_swapb(char *l, char *f, int n)
308+static void st_swapb(char *l, char *f, int n)
310309 {
311310 register int i;
312311
@@ -358,18 +357,28 @@ double st_swapd(double df) · 45 unmodified lines
358357
359358
360359 /* dummy format routines for do-nothing functions */
361−int st_format_nothing(ft_t ft) { return(ST_SUCCESS); }
362−st_ssize_t st_format_nothing_read_io(ft_t ft, st_sample_t *buf, st_size_t len) { return(0); }
363−st_ssize_t st_format_nothing_write_io(ft_t ft, const st_sample_t *buf, st_size_t len) { return(0); }
364−int st_format_nothing_seek(ft_t ft, st_size_t offset) { st_fail_errno(ft, ST_ENOTSUP, "operation not supported"); return(ST_EOF); }
360+int st_format_nothing(ft_t ft UNUSED) { return(ST_SUCCESS); }
361+st_size_t st_format_nothing_read_io(ft_t ft UNUSED, st_sample_t *buf UNUSED, st_size_t len UNUSED) { return(0); }
362+st_size_t st_format_nothing_write_io(ft_t ft UNUSED, const st_sample_t *buf UNUSED, st_size_t len UNUSED) { return(0); }
363+int st_format_nothing_seek(ft_t ft UNUSED, st_size_t offset UNUSED) { st_fail_errno(ft, ST_ENOTSUP, "operation not supported"); return(ST_EOF); }
365364
366365 /* dummy effect routine for do-nothing functions */
367−int st_effect_nothing(eff_t effp) { return(ST_SUCCESS); }
368−int st_effect_nothing_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp)
366+int st_effect_nothing(eff_t effp UNUSED) { return(ST_SUCCESS); }
367+int st_effect_nothing_drain(eff_t effp UNUSED, st_sample_t *obuf UNUSED, st_size_t *osamp)
369368 { /* Inform no more samples to drain */ *osamp = 0; return(ST_EOF); }
370369
370+int st_effect_nothing_getopts(eff_t effp, int n, char **argv UNUSED)
371+{
372+ if (n) {
373+ st_fail(effp->h->usage);
374+ return (ST_EOF);
375+ }
376+ return (ST_SUCCESS);
377+}
378+
379+
371380 /* here for linear interp. might be useful for other things */
372−st_sample_t st_gcd(st_sample_t a, st_sample_t b)
381+REGPARM(2) st_sample_t st_gcd(st_sample_t a, st_sample_t b)
373382 {
374383 if (b == 0)
375384 return a;
@@ -377,7 +386,7 @@ st_sample_t st_gcd(st_sample_t a, st_sample_t b) · 1 unmodified line
377386 return st_gcd(b, a % b);
378387 }
379388
380−st_sample_t st_lcm(st_sample_t a, st_sample_t b)
389+REGPARM(2) st_sample_t st_lcm(st_sample_t a, st_sample_t b)
381390 {
382391 /* parenthesize this way to avoid st_sample_t overflow in product term */
383392 return a * (b / st_gcd(a, b));
@@ -429,7 +438,7 @@ void st_initrand(void) { · 45 unmodified lines
429438 void st_generate_wave_table(
430439 st_wave_t wave_type,
431440 st_data_t data_type,
432− void * table,
441+ void *table,
433442 uint32_t table_size,
434443 double min,
435444 double max,
@@ -457,19 +466,47 @@ void st_generate_wave_table( · 21 unmodified lines
457466 case 3: d = d - 1.5; break;
458467 }
459468 break;
469+
470+ default: /* Oops! FIXME */
471+ d = 0.0; /* Make sure we have a value */
472+ break;
460473 }
461474 d = d * (max - min) + min;
462475 switch (data_type)
463476 {
464− case ST_FLOAT : *(float *)table = d; table += sizeof(float ); continue;
465− case ST_DOUBLE: *(double *)table = d; table += sizeof(double); continue;
477+ case ST_FLOAT:
478+ {
479+ float *fp = (float *)table;
480+ *fp++ = (float)d;
481+ table = fp;
482+ continue;
483+ }
484+ case ST_DOUBLE:
485+ {
486+ double *dp = (double *)table;
487+ *dp++ = d;
488+ table = dp;
489+ continue;
490+ }
466491 default: break;
467492 }
468493 d += d < 0? -0.5 : +0.5;
469494 switch (data_type)
470495 {
471− case ST_SHORT : *(short *)table = d; table += sizeof(short ); continue;
472− case ST_INT : *(int *)table = d; table += sizeof(int ); continue;
496+ case ST_SHORT:
497+ {
498+ short *sp = table;
499+ *sp++ = (short)d;
500+ table = sp;
501+ continue;
502+ }
503+ case ST_INT:
504+ {
505+ int *ip = table;
506+ *ip++ = (int)d;
507+ table = ip;
508+ continue;
509+ }
473510 default: break;
474511 }
475512 }
@@ -542,5 +579,5 @@ enum_item const * find_enum_text(char const * text, enum_item const * enum_items · 66 unmodified lines
542579 enum_item const st_wave_enum[] = {
543580 ENUM_ITEM(ST_WAVE_,SINE)
544581 ENUM_ITEM(ST_WAVE_,TRIANGLE)
545− {0}};
582+ {0, 0}};
546583

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t