rawplayer.c 919 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Rawplayer.c simple raw file stdout player
  3. (c) Anthony C Minessale II <anthmct@yahoo.com>
  4. 2006-03-10: Bruno Rocha <bruno@3gnt.net>
  5. - include <stdlib.h> to remove compiler warning on some platforms
  6. - check for read/write errors (avoid 100% CPU usage in some asterisk failures)
  7. */
  8. #define BUFLEN 320
  9. #include <stdio.h>
  10. #include <sys/types.h>
  11. #include <sys/stat.h>
  12. #include <fcntl.h>
  13. #include <stdlib.h>
  14. static int deliver_file(char *path, int fdout) {
  15. int fd = 0, bytes = 0, error = 0;
  16. short buf[BUFLEN];
  17. if ((fd = open(path,O_RDONLY))) {
  18. while ((bytes=read(fd, buf, BUFLEN)) > 0) {
  19. if(write(fdout, buf, bytes) < 0){
  20. error = -2;
  21. break;
  22. }
  23. }
  24. if(fd)
  25. close(fd);
  26. } else
  27. return -1;
  28. return error;
  29. }
  30. int main(int argc, char *argv[]) {
  31. int x = 0, fdout = 0;
  32. fdout = fileno(stdout);
  33. for (;;)
  34. for (x = 1; x < argc ; x++) {
  35. if(deliver_file(argv[x], fdout))
  36. exit(1);
  37. }
  38. }