Asterisk - The Open Source Telephony Project  18.5.0
rawplayer.c
Go to the documentation of this file.
1 /*
2  Rawplayer.c simple raw file stdout player
3  (c) Anthony C Minessale II <[email protected]>
4 
5  2006-03-10: Bruno Rocha <[email protected]>
6  - include <stdlib.h> to remove compiler warning on some platforms
7  - check for read/write errors (avoid 100% CPU usage in some asterisk failures)
8 */
9 
10 #define BUFLEN 320
11 #include <stdio.h>
12 #include <sys/types.h>
13 #include <sys/stat.h>
14 #include <fcntl.h>
15 #include <stdlib.h>
16 
17 static int deliver_file(char *path, int fdout) {
18  int fd = 0, bytes = 0, error = 0;
19  short buf[BUFLEN];
20 
21  if ((fd = open(path,O_RDONLY))) {
22  while ((bytes=read(fd, buf, BUFLEN)) > 0) {
23  if(write(fdout, buf, bytes) < 0){
24  error = -2;
25  break;
26  }
27  }
28  if(fd)
29  close(fd);
30  } else
31  return -1;
32 
33  return error;
34 }
35 
36 
37 int main(int argc, char *argv[]) {
38  int x = 0, fdout = 0;
39  fdout = fileno(stdout);
40  for (;;)
41  for (x = 1; x < argc ; x++) {
42  if(deliver_file(argv[x], fdout))
43  exit(1);
44  }
45 }
static int deliver_file(char *path, int fdout)
Definition: rawplayer.c:17
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
#define BUFLEN
Definition: rawplayer.c:10
int error(const char *format,...)
Definition: utils/frame.c:999
int main(int argc, char *argv[])
Definition: rawplayer.c:37