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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include "snd.h"
#include "sndfileio.h"
#define PERMISSION 0644
#ifdef __cplusplus
extern "C" {
#endif
void snd_fail(char *msg)
{
printf("ERROR: %s\n", msg);
}
int snd_file_open(char *fname, int mode)
{
int file;
if (mode == SND_RDONLY)
mode = O_RDONLY;
else
mode = O_RDWR;
file = open(fname, mode);
return file;
}
int snd_file_creat(char *fname)
{
int file = creat(fname, PERMISSION);
return file;
}
long snd_file_len(int file)
{
long len;
struct stat statbuf;
fstat(file ,&statbuf);
len = (long) statbuf.st_size; /* get length of file */
return len;
}
long snd_file_read(int fp, char *data, long len)
{
return read(fp, data, len);
}
long snd_file_write(int fp, char *data, long len)
{
return write(fp, data, len);
}
int snd_file_close(int fp)
{
return close(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;
return lseek(file, offset, param);
}
void *snd_alloc(size_t s) { return malloc(s); }
void snd_free(void *a) { free(a); }
#ifdef __cplusplus
}
#endif
|