diff --git a/file.c b/file.c
index 47a187d76a743a708b8bba2828a110838b8016f9..c4fac49d149b350af43fc98b51cd3e512b2c0523 100755
--- a/file.c
+++ b/file.c
@@ -59,9 +59,9 @@ struct ast_format {
 	/* Format of frames it uses/provides (one only) */
 	int format;
 	/* Open an input stream, and start playback */
-	struct ast_filestream * (*open)(int fd);
+	struct ast_filestream * (*open)(FILE * f);
 	/* Open an output stream, of a given file descriptor and comment it appropriately if applicable */
-	struct ast_filestream * (*rewrite)(int fd, const char *comment);
+	struct ast_filestream * (*rewrite)(FILE *f, const char *comment);
 	/* Write a frame to a channel */
 	int (*write)(struct ast_filestream *, struct ast_frame *);
 	/* seek num samples into file, whence(think normal seek) */
@@ -103,8 +103,8 @@ AST_MUTEX_DEFINE_STATIC(formatlock);
 static struct ast_format *formats = NULL;
 
 int ast_format_register(const char *name, const char *exts, int format,
-						struct ast_filestream * (*open)(int fd),
-						struct ast_filestream * (*rewrite)(int fd, const char *comment),
+						struct ast_filestream * (*open)(FILE *f),
+						struct ast_filestream * (*rewrite)(FILE *f, const char *comment),
 						int (*write)(struct ast_filestream *, struct ast_frame *),
 						int (*seek)(struct ast_filestream *, long sample_offset, int whence),
 						int (*trunc)(struct ast_filestream *),
@@ -351,6 +351,7 @@ static int ast_filehelper(const char *filename, const char *filename2, const cha
 	struct ast_filestream *s;
 	int res=0, ret = 0;
 	char *ext=NULL, *exts, *fn, *nfn;
+	FILE *bfile;
 	struct ast_channel *chan = (struct ast_channel *)filename2;
 	
 	/* Start with negative response */
@@ -413,9 +414,10 @@ static int ast_filehelper(const char *filename, const char *filename2, const cha
 						case ACTION_OPEN:
 							if ((ret < 0) && ((chan->writeformat & f->format) ||
 										((f->format >= AST_FORMAT_MAX_AUDIO) && fmt))) {
-								ret = open(fn, O_RDONLY);
-								if (ret >= 0) {
-									s = f->open(ret);
+								bfile = fopen(fn, "r");
+								if (bfile) {
+									ret = 1;
+									s = f->open(bfile);
 									if (s) {
 										s->lasttimeout = -1;
 										s->fmt = f;
@@ -426,11 +428,14 @@ static int ast_filehelper(const char *filename, const char *filename2, const cha
 										else
 											chan->vstream = s;
 									} else {
-										close(ret);
-										ast_log(LOG_WARNING, "Unable to open fd on %s\n", fn);
+										fclose(bfile);
+										ast_log(LOG_WARNING, "Unable to open file on %s\n", fn);
+										ret = -1;
 									}
-								} else
+								} else{
 									ast_log(LOG_WARNING, "Couldn't open file %s\n", fn);
+									ret = -1;
+								}
 							}
 							break;
 						default:
@@ -472,7 +477,6 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
 	       set it up.
 		   
 	*/
-	int fd = -1;
 	int fmts = -1;
 	char filename2[256]="";
 	char filename3[256];
@@ -508,8 +512,8 @@ struct ast_filestream *ast_openstream_full(struct ast_channel *chan, const char
 	/* Set the channel to a format we can work with */
 	res = ast_set_write_format(chan, fmts);
 	
- 	fd = ast_filehelper(filename2, (char *)chan, NULL, ACTION_OPEN);
-	if (fd >= 0)
+ 	res = ast_filehelper(filename2, (char *)chan, NULL, ACTION_OPEN);
+	if (res >= 0)
 		return chan->stream;
 	return NULL;
 }
@@ -819,7 +823,7 @@ int ast_streamfile(struct ast_channel *chan, const char *filename, const char *p
 
 struct ast_filestream *ast_readfile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
 {
-	int fd;
+	FILE *bfile;
 	struct ast_format *f;
 	struct ast_filestream *fs = NULL;
 	char *fn;
@@ -834,13 +838,13 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
 			continue;
 
 		fn = build_filename(filename, type);
-		fd = open(fn, flags);
-		if (fd >= 0) {
+		bfile = fopen(fn, "r");
+		if (bfile) {
 			errno = 0;
 
-			if (!(fs = f->open(fd))) {
+			if (!(fs = f->open(bfile))) {
 				ast_log(LOG_WARNING, "Unable to open %s\n", fn);
-				close(fd);
+				fclose(bfile);
 				free(fn);
 				continue;
 			}
@@ -866,6 +870,7 @@ struct ast_filestream *ast_readfile(const char *filename, const char *type, cons
 struct ast_filestream *ast_writefile(const char *filename, const char *type, const char *comment, int flags, int check, mode_t mode)
 {
 	int fd, myflags = 0;
+	FILE *bfile;
 	struct ast_format *f;
 	struct ast_filestream *fs = NULL;
 	char *fn, *orig_fn = NULL;
@@ -893,11 +898,20 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
 
 		fn = build_filename(filename, type);
 		fd = open(fn, flags | myflags, mode);
+		if (fd > -1) {
+			/* fdopen() the resulting file stream */
+			bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w");
+			if (!bfile) {
+				ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
+				close(fd);
+				fd = -1;
+			}
+		}
 		
 		if (option_cache_record_files && fd >= 0) {
 			char *c;
 
-			close(fd);
+			fclose(bfile);
 			/*
 			  We touch orig_fn just as a place-holder so other things (like vmail) see the file is there.
 			  What we are really doing is writing to record_cache_dir until we are done then we will mv the file into place.
@@ -914,11 +928,20 @@ struct ast_filestream *ast_writefile(const char *filename, const char *type, con
 			free(fn);
 			fn = buf;
 			fd = open(fn, flags | myflags, mode);
+			if (fd > -1) {
+				/* fdopen() the resulting file stream */
+				bfile = fdopen(fd, ((flags | myflags) & O_RDWR) ? "w+" : "w");
+				if (!bfile) {
+					ast_log(LOG_WARNING, "Whoa, fdopen failed: %s!\n", strerror(errno));
+					close(fd);
+					fd = -1;
+				}
+			}
 		}
 		if (fd >= 0) {
 			errno = 0;
 
-			if ((fs = f->rewrite(fd, comment))) {
+			if ((fs = f->rewrite(bfile, comment))) {
 				fs->trans = NULL;
 				fs->fmt = f;
 				fs->flags = flags;
diff --git a/formats/format_au.c b/formats/format_au.c
index e49b65041d9cabb46779de53ae57f082fb9752d8..e707d5086bf9e2340277fa2e71688767325ee846 100755
--- a/formats/format_au.c
+++ b/formats/format_au.c
@@ -57,7 +57,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; 				/* Descriptor */
+	FILE *f; 				/* Descriptor */
 	struct ast_channel *owner;
 	struct ast_frame fr;			/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
@@ -98,7 +98,7 @@ static char *exts = "au";
 #endif
 
 
-static int check_header(int fd)
+static int check_header(FILE *f)
 {
 	AU_HEADER(header);
 	u_int32_t magic;
@@ -108,7 +108,7 @@ static int check_header(int fd)
 	u_int32_t sample_rate;
 	u_int32_t channels;
 
-	if (read(fd, header, AU_HEADER_SIZE) != AU_HEADER_SIZE) {
+	if (fread(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
 		ast_log(LOG_WARNING, "Read failed (header)\n");
 		return -1;
 	}
@@ -136,22 +136,24 @@ static int check_header(int fd)
 		return -1;
 	}
 	/* Skip to data */
-	data_size = lseek(fd, 0, SEEK_END) - hdr_size;
-	if (lseek(fd, hdr_size, SEEK_SET) == -1 ) {
+	fseek(f, 0, SEEK_END);
+	data_size = ftell(f) - hdr_size;
+	if (fseek(f, hdr_size, SEEK_SET) == -1 ) {
 		ast_log(LOG_WARNING, "Failed to skip to data: %d\n", hdr_size);
 		return -1;
 	}
 	return data_size;
 }
 
-static int update_header(int fd)
+static int update_header(FILE *f)
 {
 	off_t cur, end;
 	u_int32_t datalen;
 	int bytes;
 
-	cur = lseek(fd, 0, SEEK_CUR);
-	end = lseek(fd, 0, SEEK_END);
+	cur = ftell(f);
+	fseek(f, 0, SEEK_END);
+	end = ftell(f);
 	/* data starts 24 bytes in */
 	bytes = end - AU_HEADER_SIZE;
 	datalen = htoll(bytes);
@@ -160,22 +162,22 @@ static int update_header(int fd)
 		ast_log(LOG_WARNING, "Unable to find our position\n");
 		return -1;
 	}
-	if (lseek(fd, AU_HDR_DATA_SIZE_OFF * sizeof(u_int32_t), SEEK_SET) != (AU_HDR_DATA_SIZE_OFF * sizeof(u_int32_t))) {
+	if (fseek(f, AU_HDR_DATA_SIZE_OFF * sizeof(u_int32_t), SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to set our position\n");
 		return -1;
 	}
-	if (write(fd, &datalen, sizeof(datalen)) != sizeof(datalen)) {
+	if (fwrite(&datalen, 1, sizeof(datalen), f) != sizeof(datalen)) {
 		ast_log(LOG_WARNING, "Unable to set write file size\n");
 		return -1;
 	}
-	if (lseek(fd, cur, SEEK_SET) != cur) {
+	if (fseek(f, cur, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to return to position\n");
 		return -1;
 	}
 	return 0;
 }
 
-static int write_header(int fd)
+static int write_header(FILE *f)
 {
 	AU_HEADER(header);
 
@@ -187,15 +189,15 @@ static int write_header(int fd)
 	header[AU_HDR_CHANNELS_OFF] = htoll(1);
 
 	/* Write an au header, ignoring sizes which will be filled in later */
-	lseek(fd, 0, SEEK_SET);
-	if (write(fd, header, AU_HEADER_SIZE) != AU_HEADER_SIZE) {
+	fseek(f, 0, SEEK_SET);
+	if (fwrite(header, 1, AU_HEADER_SIZE, f) != AU_HEADER_SIZE) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
 	return 0;
 }
 
-static struct ast_filestream *au_open(int fd)
+static struct ast_filestream *au_open(FILE *f)
 {
 	struct ast_filestream *tmp;
 
@@ -205,7 +207,7 @@ static struct ast_filestream *au_open(int fd)
 	}
 
 	memset(tmp, 0, sizeof(struct ast_filestream));
-	if (check_header(fd) < 0) {
+	if (check_header(f) < 0) {
 		free(tmp);
 		return NULL;
 	}
@@ -214,7 +216,7 @@ static struct ast_filestream *au_open(int fd)
 		free(tmp);
 		return NULL;
 	}
-	tmp->fd = fd;
+	tmp->f = f;
 	tmp->fr.data = tmp->buf;
 	tmp->fr.frametype = AST_FRAME_VOICE;
 	tmp->fr.subclass = AST_FORMAT_ULAW;
@@ -227,7 +229,7 @@ static struct ast_filestream *au_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *au_rewrite(int fd, const char *comment)
+static struct ast_filestream *au_rewrite(FILE *f, const char *comment)
 {
 	struct ast_filestream *tmp;
 
@@ -237,7 +239,7 @@ static struct ast_filestream *au_rewrite(int fd, const char *comment)
 	}
 
 	memset(tmp, 0, sizeof(struct ast_filestream));
-	if (write_header(fd)) {
+	if (write_header(f)) {
 		free(tmp);
 		return NULL;
 	}
@@ -246,7 +248,7 @@ static struct ast_filestream *au_rewrite(int fd, const char *comment)
 		free(tmp);
 		return NULL;
 	}
-	tmp->fd = fd;
+	tmp->f = f;
 	localusecnt++;
 	ast_mutex_unlock(&au_lock);
 	ast_update_use_count();
@@ -262,7 +264,7 @@ static void au_close(struct ast_filestream *s)
 	localusecnt--;
 	ast_mutex_unlock(&au_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 }
 
@@ -277,7 +279,7 @@ static struct ast_frame *au_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->buf;
-	if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+	if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -301,11 +303,11 @@ static int au_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Asked to write non-ulaw frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
-	update_header(fs->fd);
+	update_header(fs->f);
 	return 0;
 }
 
@@ -316,8 +318,9 @@ static int au_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	
 	samples = sample_offset;
 	min = AU_HEADER_SIZE;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	if (whence == SEEK_SET)
 		offset = samples + min;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -329,21 +332,21 @@ static int au_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	}
 	/* always protect the header space. */
 	offset = (offset < min) ? min : offset;
-	return lseek(fs->fd, offset, SEEK_SET);
+	return fseek(fs->f, offset, SEEK_SET);
 }
 
 static int au_trunc(struct ast_filestream *fs)
 {
-	if(ftruncate(fs->fd, lseek(fs->fd, 0, SEEK_CUR)))
+	if (ftruncate(fileno(fs->f), ftell(fs->f)))
 		return -1;
-	return update_header(fs->fd);
+	return update_header(fs->f);
 }
 
 static long au_tell(struct ast_filestream *fs)
 {
 	off_t offset;
 
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return offset - AU_HEADER_SIZE;
 }
 
diff --git a/formats/format_g723.c b/formats/format_g723.c
index cbf76daeb8cbaf7fec21bcfc00f35d957e382765..720f2e752e6e0dc3fa55d2439bc19da966c96e62 100755
--- a/formats/format_g723.c
+++ b/formats/format_g723.c
@@ -51,7 +51,7 @@ struct ast_filestream {
 	/* First entry MUST be reserved for the channel type */
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_filestream *next;
 	struct ast_frame *fr;	/* Frame representation of buf */
 	struct timeval orig;	/* Original frame time */
@@ -66,7 +66,7 @@ static char *name = "g723sf";
 static char *desc = "G.723.1 Simple Timestamp File Format";
 static char *exts = "g723|g723sf";
 
-static struct ast_filestream *g723_open(int fd)
+static struct ast_filestream *g723_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -79,7 +79,7 @@ static struct ast_filestream *g723_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr = (struct ast_frame *)tmp->buf;
 		tmp->fr->data = tmp->buf + sizeof(struct ast_frame);
 		tmp->fr->frametype = AST_FRAME_VOICE;
@@ -94,7 +94,7 @@ static struct ast_filestream *g723_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *g723_rewrite(int fd, const char *comment)
+static struct ast_filestream *g723_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -107,7 +107,7 @@ static struct ast_filestream *g723_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&g723_lock);
 		ast_update_use_count();
@@ -122,11 +122,11 @@ static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
 	int res;
 	int delay;
 	/* Read the delay for the next packet, and schedule again if necessary */
-	if (read(s->fd, &delay, 4) == 4) 
+	if (fread(&delay, 1, 4, s->f) == 4) 
 		delay = ntohl(delay);
 	else
 		delay = -1;
-	if (read(s->fd, &size, 2) != 2) {
+	if (fread(&size, 1, 2, s->f) != 2) {
 		/* Out of data, or the file is no longer valid.  In any case
 		   go ahead and stop the stream */
 		return NULL;
@@ -144,7 +144,7 @@ static struct ast_frame *g723_read(struct ast_filestream *s, int *whennext)
 	s->fr->offset = AST_FRIENDLY_OFFSET;
 	s->fr->datalen = size;
 	s->fr->data = s->buf + sizeof(struct ast_frame) + AST_FRIENDLY_OFFSET;
-	if ((res = read(s->fd, s->fr->data , size)) != size) {
+	if ((res = fread(s->fr->data, 1, size, s->f)) != size) {
 		ast_log(LOG_WARNING, "Short read (%d of %d bytes) (%s)!\n", res, size, strerror(errno));
 		return NULL;
 	}
@@ -170,7 +170,7 @@ static void g723_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&g723_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -198,16 +198,16 @@ static int g723_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Short frame ignored (%d bytes long?)\n", f->datalen);
 		return 0;
 	}
-	if ((res = write(fs->fd, &delay, 4)) != 4) {
+	if ((res = fwrite(&delay, 1, 4, fs->f)) != 4) {
 		ast_log(LOG_WARNING, "Unable to write delay: res=%d (%s)\n", res, strerror(errno));
 		return -1;
 	}
 	size = htons(f->datalen);
-	if ((res =write(fs->fd, &size, 2)) != 2) {
+	if ((res = fwrite(&size, 1, 2, fs->f)) != 2) {
 		ast_log(LOG_WARNING, "Unable to write size: res=%d (%s)\n", res, strerror(errno));
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 		ast_log(LOG_WARNING, "Unable to write frame: res=%d (%s)\n", res, strerror(errno));
 		return -1;
 	}	
@@ -222,7 +222,7 @@ static int g723_seek(struct ast_filestream *fs, long sample_offset, int whence)
 static int g723_trunc(struct ast_filestream *fs)
 {
 	/* Truncate file to current length */
-	if (ftruncate(fs->fd, lseek(fs->fd, 0, SEEK_CUR)) < 0)
+	if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
 		return -1;
 	return 0;
 }
diff --git a/formats/format_g726.c b/formats/format_g726.c
index 1e257e216c07379d7a0f967bdb0709ec8a1f8df3..5705a574c3ad5a0ae7711f9bc86f1389c1db5b78 100755
--- a/formats/format_g726.c
+++ b/formats/format_g726.c
@@ -64,7 +64,7 @@ struct ast_filestream {
 	/* Do not place anything before "reserved" */
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; 							/* Open file descriptor */
+	FILE *f; 							/* Open file descriptor */
 	int rate;							/* RATE_* defines */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
@@ -88,7 +88,7 @@ static char *exts16 = "g726-16";
 /*
  * Rate dependant format functions (open, rewrite)
  */
-static struct ast_filestream *g726_40_open(int fd)
+static struct ast_filestream *g726_40_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -101,7 +101,7 @@ static struct ast_filestream *g726_40_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_40;
 		tmp->fr.data = tmp->g726;
 		tmp->fr.frametype = AST_FRAME_VOICE;
@@ -119,7 +119,7 @@ static struct ast_filestream *g726_40_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *g726_32_open(int fd)
+static struct ast_filestream *g726_32_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -132,7 +132,7 @@ static struct ast_filestream *g726_32_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_32;
 		tmp->fr.data = tmp->g726;
 		tmp->fr.frametype = AST_FRAME_VOICE;
@@ -150,7 +150,7 @@ static struct ast_filestream *g726_32_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *g726_24_open(int fd)
+static struct ast_filestream *g726_24_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -163,7 +163,7 @@ static struct ast_filestream *g726_24_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_24;
 		tmp->fr.data = tmp->g726;
 		tmp->fr.frametype = AST_FRAME_VOICE;
@@ -181,7 +181,7 @@ static struct ast_filestream *g726_24_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *g726_16_open(int fd)
+static struct ast_filestream *g726_16_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -194,7 +194,7 @@ static struct ast_filestream *g726_16_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_16;
 		tmp->fr.data = tmp->g726;
 		tmp->fr.frametype = AST_FRAME_VOICE;
@@ -212,7 +212,7 @@ static struct ast_filestream *g726_16_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *g726_40_rewrite(int fd, const char *comment)
+static struct ast_filestream *g726_40_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -225,7 +225,7 @@ static struct ast_filestream *g726_40_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_40;
 		glistcnt++;
 		if (option_debug)
@@ -238,7 +238,7 @@ static struct ast_filestream *g726_40_rewrite(int fd, const char *comment)
 	return tmp;
 }
 
-static struct ast_filestream *g726_32_rewrite(int fd, const char *comment)
+static struct ast_filestream *g726_32_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -251,7 +251,7 @@ static struct ast_filestream *g726_32_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_32;
 		glistcnt++;
 		if (option_debug)
@@ -264,7 +264,7 @@ static struct ast_filestream *g726_32_rewrite(int fd, const char *comment)
 	return tmp;
 }
 
-static struct ast_filestream *g726_24_rewrite(int fd, const char *comment)
+static struct ast_filestream *g726_24_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -277,7 +277,7 @@ static struct ast_filestream *g726_24_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_24;
 		glistcnt++;
 		if (option_debug)
@@ -290,7 +290,7 @@ static struct ast_filestream *g726_24_rewrite(int fd, const char *comment)
 	return tmp;
 }
 
-static struct ast_filestream *g726_16_rewrite(int fd, const char *comment)
+static struct ast_filestream *g726_16_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -303,7 +303,7 @@ static struct ast_filestream *g726_16_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->rate = RATE_16;
 		glistcnt++;
 		if (option_debug)
@@ -330,7 +330,7 @@ static void g726_close(struct ast_filestream *s)
 		ast_log(LOG_DEBUG, "Closed filestream G.726-%dk.\n", 40 - s->rate * 8);
 	ast_mutex_unlock(&g726_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -346,7 +346,7 @@ static struct ast_frame *g726_read(struct ast_filestream *s, int *whennext)
 	s->fr.datalen = frame_size[s->rate];
 	s->fr.mallocd = 0;
 	s->fr.data = s->g726;
-	if ((res = read(s->fd, s->g726, s->fr.datalen)) != s->fr.datalen) {
+	if ((res = fread(s->g726, 1, s->fr.datalen, s->f)) != s->fr.datalen) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -372,7 +372,7 @@ static int g726_write(struct ast_filestream *fs, struct ast_frame *f)
 						f->datalen, frame_size[fs->rate]);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", 
 							res, frame_size[fs->rate], strerror(errno));
 			return -1;
diff --git a/formats/format_g729.c b/formats/format_g729.c
index b38dc90d7fc1b611cf6cbec0a75b0ad06d093186..c23bffce3741b8148772d4685973858e85398841 100755
--- a/formats/format_g729.c
+++ b/formats/format_g729.c
@@ -52,7 +52,7 @@ struct ast_filestream {
 	/* Believe it or not, we must decode/recode to account for the
 	   weird MS format */
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
 	char empty;							/* Empty character */
@@ -67,7 +67,7 @@ static char *name = "g729";
 static char *desc = "Raw G729 data";
 static char *exts = "g729";
 
-static struct ast_filestream *g729_open(int fd)
+static struct ast_filestream *g729_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -80,7 +80,7 @@ static struct ast_filestream *g729_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->g729;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_G729A;
@@ -94,7 +94,7 @@ static struct ast_filestream *g729_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *g729_rewrite(int fd, const char *comment)
+static struct ast_filestream *g729_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -107,7 +107,7 @@ static struct ast_filestream *g729_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&g729_lock);
 		ast_update_use_count();
@@ -125,7 +125,7 @@ static void g729_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&g729_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -141,7 +141,7 @@ static struct ast_frame *g729_read(struct ast_filestream *s, int *whennext)
 	s->fr.datalen = 20;
 	s->fr.mallocd = 0;
 	s->fr.data = s->g729;
-	if ((res = read(s->fd, s->g729, 20)) != 20) {
+	if ((res = fread(s->g729, 1, 20, s->f)) != 20) {
 		if (res && (res != 10))
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -165,7 +165,7 @@ static int g729_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 10\n", f->datalen);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/10): %s\n", res, strerror(errno));
 			return -1;
 	}
@@ -182,8 +182,9 @@ static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	long bytes;
 	off_t min,cur,max,offset=0;
 	min = 0;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	
 	bytes = 20 * (sample_offset / 160);
 	if (whence == SEEK_SET)
@@ -197,7 +198,7 @@ static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	}
 	/* protect against seeking beyond begining. */
 	offset = (offset < min)?min:offset;
-	if (lseek(fs->fd, offset, SEEK_SET) < 0)
+	if (fseek(fs->f, offset, SEEK_SET) < 0)
 		return -1;
 	return 0;
 }
@@ -205,7 +206,7 @@ static int g729_seek(struct ast_filestream *fs, long sample_offset, int whence)
 static int g729_trunc(struct ast_filestream *fs)
 {
 	/* Truncate file to current length */
-	if (ftruncate(fs->fd, lseek(fs->fd, 0, SEEK_CUR)) < 0)
+	if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
 		return -1;
 	return 0;
 }
@@ -213,7 +214,7 @@ static int g729_trunc(struct ast_filestream *fs)
 static long g729_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return (offset/20)*160;
 }
 
diff --git a/formats/format_gsm.c b/formats/format_gsm.c
index 8a218024ec55fe7e195a95de6812a5a76469657b..ec92f713848ea7ee9de07603a58b544505501d30 100755
--- a/formats/format_gsm.c
+++ b/formats/format_gsm.c
@@ -62,7 +62,7 @@ struct ast_filestream {
 	/* Believe it or not, we must decode/recode to account for the
 	   weird MS format */
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
 	char empty;							/* Empty character */
@@ -77,7 +77,7 @@ static char *name = "gsm";
 static char *desc = "Raw GSM data";
 static char *exts = "gsm";
 
-static struct ast_filestream *gsm_open(int fd)
+static struct ast_filestream *gsm_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -90,7 +90,7 @@ static struct ast_filestream *gsm_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->gsm;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_GSM;
@@ -104,7 +104,7 @@ static struct ast_filestream *gsm_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *gsm_rewrite(int fd, const char *comment)
+static struct ast_filestream *gsm_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -117,7 +117,7 @@ static struct ast_filestream *gsm_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&gsm_lock);
 		ast_update_use_count();
@@ -135,7 +135,7 @@ static void gsm_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&gsm_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 }
 
@@ -149,7 +149,7 @@ static struct ast_frame *gsm_read(struct ast_filestream *s, int *whennext)
 	s->fr.datalen = 33;
 	s->fr.mallocd = 0;
 	s->fr.data = s->gsm;
-	if ((res = read(s->fd, s->gsm, 33)) != 33) {
+	if ((res = fread(s->gsm, 1, 33, s->f)) != 33) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -175,7 +175,7 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f)
 		int len=0;
 		while(len < f->datalen) {
 			conv65(f->data + len, gsm);
-			if ((res = write(fs->fd, gsm, 66)) != 66) {
+			if ((res = fwrite(gsm, 1, 66, fs->f)) != 66) {
 				ast_log(LOG_WARNING, "Bad write (%d/66): %s\n", res, strerror(errno));
 				return -1;
 			}
@@ -186,7 +186,7 @@ static int gsm_write(struct ast_filestream *fs, struct ast_frame *f)
 			ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 33\n", f->datalen);
 			return -1;
 		}
-		if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+		if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 				ast_log(LOG_WARNING, "Bad write (%d/33): %s\n", res, strerror(errno));
 				return -1;
 		}
@@ -199,8 +199,9 @@ static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	off_t offset=0,min,cur,max,distance;
 	
 	min = 0;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	/* have to fudge to frame here, so not fully to sample */
 	distance = (sample_offset/160) * 33;
 	if(whence == SEEK_SET)
@@ -215,23 +216,23 @@ static int gsm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 		offset = (offset > max)?max:offset;
 	} else if (offset > max) {
 		int i;
-		lseek(fs->fd, 0, SEEK_END);
+		fseek(fs->f, 0, SEEK_END);
 		for (i=0; i< (offset - max) / 33; i++) {
-			write(fs->fd, gsm_silence, 33);
+			fwrite(gsm_silence, 1, 33, fs->f);
 		}
 	}
-	return lseek(fs->fd, offset, SEEK_SET);
+	return fseek(fs->f, offset, SEEK_SET);
 }
 
 static int gsm_trunc(struct ast_filestream *fs)
 {
-	return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+	return ftruncate(fileno(fs->f), ftell(fs->f));
 }
 
 static long gsm_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return (offset/33)*160;
 }
 
diff --git a/formats/format_h263.c b/formats/format_h263.c
index 809a14788a728b8a5bd25f4e8ad5fc81af3bf7d4..1fc36989d04e78cf5b6178a788ae64743970ac03 100755
--- a/formats/format_h263.c
+++ b/formats/format_h263.c
@@ -52,7 +52,7 @@ struct ast_filestream {
 	/* Believe it or not, we must decode/recode to account for the
 	   weird MS format */
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	unsigned int lastts;
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
@@ -68,7 +68,7 @@ static char *name = "h263";
 static char *desc = "Raw h263 data";
 static char *exts = "h263";
 
-static struct ast_filestream *h263_open(int fd)
+static struct ast_filestream *h263_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -76,7 +76,7 @@ static struct ast_filestream *h263_open(int fd)
 	struct ast_filestream *tmp;
 	unsigned int ts;
 	int res;
-	if ((res = read(fd, &ts, sizeof(ts))) < sizeof(ts)) {
+	if ((res = fread(&ts, 1, sizeof(ts), f)) < sizeof(ts)) {
 		ast_log(LOG_WARNING, "Empty file!\n");
 		return NULL;
 	}
@@ -88,7 +88,7 @@ static struct ast_filestream *h263_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->h263;
 		tmp->fr.frametype = AST_FRAME_VIDEO;
 		tmp->fr.subclass = AST_FORMAT_H263;
@@ -102,7 +102,7 @@ static struct ast_filestream *h263_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *h263_rewrite(int fd, const char *comment)
+static struct ast_filestream *h263_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -115,7 +115,7 @@ static struct ast_filestream *h263_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&h263_lock);
 		ast_update_use_count();
@@ -133,7 +133,7 @@ static void h263_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&h263_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -150,7 +150,7 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->h263;
-	if ((res = read(s->fd, &len, sizeof(len))) < 1) {
+	if ((res = fread(&len, 1, sizeof(len), s->f)) < 1) {
 		return NULL;
 	}
 	len = ntohs(len);
@@ -161,7 +161,7 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
 	if (len > sizeof(s->h263)) {
 		ast_log(LOG_WARNING, "Length %d is too long\n", len);
 	}
-	if ((res = read(s->fd, s->h263, len)) != len) {
+	if ((res = fread(s->h263, 1, len, s->f)) != len) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -171,7 +171,7 @@ static struct ast_frame *h263_read(struct ast_filestream *s, int *whennext)
 	s->fr.subclass |= mark;
 	s->fr.delivery.tv_sec = 0;
 	s->fr.delivery.tv_usec = 0;
-	if ((res = read(s->fd, &ts, sizeof(ts))) == sizeof(ts)) {
+	if ((res = fread(&ts, 1, sizeof(ts), s->f)) == sizeof(ts)) {
 		s->lastts = ntohl(ts);
 		*whennext = s->lastts * 4/45;
 	} else
@@ -199,16 +199,16 @@ static int h263_write(struct ast_filestream *fs, struct ast_frame *f)
 		return -1;
 	}
 	ts = htonl(f->samples);
-	if ((res = write(fs->fd, &ts, sizeof(ts))) != sizeof(ts)) {
+	if ((res = fwrite(&ts, 1, sizeof(ts), fs->f)) != sizeof(ts)) {
 			ast_log(LOG_WARNING, "Bad write (%d/4): %s\n", res, strerror(errno));
 			return -1;
 	}
 	len = htons(f->datalen | mark);
-	if ((res = write(fs->fd, &len, sizeof(len))) != sizeof(len)) {
+	if ((res = fwrite(&len, 1, sizeof(len), fs->f)) != sizeof(len)) {
 			ast_log(LOG_WARNING, "Bad write (%d/2): %s\n", res, strerror(errno));
 			return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
@@ -229,15 +229,16 @@ static int h263_seek(struct ast_filestream *fs, long sample_offset, int whence)
 static int h263_trunc(struct ast_filestream *fs)
 {
 	/* Truncate file to current length */
-	if (ftruncate(fs->fd, lseek(fs->fd, 0, SEEK_CUR)) < 0)
+	if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
 		return -1;
 	return 0;
 }
 
 static long h263_tell(struct ast_filestream *fs)
 {
+	/* XXX This is totally bogus XXX */
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return (offset/20)*160;
 }
 
diff --git a/formats/format_ilbc.c b/formats/format_ilbc.c
index 3689d6c82e3610b8fa86e2613ac2eac60ce5a317..94a85c71deed62140cd55dd8e6db1a081331f69d 100755
--- a/formats/format_ilbc.c
+++ b/formats/format_ilbc.c
@@ -54,7 +54,7 @@ struct ast_filestream {
 	/* Believe it or not, we must decode/recode to account for the
 	   weird MS format */
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
 	char empty;							/* Empty character */
@@ -69,7 +69,7 @@ static char *name = "iLBC";
 static char *desc = "Raw iLBC data";
 static char *exts = "ilbc";
 
-static struct ast_filestream *ilbc_open(int fd)
+static struct ast_filestream *ilbc_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -82,7 +82,7 @@ static struct ast_filestream *ilbc_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->ilbc;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_ILBC;
@@ -96,7 +96,7 @@ static struct ast_filestream *ilbc_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *ilbc_rewrite(int fd, const char *comment)
+static struct ast_filestream *ilbc_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -109,7 +109,7 @@ static struct ast_filestream *ilbc_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&ilbc_lock);
 		ast_update_use_count();
@@ -127,7 +127,7 @@ static void ilbc_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&ilbc_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -143,7 +143,7 @@ static struct ast_frame *ilbc_read(struct ast_filestream *s, int *whennext)
 	s->fr.datalen = 50;
 	s->fr.mallocd = 0;
 	s->fr.data = s->ilbc;
-	if ((res = read(s->fd, s->ilbc, 50)) != 50) {
+	if ((res = fread(s->ilbc, 1, 50, s->f)) != 50) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -167,7 +167,7 @@ static int ilbc_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Invalid data length, %d, should be multiple of 50\n", f->datalen);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/50): %s\n", res, strerror(errno));
 			return -1;
 	}
@@ -184,8 +184,9 @@ static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	long bytes;
 	off_t min,cur,max,offset=0;
 	min = 0;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	
 	bytes = 50 * (sample_offset / 240);
 	if (whence == SEEK_SET)
@@ -199,7 +200,7 @@ static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	}
 	/* protect against seeking beyond begining. */
 	offset = (offset < min)?min:offset;
-	if (lseek(fs->fd, offset, SEEK_SET) < 0)
+	if (fseek(fs->f, offset, SEEK_SET) < 0)
 		return -1;
 	return 0;
 }
@@ -207,7 +208,7 @@ static int ilbc_seek(struct ast_filestream *fs, long sample_offset, int whence)
 static int ilbc_trunc(struct ast_filestream *fs)
 {
 	/* Truncate file to current length */
-	if (ftruncate(fs->fd, lseek(fs->fd, 0, SEEK_CUR)) < 0)
+	if (ftruncate(fileno(fs->f), ftell(fs->f)) < 0)
 		return -1;
 	return 0;
 }
@@ -215,7 +216,7 @@ static int ilbc_trunc(struct ast_filestream *fs)
 static long ilbc_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return (offset/50)*240;
 }
 
diff --git a/formats/format_ogg_vorbis.c b/formats/format_ogg_vorbis.c
index e8cb733f147a7152ccf730e1a02e06d2f8f3a1ec..b39a7741ce8bd81426e909b559425867f5d82562 100755
--- a/formats/format_ogg_vorbis.c
+++ b/formats/format_ogg_vorbis.c
@@ -54,7 +54,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 
-	int fd;
+	FILE *f;
 
 	/* structures for handling the Ogg container */
 	ogg_sync_state	 oy;
@@ -92,10 +92,10 @@ static char *exts = "ogg";
 
 /*!
  * \brief Create a new OGG/Vorbis filestream and set it up for reading.
- * \param fd Descriptor that points to on disk storage of the OGG/Vorbis data.
+ * \param f File that points to on disk storage of the OGG/Vorbis data.
  * \return The new filestream.
  */
-static struct ast_filestream *ogg_vorbis_open(int fd)
+static struct ast_filestream *ogg_vorbis_open(FILE *f)
 {
 	int i;
 	int bytes;
@@ -109,12 +109,12 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 		memset(tmp, 0, sizeof(struct ast_filestream));
 
 		tmp->writing = 0;
-		tmp->fd = fd;
+		tmp->f = f;
 
 		ogg_sync_init(&tmp->oy);
 
 		buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE);
-		bytes = read(tmp->fd, buffer, BLOCK_SIZE);
+		bytes = fread(buffer, 1, BLOCK_SIZE, f);
 		ogg_sync_wrote(&tmp->oy, bytes);
 
 		result = ogg_sync_pageout(&tmp->oy, &tmp->og);
@@ -124,7 +124,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 			} else {
 				ast_log(LOG_ERROR, "Input does not appear to be an Ogg bitstream.\n");
 			}
-			close(fd);
+			fclose(f);
 			ogg_sync_clear(&tmp->oy);
 			free(tmp);
 			return NULL;
@@ -136,7 +136,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 
 		if(ogg_stream_pagein(&tmp->os, &tmp->og) < 0) { 
 			ast_log(LOG_ERROR, "Error reading first page of Ogg bitstream data.\n");
-			close(fd);
+			fclose(f);
 			ogg_stream_clear(&tmp->os);
 			vorbis_comment_clear(&tmp->vc);
 			vorbis_info_clear(&tmp->vi);
@@ -147,7 +147,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 		
 		if(ogg_stream_packetout(&tmp->os, &tmp->op) != 1) { 
 			ast_log(LOG_ERROR, "Error reading initial header packet.\n");
-			close(fd);
+			fclose(f);
 			ogg_stream_clear(&tmp->os);
 			vorbis_comment_clear(&tmp->vc);
 			vorbis_info_clear(&tmp->vi);
@@ -158,7 +158,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 		
 		if(vorbis_synthesis_headerin(&tmp->vi, &tmp->vc, &tmp->op) < 0) { 
 			ast_log(LOG_ERROR, "This Ogg bitstream does not contain Vorbis audio data.\n");
-			close(fd);
+			fclose(f);
 			ogg_stream_clear(&tmp->os);
 			vorbis_comment_clear(&tmp->vc);
 			vorbis_info_clear(&tmp->vi);
@@ -181,7 +181,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 							break;
 						if(result < 0) {
 							ast_log(LOG_ERROR, "Corrupt secondary header.  Exiting.\n");
-							close(fd);
+							fclose(f);
 							ogg_stream_clear(&tmp->os);
 							vorbis_comment_clear(&tmp->vc);
 							vorbis_info_clear(&tmp->vi);
@@ -196,10 +196,10 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 			}
 
 			buffer = ogg_sync_buffer(&tmp->oy, BLOCK_SIZE);
-			bytes = read(tmp->fd, buffer, BLOCK_SIZE);
+			bytes = fread(buffer, 1, BLOCK_SIZE, f);
 			if(bytes == 0 && i < 2) {
 				ast_log(LOG_ERROR, "End of file before finding all Vorbis headers!\n");
-				close(fd);
+				fclose(f);
 				ogg_stream_clear(&tmp->os);
 				vorbis_comment_clear(&tmp->vc);
 				vorbis_info_clear(&tmp->vi);
@@ -231,7 +231,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 
 		if(tmp->vi.rate != 8000) {
 			ast_log(LOG_ERROR, "Only 8000Hz OGG/Vorbis files are currently supported!\n");
-			close(fd);
+			fclose(f);
 			ogg_stream_clear(&tmp->os);
 			vorbis_block_clear(&tmp->vb);
 			vorbis_dsp_clear(&tmp->vd);
@@ -247,7 +247,7 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 
 		if(ast_mutex_lock(&ogg_vorbis_lock)) {
 			ast_log(LOG_WARNING, "Unable to lock ogg_vorbis list\n");
-			close(fd);
+			fclose(f);
 			ogg_stream_clear(&tmp->os);
 			vorbis_block_clear(&tmp->vb);
 			vorbis_dsp_clear(&tmp->vd);
@@ -266,11 +266,11 @@ static struct ast_filestream *ogg_vorbis_open(int fd)
 
 /*!
  * \brief Create a new OGG/Vorbis filestream and set it up for writing.
- * \param fd File descriptor that points to on-disk storage.
+ * \param f File pointer that points to on-disk storage.
  * \param comment Comment that should be embedded in the OGG/Vorbis file.
  * \return A new filestream.
  */
-static struct ast_filestream *ogg_vorbis_rewrite(int fd, const char *comment)
+static struct ast_filestream *ogg_vorbis_rewrite(FILE *f, const char *comment)
 {
 	ogg_packet header;
 	ogg_packet header_comm;
@@ -282,7 +282,7 @@ static struct ast_filestream *ogg_vorbis_rewrite(int fd, const char *comment)
 		memset(tmp, 0, sizeof(struct ast_filestream));
 
 		tmp->writing = 1;
-		tmp->fd = fd;
+		tmp->f = f;
 
 		vorbis_info_init(&tmp->vi);
 
@@ -310,15 +310,15 @@ static struct ast_filestream *ogg_vorbis_rewrite(int fd, const char *comment)
 		while(!tmp->eos) {
 			if(ogg_stream_flush(&tmp->os, &tmp->og) == 0)
 				break;
-			write(tmp->fd, tmp->og.header, tmp->og.header_len);
-			write(tmp->fd, tmp->og.body, tmp->og.body_len);
+			fwrite(tmp->og.header, 1, tmp->og.header_len, tmp->f);
+			fwrite(tmp->og.body, 1, tmp->og.body_len, tmp->f);
 			if(ogg_page_eos(&tmp->og))
 				tmp->eos = 1;
 		}
 
 		if(ast_mutex_lock(&ogg_vorbis_lock)) {
 			ast_log(LOG_WARNING, "Unable to lock ogg_vorbis list\n");
-			close(fd);
+			fclose(f);
 			ogg_stream_clear(&tmp->os);
 			vorbis_block_clear(&tmp->vb);
 			vorbis_dsp_clear(&tmp->vd);
@@ -350,8 +350,8 @@ static void write_stream(struct ast_filestream *s)
 				if(ogg_stream_pageout(&s->os, &s->og) == 0) {
 					break;
 				}
-				write(s->fd, s->og.header, s->og.header_len);
-				write(s->fd, s->og.body, s->og.body_len);
+				fwrite(s->og.header, 1, s->og.header_len, s->f);
+				fwrite(s->og.body, 1, s->og.body_len, s->f);
 				if(ogg_page_eos(&s->og)) {
 					s->eos = 1;
 				}
@@ -434,7 +434,7 @@ static void ogg_vorbis_close(struct ast_filestream *s)
 		ogg_sync_clear(&s->oy);
 	}
 	
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 }
 
@@ -503,7 +503,7 @@ static int read_samples(struct ast_filestream *s, float ***pcm)
 			/* get a buffer from OGG to read the data into */
 			buffer = ogg_sync_buffer(&s->oy, BLOCK_SIZE);
 			/* read more data from the file descriptor */
-			bytes = read(s->fd, buffer, BLOCK_SIZE);
+			bytes = fread(buffer, 1, BLOCK_SIZE, s->f);
 			/* Tell OGG how many bytes we actually read into the buffer */
 			ogg_sync_wrote(&s->oy, bytes);
 			if(bytes == 0) {
diff --git a/formats/format_pcm.c b/formats/format_pcm.c
index dc16935b946d6afe197289ab2977d0bd9df180f7..dcfc3ea776092b0904c02e8b19e503a9e076965c 100755
--- a/formats/format_pcm.c
+++ b/formats/format_pcm.c
@@ -48,7 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_channel *owner;
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
@@ -65,7 +65,7 @@ static char *name = "pcm";
 static char *desc = "Raw uLaw 8khz Audio support (PCM)";
 static char *exts = "pcm|ulaw|ul|mu";
 
-static struct ast_filestream *pcm_open(int fd)
+static struct ast_filestream *pcm_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -78,7 +78,7 @@ static struct ast_filestream *pcm_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->buf;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_ULAW;
@@ -92,7 +92,7 @@ static struct ast_filestream *pcm_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *pcm_rewrite(int fd, const char *comment)
+static struct ast_filestream *pcm_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -105,7 +105,7 @@ static struct ast_filestream *pcm_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&pcm_lock);
 		ast_update_use_count();
@@ -123,7 +123,7 @@ static void pcm_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&pcm_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -139,7 +139,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->buf;
-	if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+	if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -162,7 +162,7 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Asked to write non-ulaw frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
@@ -174,8 +174,9 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	off_t offset=0,min,cur,max;
 
 	min = 0;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	if (whence == SEEK_SET)
 		offset = sample_offset;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -187,18 +188,18 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	}
 	/* always protect against seeking past begining. */
 	offset = (offset < min)?min:offset;
-	return lseek(fs->fd, offset, SEEK_SET);
+	return fseek(fs->f, offset, SEEK_SET);
 }
 
 static int pcm_trunc(struct ast_filestream *fs)
 {
-	return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+	return ftruncate(fileno(fs->f), ftell(fs->f));
 }
 
 static long pcm_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return offset;
 }
 
diff --git a/formats/format_pcm_alaw.c b/formats/format_pcm_alaw.c
index 52c3eeed3be1c994e6666e551c3336b250fecbb6..c9efba1e71f33a56cf83ebe8c54c66d583f6ff1e 100755
--- a/formats/format_pcm_alaw.c
+++ b/formats/format_pcm_alaw.c
@@ -54,7 +54,7 @@ struct ast_filestream {
 	/* Believe it or not, we must decode/recode to account for the
 	   weird MS format */
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
 	char empty;							/* Empty character */
@@ -90,7 +90,7 @@ static unsigned long get_time(void)
 }
 #endif
 
-static struct ast_filestream *pcm_open(int fd)
+static struct ast_filestream *pcm_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -103,7 +103,7 @@ static struct ast_filestream *pcm_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->buf;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_ALAW;
@@ -120,7 +120,7 @@ static struct ast_filestream *pcm_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *pcm_rewrite(int fd, const char *comment)
+static struct ast_filestream *pcm_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -133,7 +133,7 @@ static struct ast_filestream *pcm_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 #ifdef REALTIME_WRITE
 		tmp->start_time = get_time();
 #endif
@@ -154,7 +154,7 @@ static void pcm_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&pcm_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -169,7 +169,7 @@ static struct ast_frame *pcm_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->buf;
-	if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+	if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -204,46 +204,41 @@ static int pcm_write(struct ast_filestream *fs, struct ast_frame *f)
 	/* Check if we have written to this position yet. If we have, then increment pos by one frame
 	*  for some degree of protection against receiving packets in the same clock tick.
 	*/
-	fstat( fs->fd, &stat_buf );
-	if( stat_buf.st_size > fpos )
-	{
+	
+	fstat(fileno(fs->f), &stat_buf );
+	if (stat_buf.st_size > fpos ) {
 		fpos += f->datalen;	/* Incrementing with the size of this current frame */
 	}
 
-	if( stat_buf.st_size < fpos )
-	{
+	if (stat_buf.st_size < fpos) {
 		/* fill the gap with 0x55 rather than 0. */
 		char buf[ 512 ];
 		unsigned long cur, to_write;
 
 		cur = stat_buf.st_size;
-		if( lseek( fs->fd, cur, SEEK_SET ) < 0 )
-		{
+		if (fseek(fs->f, cur, SEEK_SET) < 0) {
 			ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
 			return -1;
 		}
-		memset( buf, 0x55, 512 );
-		while( cur < fpos )
-		{
+		memset(buf, 0x55, 512);
+		while (cur < fpos) {
 			to_write = fpos - cur;
-			if( to_write > 512 )
-			{
+			if (to_write > 512) {
 				to_write = 512;
 			}
-			write( fs->fd, buf, to_write );
+			fwrite(buf, 1, to_write, fs->f);
 			cur += to_write;
 		}
 	}
 
 
-	if( lseek( fs->fd, fpos, SEEK_SET ) < 0 )
-	{
+	if (fseek(s->f, fpos, SEEK_SET) < 0) {
 		ast_log( LOG_WARNING, "Cannot seek in file: %s\n", strerror(errno) );
 		return -1;
 	}
 #endif	/* REALTIME_WRITE */
 	
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
@@ -255,8 +250,9 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	off_t offset=0,min,cur,max;
 
 	min = 0;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	if (whence == SEEK_SET)
 		offset = sample_offset;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -268,18 +264,18 @@ static int pcm_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	}
 	/* Always protect against seeking past begining */
 	offset = (offset < min)?min:offset;
-	return lseek(fs->fd, offset, SEEK_SET);
+	return fseek(fs->f, offset, SEEK_SET);
 }
 
 static int pcm_trunc(struct ast_filestream *fs)
 {
-	return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+	return ftruncate(fileno(fs->f), ftell(fs->f));
 }
 
 static long pcm_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return offset;
 }
 
diff --git a/formats/format_sln.c b/formats/format_sln.c
index 3a783e0af81d738d8b18041090a35872f462f117..6e056aa0ff62dc7293c050ee802458bc31c0e9fc 100755
--- a/formats/format_sln.c
+++ b/formats/format_sln.c
@@ -47,7 +47,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_channel *owner;
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
@@ -64,7 +64,7 @@ static char *name = "sln";
 static char *desc = "Raw Signed Linear Audio support (SLN)";
 static char *exts = "sln|raw";
 
-static struct ast_filestream *slinear_open(int fd)
+static struct ast_filestream *slinear_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -77,7 +77,7 @@ static struct ast_filestream *slinear_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->buf;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_SLINEAR;
@@ -91,7 +91,7 @@ static struct ast_filestream *slinear_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *slinear_rewrite(int fd, const char *comment)
+static struct ast_filestream *slinear_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -104,7 +104,7 @@ static struct ast_filestream *slinear_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&slinear_lock);
 		ast_update_use_count();
@@ -122,7 +122,7 @@ static void slinear_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&slinear_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -138,7 +138,7 @@ static struct ast_frame *slinear_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->buf;
-	if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+	if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -161,7 +161,7 @@ static int slinear_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Asked to write non-slinear frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
@@ -174,8 +174,9 @@ static int slinear_seek(struct ast_filestream *fs, long sample_offset, int whenc
 
 	min = 0;
 	sample_offset <<= 1;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	if (whence == SEEK_SET)
 		offset = sample_offset;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -187,18 +188,18 @@ static int slinear_seek(struct ast_filestream *fs, long sample_offset, int whenc
 	}
 	/* always protect against seeking past begining. */
 	offset = (offset < min)?min:offset;
-	return lseek(fs->fd, offset, SEEK_SET) / 2;
+	return fseek(fs->f, offset, SEEK_SET) / 2;
 }
 
 static int slinear_trunc(struct ast_filestream *fs)
 {
-	return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+	return ftruncate(fileno(fs->f), ftell(fs->f));
 }
 
 static long slinear_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	return offset / 2;
 }
 
diff --git a/formats/format_vox.c b/formats/format_vox.c
index f63570d6ef234834a50c32e66c15135ee1aac989..1c1e955242ae0ae351debb3ad4399aa5783160fe 100755
--- a/formats/format_vox.c
+++ b/formats/format_vox.c
@@ -48,7 +48,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
 	char empty;							/* Empty character */
@@ -69,7 +69,7 @@ static char *name = "vox";
 static char *desc = "Dialogic VOX (ADPCM) File Format";
 static char *exts = "vox";
 
-static struct ast_filestream *vox_open(int fd)
+static struct ast_filestream *vox_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -82,7 +82,7 @@ static struct ast_filestream *vox_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->buf;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_ADPCM;
@@ -97,7 +97,7 @@ static struct ast_filestream *vox_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *vox_rewrite(int fd, const char *comment)
+static struct ast_filestream *vox_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -110,7 +110,7 @@ static struct ast_filestream *vox_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&vox_lock);
 		ast_update_use_count();
@@ -128,7 +128,7 @@ static void vox_close(struct ast_filestream *s)
 	glistcnt--;
 	ast_mutex_unlock(&vox_lock);
 	ast_update_use_count();
-	close(s->fd);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -142,7 +142,7 @@ static struct ast_frame *vox_read(struct ast_filestream *s, int *whennext)
 	s->fr.offset = AST_FRIENDLY_OFFSET;
 	s->fr.mallocd = 0;
 	s->fr.data = s->buf;
-	if ((res = read(s->fd, s->buf, BUF_SIZE)) < 1) {
+	if ((res = fread(s->buf, 1, BUF_SIZE, s->f)) < 1) {
 		if (res)
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		return NULL;
@@ -164,7 +164,7 @@ static int vox_write(struct ast_filestream *fs, struct ast_frame *f)
 		ast_log(LOG_WARNING, "Asked to write non-ADPCM frame (%d)!\n", f->subclass);
 		return -1;
 	}
-	if ((res = write(fs->fd, f->data, f->datalen)) != f->datalen) {
+	if ((res = fwrite(f->data, 1, f->datalen, fs->f)) != f->datalen) {
 			ast_log(LOG_WARNING, "Bad write (%d/%d): %s\n", res, f->datalen, strerror(errno));
 			return -1;
 	}
@@ -181,8 +181,10 @@ static int vox_seek(struct ast_filestream *fs, long sample_offset, int whence)
      off_t offset=0,min,cur,max,distance;
 	
      min = 0;
-     cur = lseek(fs->fd, 0, SEEK_CUR);
-     max = lseek(fs->fd, 0, SEEK_END);
+     cur = ftell(fs->f);
+     fseek(fs->f, 0, SEEK_END);
+	 max = ftell(fs->f);
+	 
      /* have to fudge to frame here, so not fully to sample */
      distance = sample_offset/2;
      if(whence == SEEK_SET)
@@ -195,18 +197,19 @@ static int vox_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	  offset = (offset > max)?max:offset;
 	  offset = (offset < min)?min:offset;
      }
-     return lseek(fs->fd, offset, SEEK_SET);
+     fseek(fs->f, offset, SEEK_SET);
+	 return ftell(fs->f);
 }
 
 static int vox_trunc(struct ast_filestream *fs)
 {
-     return ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR));
+     return ftruncate(fileno(fs->f), ftell(fs->f));
 }
 
 static long vox_tell(struct ast_filestream *fs)
 {
      off_t offset;
-     offset = lseek(fs->fd, 0, SEEK_CUR);
+     offset = ftell(fs->f) << 1;
      return offset; 
 }
 
diff --git a/formats/format_wav.c b/formats/format_wav.c
index 4fb97473f321a17c9e0ba05eedd4a5a1ade3729a..7d212b409b0ff564fc45c16e572985f4a42aed9f 100755
--- a/formats/format_wav.c
+++ b/formats/format_wav.c
@@ -50,7 +50,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 struct ast_filestream {
 	void *reserved[AST_RESERVED_POINTERS];
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	int bytes;
 	int needsgain;
 	struct ast_frame fr;				/* Frame information */
@@ -98,7 +98,7 @@ static char *exts = "wav";
 #endif
 
 
-static int check_header(int fd)
+static int check_header(FILE *f)
 {
 	int type, size, formtype;
 	int fmt, hsize;
@@ -106,16 +106,16 @@ static int check_header(int fd)
 	int bysec;
 	int freq;
 	int data;
-	if (read(fd, &type, 4) != 4) {
+	if (fread(&type, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (type)\n");
 		return -1;
 	}
-	if (read(fd, &size, 4) != 4) {
+	if (fread(&size, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (size)\n");
 		return -1;
 	}
 	size = ltohl(size);
-	if (read(fd, &formtype, 4) != 4) {
+	if (fread(&formtype, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (formtype)\n");
 		return -1;
 	}
@@ -127,7 +127,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Does not contain WAVE\n");
 		return -1;
 	}
-	if (read(fd, &fmt, 4) != 4) {
+	if (fread(&fmt, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (fmt)\n");
 		return -1;
 	}
@@ -135,7 +135,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Does not say fmt\n");
 		return -1;
 	}
-	if (read(fd, &hsize, 4) != 4) {
+	if (fread(&hsize, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (formtype)\n");
 		return -1;
 	}
@@ -143,7 +143,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
 		return -1;
 	}
-	if (read(fd, &format, 2) != 2) {
+	if (fread(&format, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Read failed (format)\n");
 		return -1;
 	}
@@ -151,7 +151,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Not a wav file %d\n", ltohs(format));
 		return -1;
 	}
-	if (read(fd, &chans, 2) != 2) {
+	if (fread(&chans, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Read failed (format)\n");
 		return -1;
 	}
@@ -159,7 +159,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
 		return -1;
 	}
-	if (read(fd, &freq, 4) != 4) {
+	if (fread(&freq, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (freq)\n");
 		return -1;
 	}
@@ -168,12 +168,12 @@ static int check_header(int fd)
 		return -1;
 	}
 	/* Ignore the byte frequency */
-	if (read(fd, &bysec, 4) != 4) {
+	if (fread(&bysec, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SECOND)\n");
 		return -1;
 	}
 	/* Check bytes per sample */
-	if (read(fd, &bysam, 2) != 2) {
+	if (fread(&bysam, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SAMPLE)\n");
 		return -1;
 	}
@@ -181,39 +181,40 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Can only handle 16bits per sample: %d\n", ltohs(bysam));
 		return -1;
 	}
-	if (read(fd, &bisam, 2) != 2) {
+	if (fread(&bisam, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
 		return -1;
 	}
 	/* Skip any additional header */
-	if ( lseek(fd,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
+	if (fseek(f,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
 		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
 		return -1;
 	}
 	/* Skip any facts and get the first data block */
 	for(;;)
 	{ 
-            char buf[4];
+		char buf[4];
 	    
 	    /* Begin data chunk */
-	    if (read(fd, &buf, 4) != 4) {
-		ast_log(LOG_WARNING, "Read failed (data)\n");
-		return -1;
+	    if (fread(&buf, 1, 4, f) != 4) {
+			ast_log(LOG_WARNING, "Read failed (data)\n");
+			return -1;
 	    }
 	    /* Data has the actual length of data in it */
-	    if (read(fd, &data, 4) != 4) {
-		ast_log(LOG_WARNING, "Read failed (data)\n");
-		return -1;
+	    if (fread(&data, 1, 4, f) != 4) {
+			ast_log(LOG_WARNING, "Read failed (data)\n");
+			return -1;
 	    }
 	    data = ltohl(data);
-	    if( memcmp(buf, "data", 4) == 0 ) break;
-	    if( memcmp(buf, "fact", 4) != 0 ) {
-		ast_log(LOG_WARNING, "Unknown block - not fact or data\n");
-		return -1;
+	    if(memcmp(buf, "data", 4) == 0 ) 
+			break;
+	    if(memcmp(buf, "fact", 4) != 0 ) {
+			ast_log(LOG_WARNING, "Unknown block - not fact or data\n");
+			return -1;
 	    }
-	    if ( lseek(fd,data,SEEK_CUR) == -1 ) {
-		ast_log(LOG_WARNING, "Failed to skip fact block: %d\n", data );
-		return -1;
+	    if (fseek(f,data,SEEK_CUR) == -1 ) {
+			ast_log(LOG_WARNING, "Failed to skip fact block: %d\n", data );
+			return -1;
 	    }
 	}
 #if 0
@@ -225,14 +226,15 @@ static int check_header(int fd)
 	return data;
 }
 
-static int update_header(int fd)
+static int update_header(FILE *f)
 {
 	off_t cur,end;
 	int datalen,filelen,bytes;
 	
 	
-	cur = lseek(fd, 0, SEEK_CUR);
-	end = lseek(fd, 0, SEEK_END);
+	cur = ftell(f);
+	fseek(f, 0, SEEK_END);
+	end = ftell(f);
 	/* data starts 44 bytes in */
 	bytes = end - 44;
 	datalen = htoll(bytes);
@@ -243,30 +245,30 @@ static int update_header(int fd)
 		ast_log(LOG_WARNING, "Unable to find our position\n");
 		return -1;
 	}
-	if (lseek(fd, 4, SEEK_SET) != 4) {
+	if (fseek(f, 4, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to set our position\n");
 		return -1;
 	}
-	if (write(fd, &filelen, 4) != 4) {
+	if (fwrite(&filelen, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to set write file size\n");
 		return -1;
 	}
-	if (lseek(fd, 40, SEEK_SET) != 40) {
+	if (fseek(f, 40, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to set our position\n");
 		return -1;
 	}
-	if (write(fd, &datalen, 4) != 4) {
+	if (fwrite(&datalen, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to set write datalen\n");
 		return -1;
 	}
-	if (lseek(fd, cur, SEEK_SET) != cur) {
+	if (fseek(f, cur, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to return to position\n");
 		return -1;
 	}
 	return 0;
 }
 
-static int write_header(int fd)
+static int write_header(FILE *f)
 {
 	unsigned int hz=htoll(8000);
 	unsigned int bhz = htoll(16000);
@@ -277,59 +279,59 @@ static int write_header(int fd)
 	unsigned short bisam = htols(16);
 	unsigned int size = htoll(0);
 	/* Write a wav header, ignoring sizes which will be filled in later */
-	lseek(fd,0,SEEK_SET);
-	if (write(fd, "RIFF", 4) != 4) {
+	fseek(f,0,SEEK_SET);
+	if (fwrite("RIFF", 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &size, 4) != 4) {
+	if (fwrite(&size, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, "WAVEfmt ", 8) != 8) {
+	if (fwrite("WAVEfmt ", 1, 8, f) != 8) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &hs, 4) != 4) {
+	if (fwrite(&hs, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &fmt, 2) != 2) {
+	if (fwrite(&fmt, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &chans, 2) != 2) {
+	if (fwrite(&chans, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &hz, 4) != 4) {
+	if (fwrite(&hz, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &bhz, 4) != 4) {
+	if (fwrite(&bhz, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &bysam, 2) != 2) {
+	if (fwrite(&bysam, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &bisam, 2) != 2) {
+	if (fwrite(&bisam, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, "data", 4) != 4) {
+	if (fwrite("data", 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &size, 4) != 4) {
+	if (fwrite(&size, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
 	return 0;
 }
 
-static struct ast_filestream *wav_open(int fd)
+static struct ast_filestream *wav_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -337,7 +339,7 @@ static struct ast_filestream *wav_open(int fd)
 	struct ast_filestream *tmp;
 	if ((tmp = malloc(sizeof(struct ast_filestream)))) {
 		memset(tmp, 0, sizeof(struct ast_filestream));
-		if ((tmp->maxlen = check_header(fd)) < 0) {
+		if ((tmp->maxlen = check_header(f)) < 0) {
 			free(tmp);
 			return NULL;
 		}
@@ -346,7 +348,7 @@ static struct ast_filestream *wav_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->needsgain = 1;
 		tmp->fr.data = tmp->buf;
 		tmp->fr.frametype = AST_FRAME_VOICE;
@@ -362,7 +364,7 @@ static struct ast_filestream *wav_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *wav_rewrite(int fd, const char *comment)
+static struct ast_filestream *wav_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -370,7 +372,7 @@ static struct ast_filestream *wav_rewrite(int fd, const char *comment)
 	struct ast_filestream *tmp;
 	if ((tmp = malloc(sizeof(struct ast_filestream)))) {
 		memset(tmp, 0, sizeof(struct ast_filestream));
-		if (write_header(fd)) {
+		if (write_header(f)) {
 			free(tmp);
 			return NULL;
 		}
@@ -379,7 +381,7 @@ static struct ast_filestream *wav_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&wav_lock);
 		ast_update_use_count();
@@ -400,8 +402,8 @@ static void wav_close(struct ast_filestream *s)
 	ast_update_use_count();
 	/* Pad to even length */
 	if (s->bytes & 0x1)
-		write(s->fd, &zero, 1);
-	close(s->fd);
+		fwrite(&zero, 1, 1, s->f);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -415,14 +417,14 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
 	int bytes = sizeof(tmp);
 	off_t here;
 	/* Send a frame from the file to the appropriate channel */
-	here = lseek(s->fd, 0, SEEK_CUR);
+	here = ftell(s->f);
 	if ((s->maxlen - here) < bytes)
 		bytes = s->maxlen - here;
 	if (bytes < 0)
 		bytes = 0;
 /* 	ast_log(LOG_DEBUG, "here: %d, maxlen: %d, bytes: %d\n", here, s->maxlen, bytes); */
 	
-	if ( (res = read(s->fd, tmp, bytes)) <= 0 ) {
+	if ( (res = fread(tmp, 1, bytes, s->f)) <= 0 ) {
 		if (res) {
 			ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 		}
@@ -503,7 +505,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
 #endif
 
 		}
-		if ((write (fs->fd, tmp, f->datalen) != f->datalen) ) {
+		if ((fwrite(tmp, 1, f->datalen, fs->f) != f->datalen) ) {
 			ast_log(LOG_WARNING, "Bad write (%d): %s\n", res, strerror(errno));
 			return -1;
 		}
@@ -513,7 +515,7 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
 	}
 	
 	fs->bytes += f->datalen;
-	update_header(fs->fd);
+	update_header(fs->f);
 		
 	return 0;
 
@@ -526,8 +528,9 @@ static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	
 	samples = sample_offset * 2; /* SLINEAR is 16 bits mono, so sample_offset * 2 = bytes */
 	min = 44; /* wav header is 44 bytes */
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	if (whence == SEEK_SET)
 		offset = samples + min;
 	else if (whence == SEEK_CUR || whence == SEEK_FORCECUR)
@@ -539,20 +542,20 @@ static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
 	}
 	/* always protect the header space. */
 	offset = (offset < min)?min:offset;
-	return lseek(fs->fd,offset,SEEK_SET);
+	return fseek(fs->f,offset,SEEK_SET);
 }
 
 static int wav_trunc(struct ast_filestream *fs)
 {
-	if(ftruncate(fs->fd, lseek(fs->fd,0,SEEK_CUR)))
+	if (ftruncate(fileno(fs->f), ftell(fs->f)))
 		return -1;
-	return update_header(fs->fd);
+	return update_header(fs->f);
 }
 
 static long wav_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	/* subtract header size to get samples, then divide by 2 for 16 bit samples */
 	return (offset - 44)/2;
 }
diff --git a/formats/format_wav_gsm.c b/formats/format_wav_gsm.c
index 8c895eda21dc1515a2526df69be42cd7a14e41bb..9c1f7b637a2c5759ae40c017bdf8b6a3e69787bf 100755
--- a/formats/format_wav_gsm.c
+++ b/formats/format_wav_gsm.c
@@ -63,7 +63,7 @@ struct ast_filestream {
 	/* Believe it or not, we must decode/recode to account for the
 	   weird MS format */
 	/* This is what a filestream means to us */
-	int fd; /* Descriptor */
+	FILE *f; /* Descriptor */
 	struct ast_frame fr;				/* Frame information */
 	char waste[AST_FRIENDLY_OFFSET];	/* Buffer for sending frames, etc */
 	char empty;							/* Empty character */
@@ -104,23 +104,23 @@ static char *exts = "WAV|wav49";
 #endif
 
 
-static int check_header(int fd)
+static int check_header(FILE *f)
 {
 	int type, size, formtype;
 	int fmt, hsize, fact;
 	short format, chans;
 	int freq;
 	int data;
-	if (read(fd, &type, 4) != 4) {
+	if (fread(&type, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (type)\n");
 		return -1;
 	}
-	if (read(fd, &size, 4) != 4) {
+	if (fread(&size, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (size)\n");
 		return -1;
 	}
 	size = ltohl(size);
-	if (read(fd, &formtype, 4) != 4) {
+	if (fread(&formtype, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (formtype)\n");
 		return -1;
 	}
@@ -132,7 +132,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Does not contain WAVE\n");
 		return -1;
 	}
-	if (read(fd, &fmt, 4) != 4) {
+	if (fread(&fmt, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (fmt)\n");
 		return -1;
 	}
@@ -140,7 +140,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Does not say fmt\n");
 		return -1;
 	}
-	if (read(fd, &hsize, 4) != 4) {
+	if (fread(&hsize, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (formtype)\n");
 		return -1;
 	}
@@ -148,7 +148,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
 		return -1;
 	}
-	if (read(fd, &format, 2) != 2) {
+	if (fread(&format, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Read failed (format)\n");
 		return -1;
 	}
@@ -156,7 +156,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Not a GSM file %d\n", ltohs(format));
 		return -1;
 	}
-	if (read(fd, &chans, 2) != 2) {
+	if (fread(&chans, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Read failed (format)\n");
 		return -1;
 	}
@@ -164,7 +164,7 @@ static int check_header(int fd)
 		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
 		return -1;
 	}
-	if (read(fd, &freq, 4) != 4) {
+	if (fread(&freq, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (freq)\n");
 		return -1;
 	}
@@ -173,22 +173,22 @@ static int check_header(int fd)
 		return -1;
 	}
 	/* Ignore the byte frequency */
-	if (read(fd, &freq, 4) != 4) {
+	if (fread(&freq, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (X_1)\n");
 		return -1;
 	}
 	/* Ignore the two weird fields */
-	if (read(fd, &freq, 4) != 4) {
+	if (fread(&freq, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (X_2/X_3)\n");
 		return -1;
 	}
 	/* Ignore the byte frequency */
-	if (read(fd, &freq, 4) != 4) {
+	if (fread(&freq, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (Y_1)\n");
 		return -1;
 	}
 	/* Check for the word fact */
-	if (read(fd, &fact, 4) != 4) {
+	if (fread(&fact, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (fact)\n");
 		return -1;
 	}
@@ -197,16 +197,16 @@ static int check_header(int fd)
 		return -1;
 	}
 	/* Ignore the "fact value" */
-	if (read(fd, &fact, 4) != 4) {
+	if (fread(&fact, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (fact header)\n");
 		return -1;
 	}
-	if (read(fd, &fact, 4) != 4) {
+	if (fread(&fact, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (fact value)\n");
 		return -1;
 	}
 	/* Check for the word data */
-	if (read(fd, &data, 4) != 4) {
+	if (fread(&data, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (data)\n");
 		return -1;
 	}
@@ -215,20 +215,21 @@ static int check_header(int fd)
 		return -1;
 	}
 	/* Ignore the data length */
-	if (read(fd, &data, 4) != 4) {
+	if (fread(&data, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (data)\n");
 		return -1;
 	}
 	return 0;
 }
 
-static int update_header(int fd)
+static int update_header(FILE *f)
 {
 	off_t cur,end,bytes;
 	int datalen,filelen;
 	
-	cur = lseek(fd, 0, SEEK_CUR);
-	end = lseek(fd, 0, SEEK_END);
+	cur = ftell(f);
+	fseek(f, 0, SEEK_END);
+	end = ftell(f);
 	/* in a gsm WAV, data starts 60 bytes in */
 	bytes = end - 60;
 	datalen = htoll((bytes + 1) & ~0x1);
@@ -237,30 +238,30 @@ static int update_header(int fd)
 		ast_log(LOG_WARNING, "Unable to find our position\n");
 		return -1;
 	}
-	if (lseek(fd, 4, SEEK_SET) != 4) {
+	if (fseek(f, 4, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to set our position\n");
 		return -1;
 	}
-	if (write(fd, &filelen, 4) != 4) {
+	if (fwrite(&filelen, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to set write file size\n");
 		return -1;
 	}
-	if (lseek(fd, 56, SEEK_SET) != 56) {
+	if (fseek(f, 56, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to set our position\n");
 		return -1;
 	}
-	if (write(fd, &datalen, 4) != 4) {
+	if (fwrite(&datalen, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to set write datalen\n");
 		return -1;
 	}
-	if (lseek(fd, cur, SEEK_SET) != cur) {
+	if (fseek(f, cur, SEEK_SET)) {
 		ast_log(LOG_WARNING, "Unable to return to position\n");
 		return -1;
 	}
 	return 0;
 }
 
-static int write_header(int fd)
+static int write_header(FILE *f)
 {
 	unsigned int hz=htoll(8000);
 	unsigned int bhz = htoll(1625);
@@ -274,74 +275,74 @@ static int write_header(int fd)
 	unsigned int y_1 = htoll(20160);
 	unsigned int size = htoll(0);
 	/* Write a GSM header, ignoring sizes which will be filled in later */
-	if (write(fd, "RIFF", 4) != 4) {
+	if (fwrite("RIFF", 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &size, 4) != 4) {
+	if (fwrite(&size, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, "WAVEfmt ", 8) != 8) {
+	if (fwrite("WAVEfmt ", 1, 8, f) != 8) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &hs, 4) != 4) {
+	if (fwrite(&hs, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &fmt, 2) != 2) {
+	if (fwrite(&fmt, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &chans, 2) != 2) {
+	if (fwrite(&chans, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &hz, 4) != 4) {
+	if (fwrite(&hz, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &bhz, 4) != 4) {
+	if (fwrite(&bhz, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &x_1, 4) != 4) {
+	if (fwrite(&x_1, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &x_2, 2) != 2) {
+	if (fwrite(&x_2, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &x_3, 2) != 2) {
+	if (fwrite(&x_3, 1, 2, f) != 2) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, "fact", 4) != 4) {
+	if (fwrite("fact", 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &fhs, 4) != 4) {
+	if (fwrite(&fhs, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &y_1, 4) != 4) {
+	if (fwrite(&y_1, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, "data", 4) != 4) {
+	if (fwrite("data", 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
-	if (write(fd, &size, 4) != 4) {
+	if (fwrite(&size, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Unable to write header\n");
 		return -1;
 	}
 	return 0;
 }
 
-static struct ast_filestream *wav_open(int fd)
+static struct ast_filestream *wav_open(FILE *f)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -349,7 +350,7 @@ static struct ast_filestream *wav_open(int fd)
 	struct ast_filestream *tmp;
 	if ((tmp = malloc(sizeof(struct ast_filestream)))) {
 		memset(tmp, 0, sizeof(struct ast_filestream));
-		if (check_header(fd)) {
+		if (check_header(f)) {
 			free(tmp);
 			return NULL;
 		}
@@ -358,7 +359,7 @@ static struct ast_filestream *wav_open(int fd)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		tmp->fr.data = tmp->gsm;
 		tmp->fr.frametype = AST_FRAME_VOICE;
 		tmp->fr.subclass = AST_FORMAT_GSM;
@@ -373,7 +374,7 @@ static struct ast_filestream *wav_open(int fd)
 	return tmp;
 }
 
-static struct ast_filestream *wav_rewrite(int fd, const char *comment)
+static struct ast_filestream *wav_rewrite(FILE *f, const char *comment)
 {
 	/* We don't have any header to read or anything really, but
 	   if we did, it would go here.  We also might want to check
@@ -381,7 +382,7 @@ static struct ast_filestream *wav_rewrite(int fd, const char *comment)
 	struct ast_filestream *tmp;
 	if ((tmp = malloc(sizeof(struct ast_filestream)))) {
 		memset(tmp, 0, sizeof(struct ast_filestream));
-		if (write_header(fd)) {
+		if (write_header(f)) {
 			free(tmp);
 			return NULL;
 		}
@@ -390,7 +391,7 @@ static struct ast_filestream *wav_rewrite(int fd, const char *comment)
 			free(tmp);
 			return NULL;
 		}
-		tmp->fd = fd;
+		tmp->f = f;
 		glistcnt++;
 		ast_mutex_unlock(&wav_lock);
 		ast_update_use_count();
@@ -410,9 +411,10 @@ static void wav_close(struct ast_filestream *s)
 	ast_mutex_unlock(&wav_lock);
 	ast_update_use_count();
 	/* Pad to even length */
-	if (lseek(s->fd, 0, SEEK_END) & 0x1)
-		write(s->fd, &zero, 1);
-	close(s->fd);
+	fseek(s->f, 0, SEEK_END);
+	if (ftell(s->f) & 0x1)
+		fwrite(&zero, 1, 1, s->f);
+	fclose(s->f);
 	free(s);
 	s = NULL;
 }
@@ -433,7 +435,7 @@ static struct ast_frame *wav_read(struct ast_filestream *s, int *whennext)
 		/* Just return a frame based on the second GSM frame */
 		s->fr.data = s->gsm + 33;
 	} else {
-		if ((res = read(s->fd, msdata, 65)) != 65) {
+		if ((res = fread(msdata, 1, 65, s->f)) != 65) {
 			if (res && (res != 1))
 				ast_log(LOG_WARNING, "Short read (%d) (%s)!\n", res, strerror(errno));
 			return NULL;
@@ -466,21 +468,21 @@ static int wav_write(struct ast_filestream *fs, struct ast_frame *f)
 	while(len < f->datalen) {
 		if (alreadyms) {
 			fs->secondhalf = 0;
-			if ((res = write(fs->fd, f->data + len, 65)) != 65) {
+			if ((res = fwrite(f->data + len, 1, 65, fs->f)) != 65) {
 				ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
 				return -1;
 			}
-			update_header(fs->fd);
+			update_header(fs->f);
 			len += 65;
 		} else {
 			if (fs->secondhalf) {
 				memcpy(fs->gsm + 33, f->data + len, 33);
 				conv66(fs->gsm, msdata);
-				if ((res = write(fs->fd, msdata, 65)) != 65) {
+				if ((res = fwrite(msdata, 1, 65, fs->f)) != 65) {
 					ast_log(LOG_WARNING, "Bad write (%d/65): %s\n", res, strerror(errno));
 					return -1;
 				}
-				update_header(fs->fd);
+				update_header(fs->f);
 			} else {
 				/* Copy the data and do nothing */
 				memcpy(fs->gsm, f->data + len, 33);
@@ -496,8 +498,9 @@ static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
 {
 	off_t offset=0,distance,cur,min,max;
 	min = 60;
-	cur = lseek(fs->fd, 0, SEEK_CUR);
-	max = lseek(fs->fd, 0, SEEK_END);
+	cur = ftell(fs->f);
+	fseek(fs->f, 0, SEEK_END);
+	max = ftell(fs->f);
 	/* I'm getting sloppy here, I'm only going to go to even splits of the 2
 	 * frames, if you want tighter cuts use format_gsm, format_pcm, or format_wav */
 	distance = (sample_offset/320) * 65;
@@ -513,26 +516,26 @@ static int wav_seek(struct ast_filestream *fs, long sample_offset, int whence)
 		offset = (offset > max)?max:offset;
 	} else if (offset > max) {
 		int i;
-		lseek(fs->fd, 0, SEEK_END);
+		fseek(fs->f, 0, SEEK_END);
 		for (i=0; i< (offset - max) / 65; i++) {
-			write(fs->fd, msgsm_silence, 65);
+			fwrite(msgsm_silence, 1, 65, fs->f);
 		}
 	}
 	fs->secondhalf = 0;
-	return lseek(fs->fd, offset, SEEK_SET);
+	return fseek(fs->f, offset, SEEK_SET);
 }
 
 static int wav_trunc(struct ast_filestream *fs)
 {
-	if(ftruncate(fs->fd, lseek(fs->fd, 0, SEEK_CUR)))
+	if (ftruncate(fileno(fs->f), ftell(fs->f)))
 		return -1;
-	return update_header(fs->fd);
+	return update_header(fs->f);
 }
 
 static long wav_tell(struct ast_filestream *fs)
 {
 	off_t offset;
-	offset = lseek(fs->fd, 0, SEEK_CUR);
+	offset = ftell(fs->f);
 	/* since this will most likely be used later in play or record, lets stick
 	 * to that level of resolution, just even frames boundaries */
 	return (offset - 52)/65*320;
diff --git a/include/asterisk/channel.h b/include/asterisk/channel.h
index fa1e3395ba700289a8066efe2c74423b7caf4e07..d0f3b98ea46e3f685b1a9f5bc4027ba5b4ae4bb2 100755
--- a/include/asterisk/channel.h
+++ b/include/asterisk/channel.h
@@ -766,6 +766,9 @@ struct ast_channel *ast_get_channel_by_name_locked(const char *chan);
 /*! Get channel by name prefix (locks channel) */
 struct ast_channel *ast_get_channel_by_name_prefix_locked(const char *name, const int namelen);
 
+/*! Get channel by name prefix (locks channel) */
+struct ast_channel *ast_walk_channel_by_name_prefix_locked(struct ast_channel *chan, const char *name, const int namelen);
+
 /*--- ast_get_channel_by_exten_locked: Get channel by exten (and optionally context) and lock it */
 struct ast_channel *ast_get_channel_by_exten_locked(const char *exten, const char *context);
 
diff --git a/include/asterisk/file.h b/include/asterisk/file.h
index faf614b331eae1e08af049a0aa2f28127be17eac..7dc2f9ec5b40fe0c1154d31085441c21ced70b64 100755
--- a/include/asterisk/file.h
+++ b/include/asterisk/file.h
@@ -49,8 +49,8 @@ struct ast_filestream;
  * returns 0 on success, -1 on failure
  */
 int ast_format_register(const char *name, const char *exts, int format,
-						struct ast_filestream * (*open)(int fd),
-						struct ast_filestream * (*rewrite)(int fd, const char *comment),
+						struct ast_filestream * (*open)(FILE *f),
+						struct ast_filestream * (*rewrite)(FILE *f, const char *comment),
 						int (*write)(struct ast_filestream *, struct ast_frame *),
 						int (*seek)(struct ast_filestream *, long offset, int whence),
 						int (*trunc)(struct ast_filestream *),