shithub: pplay

ref: 66f0c6706650146103c229e1457d480cf5560cea
dir: /edit.c/

View raw version
#include <u.h>
#include <libc.h>
#include "dat.h"
#include "fns.h"

void
writepcm(char *path)
{
	int n, fd, sz;
	vlong ofs;
	uchar *p;

	if((fd = create(path, OWRITE, 0664)) < 0){
		fprint(2, "create: %r\n");
		return;
	}
	if((sz = iounit(fd)) == 0)
		sz = 8192;
	if(file)
		seek(ifd, loops, 0);
	p = pcmbuf;
	for(ofs=loops; ofs<loope; ofs+=sz){
		n = loope - ofs < sz ? loope - ofs : sz;
		if(!file)
			p = pcmbuf + ofs;
		else if(read(ifd, p, n) != n)
			fprint(2, "read: %r\n");
		if(write(fd, p, n) != n){
			fprint(2, "write: %r\n");
			break;
		}
	}
	close(fd);
	if(file)
		seek(ifd, seekp, 0);
}