]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Changes in shared code that don't affect open-vm-tools functionality.
authorVMware, Inc <>
Tue, 24 Aug 2010 18:04:43 +0000 (11:04 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 24 Aug 2010 18:04:43 +0000 (11:04 -0700)
Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/file/fileIOPosix.c
open-vm-tools/lib/include/fileIO.h
open-vm-tools/lib/include/log.h

index b1ac820f9a433c4085f007ed0da17ac2c8711791..6f4a0591dc912f05c38f4f4ee635af36f882dc81 100644 (file)
@@ -2173,6 +2173,51 @@ FileIO_PrivilegedPosixOpen(ConstUnicode pathName,  // IN:
 }
 
 
+/*
+ *-----------------------------------------------------------------------------
+ *
+ * FileIO_FDToStream
+ *
+ *      Return a FILE * stream equivalent to the given (POSIX) file descriptor.
+ *      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_FDToStream(int fd,            // IN:
+                  const char *mode,  // IN:
+                  Bool textMode)     // IN: unused
+{
+   int dupFD;
+   FILE *stream;
+
+   dupFD = dup(fd);
+
+   if (dupFD == -1) {
+      return NULL;
+   }
+
+   stream = fdopen(dupFD, mode);
+
+   if (stream == NULL) {
+      close(dupFD);
+   }
+
+   return stream;
+}
+
+
 /*
  *-----------------------------------------------------------------------------
  *
@@ -2181,14 +2226,11 @@ FileIO_PrivilegedPosixOpen(ConstUnicode pathName,  // IN:
  *      Return a FILE * stream equivalent to the given FileIODescriptor.
  *      This is the logical equivalent of Posix dup() then fdopen().
  *
- *      Since the passed descriptor and returned FILE * represent the same
- *      underlying file, and their cursor is shared, you should avoid
- *      interleaving uses to both.
+ *      Caller should fclose the returned descriptor when finished.
  *
  * Results:
- *      A FILE * representing the same underlying file as the passed descriptor
- *      NULL if there was an error.
- *      Caller should fclose the returned descriptor when finished.
+ *      !NULL  A FILE * associated with the file associated with the fd
+ *      NULL   Failure
  *
  * Side effects:
  *      New fd allocated.
@@ -2200,21 +2242,14 @@ FILE *
 FileIO_DescriptorToStream(FileIODescriptor *fdesc,  // IN:
                           Bool textMode)            // IN: unused
 {
-   int dupFd;
-   const char *mode;
    int tmpFlags;
-   FILE *stream;
+   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);
    tmpFlags = fdesc->flags & (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE);
 
-   dupFd = dup(fdesc->posix);
-   if (dupFd == -1) {
-      return NULL;
-   }
-
    if (tmpFlags == (FILEIO_OPEN_ACCESS_READ | FILEIO_OPEN_ACCESS_WRITE)) {
       mode = "r+";
    } else if (tmpFlags == FILEIO_OPEN_ACCESS_WRITE) {
@@ -2223,18 +2258,11 @@ FileIO_DescriptorToStream(FileIODescriptor *fdesc,  // IN:
       mode = "r";
    }
 
-   stream = fdopen(dupFd, mode);
-
-   if (stream == NULL) {
-      close(dupFd);
-   }
-
-   return stream;
+   return FileIO_FDToStream(fdesc->posix, mode, textMode);
 }
 
 
 #if defined(__APPLE__)
-
 /*
  *-----------------------------------------------------------------------------
  *
index 51003c5f64133bec6db4d42f9a3335c273b4128c..bb3ab1129c5506f4882db6458706cc7e1bf988ab 100644 (file)
@@ -371,6 +371,10 @@ int FileIO_PrivilegedPosixOpen(ConstUnicode pathName,
                                int flags);
 #endif
 
+FILE *FileIO_FDToStream(int fd,
+                        const char *mode,
+                        Bool textMode);
+
 FILE *FileIO_DescriptorToStream(FileIODescriptor *fd,
                                 Bool textMode);
 
index 23591a23a6776aa2118994c024dff077085dfb2a..c83c70b36781f7a3b288995a7c36c6e20ae67cea 100644 (file)
@@ -31,7 +31,7 @@ typedef void (LogBasicFunc)(const char *fmt, va_list args);
 
 
 typedef enum {
-   LOG_NO_SYSTEM_LOGGER,
+   LOG_SYSTEM_LOGGER_NONE,
    LOG_SYSTEM_LOGGER_ADJUNCT,
    LOG_SYSTEM_LOGGER_ONLY
 } SysLogger;
@@ -100,11 +100,11 @@ uint32 Log_MaxLineLength(void);
 void Log_RegisterBasicFunctions(LogBasicFunc *log,
                                 LogBasicFunc *warning);
 
-Bool Log_SwitchFile(const char *fileName,
-                    const char *config,
-                    Bool copy,
-                    uint32 systemLoggerUse,
-                    char *systemLoggerID);
+Bool Log_SetOutput(const char *fileName,
+                   const char *config,
+                   Bool copy,
+                   uint32 systemLoggerUse,
+                   char *systemLoggerID);
 
 size_t Log_MakeTimeString(Bool millisec,
                           char *buf,