/* * write method of the file structure */ unsigned int wav_write(struct file *file, unsigned char *data, unsigned int count) { struct wav *f = (struct wav *)file; unsigned int n; if (f->wbytes >= 0 && count > f->wbytes) { count = f->wbytes; /* wbytes fits in count */ if (count == 0) { #ifdef DEBUG if (debug_level >= 3) { wav_dbg(f); dbg_puts(": write complete\n"); } #endif file_hup(&f->pipe.file); return 0; } } n = pipe_write(file, data, count); if (f->wbytes >= 0) f->wbytes -= n; f->endpos += n; return n; }
unsigned int siofile_write(struct file *file, unsigned char *data, unsigned int count) { struct siofile *f = (struct siofile *)file; unsigned int n; #ifdef DEBUG if (f->wtickets == 0) { file_dbg(&f->file); dbg_puts(": called with no write tickets\n"); } #endif if (count > f->wtickets) count = f->wtickets; n = f->started ? sio_write(f->hdl, data, count) : 0; if (n == 0) { f->file.state &= ~FILE_WOK; if (sio_eof(f->hdl)) { #ifdef DEBUG dbg_puts(f->file.name); dbg_puts(": failed to write on device\n"); #endif file_hup(&f->file); } else { #ifdef DEBUG if (debug_level >= 4) { file_dbg(&f->file); dbg_puts(": writing blocked\n"); } #endif } return 0; } else { f->wtickets -= n; if (f->wtickets == 0) { f->file.state &= ~FILE_WOK; #ifdef DEBUG if (debug_level >= 4) { file_dbg(&f->file); dbg_puts(": write tickets exhausted\n"); } #endif } } return n; }