1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
#include <stdio.h>
#include "snd.h"
#include "sndfileio.h"
#ifdef __WXMAC__
#include "wx/filefn.h"
#endif
void snd_fail(char *msg)
{
printf("ERROR: %s\n", msg);
}
int snd_file_open(char *fname, int mode)
{
return (int)fopen(fname, mode==SND_RDONLY? "rb" : "r+b");
}
int snd_file_creat(char *fname)
{
return (int)fopen(fname, "wb");
}
long snd_file_len(int file)
{
FILE *fp = (FILE *)file;
long save = ftell(fp);
fseek(fp, 0, SEEK_END);
long len = ftell(fp);
fseek(fp, save, SEEK_SET);
return len;
}
long snd_file_read(int fp, char *data, long len)
{
return fread(data, 1, len, (FILE *)fp);
}
long snd_file_write(int fp, char *data, long len)
{
return fwrite(data, 1, len, (FILE *)fp);
}
int snd_file_close(int fp)
{
return fclose((FILE *)fp);
}
int snd_file_lseek(int file, long offset, int param)
{
if (param == SND_SEEK_CUR) param = SEEK_CUR;
else if (param == SND_SEEK_SET) param = SEEK_SET;
else param = SEEK_END;
fseek((FILE *)file, offset, param);
return ftell((FILE *)file);
}
void *snd_alloc(size_t s) { return malloc(s); }
void snd_free(void *a) { free(a); }
|