Index: trunk/psLib/src/sys/psTrace.c
===================================================================
--- trunk/psLib/src/sys/psTrace.c	(revision 4972)
+++ trunk/psLib/src/sys/psTrace.c	(revision 5071)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.58 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-08 00:27:50 $
+ *  @version $Revision: 1.59 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-20 00:31:22 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -54,5 +54,5 @@
 
 static p_psComponent* cRoot = NULL; // The root of the trace component
-static FILE *traceFP = NULL;        // File destination for messages.
+// static FILE *traceFP = NULL;        // File destination for messages.
 static psBool traceTime = false;     // Flag to include time info
 static psBool traceHost = false;     // Flag to include host info
@@ -60,5 +60,5 @@
 static psBool traceName = false;     // Flag to include name info
 static psBool traceMsg = true;      // Flag to include message info
-//static int traceFD = 0;
+static int traceFD = STDOUT_FILENO; // default value
 
 static void componentFree(p_psComponent* comp);
@@ -259,8 +259,4 @@
     if (cRoot == NULL) {
         initTrace();
-    }
-
-    if (traceFP == NULL) {
-        traceFP = stdout;
     }
 
@@ -436,9 +432,10 @@
                                psS32 defLevel)
 {
+    char line[1024];
     psS32 i = 0;
 
-    if (traceFP == NULL) {
-        traceFP = stdout;
-    }
+    // XXX EAM : probably should just return if traceFD < 1
+    if (traceFD < 1)
+        return;
 
     if (comp->name[0] == '\0') {
@@ -446,7 +443,11 @@
     } else {
         if (comp->level == PS_DEFAULT_TRACE_LEVEL) {
-            fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
+            // fprintf(traceFP,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
+            sprintf(line,"%*s%-*s %d\n", depth, "", 20 - depth, comp->name, defLevel);
+            write (traceFD, line, strlen(line));
         } else {
-            fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
+            // fprintf(traceFP, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
+            sprintf(line, "%*s%-*s %d\n", depth, "", 20 - depth, comp->name, comp->level);
+            write (traceFD, line, strlen(line));
         }
     }
@@ -486,5 +487,5 @@
               va_list ap)
 {
-    char *fmt = NULL;
+    // char *fmt = NULL;
     //    va_list ap;
     static psS32 first = 1;       // Flag for calling gethostname()
@@ -498,7 +499,7 @@
     struct tm *utc = gmtime(&clock);    // The current gm time.
 
-    if (traceFP == NULL) {
-        traceFP = stdout;
-    }
+    // XXX EAM : fd < 1 does not print messages
+    if (traceFD < 1)
+        return;
 
     if (NULL == comp) {
@@ -590,18 +591,26 @@
 
 
-
-        fputs(head, traceFP);
+        // fputs(head, traceFP);
+        write (traceFD, head, strlen(head));
+
         if (traceMsg) {
+            char line[1024];
+
             // The following functions get the variable list of parameters with
             // which this function was called, and print them to the standard
             // output.
-            fmt = va_arg(ap, char *);
+            // fmt = va_arg(ap, char *);
 
             // We indent each message one space for each level of the message.
             for (i = 0; i < level; i++) {
                 //            fprintf(traceFP, " ");
-                fprintf(traceFP, "%s", format);
+                // fprintf(traceFP, "%s", format);
+                // sprintf(line, "%s", format);
+                write (traceFD, " ", 1);
             }
-            vfprintf(traceFP, fmt, ap);
+            // vfprintf(traceFP, fmt, ap);
+            vsprintf(line, format, ap);
+            write (traceFD, line, strlen(line));
+
             //        vfprintf(traceFP, format, ap);
             //        va_end(ap);
@@ -609,5 +618,5 @@
                         char* msgPtr;
                         vsnprintf(msg,1024, format, ap);  // create message
-             
+
                         // detect multiple lines in message and indent each line by 4 spaces.
                         char* line = strtok_r(msg,"\n",&msgPtr);
@@ -618,5 +627,6 @@
             */
         } else {
-            fputc('\n', traceFP);
+            // fputc('\n', traceFP);
+            write(traceFD, "\n", 1);
         }
 
@@ -647,7 +657,9 @@
     va_list ap;
     va_start(ap, format);
+    format = va_arg(ap, char *);
     psTraceV(comp, level, format, ap);
     va_end(ap);
-    fflush(traceFP);
+    // fflush(traceFP);
+    // XXX EAM : what is fd-appropriate equivalent?
 }
 
@@ -676,15 +688,15 @@
         traceFP = fp;
     */
-    if (fd == -1) {
+    if (fd < 1) {
+        traceFD = 0;
         return;
     }
     if (fd == 1) {
-        traceFP = stdout;
+        traceFD = STDOUT_FILENO;
     } else if (fd == 2) {
-        traceFP = stderr;
-    } else if (fd == 0) {
-        traceFP = stdin;
+        traceFD = STDERR_FILENO;
     } else if (fd > 2) {
-        traceFP = fdopen(fd, "w");
+        close (traceFD);
+        traceFD = fd;
     }
 }
@@ -692,7 +704,5 @@
 int psTraceGetDestination()
 {
-    int fd;
-    fd = fileno(traceFP);
-    return fd;
+    return traceFD;
 }
 
