/*
*-----------------------------------------------------------------------------
*
- * FileIO_FDToStream
+ * FileIO_DescriptorToStream
*
- * Return a FILE * stream equivalent to the given (POSIX) file descriptor.
+ * Return a FILE * stream equivalent to the given FileIODescriptor.
* This is the logical equivalent of Posix dup() then fdopen().
*
* Caller should fclose the returned descriptor when finished.
*-----------------------------------------------------------------------------
*/
-
FILE *
-FileIO_FDToStream(int fd, // IN:
- const char *mode, // IN:
- Bool textMode) // IN: unused
+FileIO_DescriptorToStream(FileIODescriptor *fdesc, // IN:
+ Bool textMode) // IN: unused
{
int dupFD;
+ const char *mode;
+ int tmpFlags;
FILE *stream;
- dupFD = dup(fd);
-
+ dupFD = dup(fdesc->posix);
if (dupFD == -1) {
return NULL;
}
- stream = fdopen(dupFD, mode);
-
- if (stream == NULL) {
- close(dupFD);
- }
-
- return stream;
-}
-
-
-/*
- *-----------------------------------------------------------------------------
- *
- * FileIO_DescriptorToStream
- *
- * Return a FILE * stream equivalent to the given FileIODescriptor.
- * This is the logical equivalent of Posix dup() then fdopen().
- *
- * Caller should fclose the returned descriptor when finished.
- *
- * Results:
- * !NULL A FILE * associated with the file associated with the fd
- * NULL Failure
- *
- * Side effects:
- * New fd allocated.
- *
- *-----------------------------------------------------------------------------
- */
-
-FILE *
-FileIO_DescriptorToStream(FileIODescriptor *fdesc, // IN:
- Bool textMode) // IN: unused
-{
- int tmpFlags;
- const char *mode;
-
/* The file you pass us should be valid and opened for *something* */
ASSERT(FileIO_IsValid(fdesc));
ASSERT((fdesc->flags & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) != 0);
mode = "r";
}
- return FileIO_FDToStream(fdesc->posix, mode, textMode);
+ stream = fdopen(dupFD, mode);
+
+ if (stream == NULL) {
+ close(dupFD);
+ }
+
+ return stream;
}