Index: /branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/include/shell.h
===================================================================
--- /branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/include/shell.h	(revision 23515)
+++ /branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/include/shell.h	(revision 23516)
@@ -166,4 +166,6 @@
 int           gprint          		PROTO((gpDest dest, char *format, ...));
 int           gwrite          		PROTO((char *buffer, int size, int N, gpDest dest));
+int           gprint_syserror           PROTO((gpDest dest, int myError, char *format, ...));
+int           gprintv                   PROTO((gpDest dest, char *format, va_list argp));
 
 /* socket functions */
Index: /branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/lib.shell/gprint.c
===================================================================
--- /branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/lib.shell/gprint.c	(revision 23515)
+++ /branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/lib.shell/gprint.c	(revision 23516)
@@ -287,11 +287,19 @@
 
   int status;
-  gpStream *stream;
   va_list argp;  
 
+  va_start (argp, format);
+  status = gprintv (dest, format, argp);
+  va_end (argp);
+  return (status);
+}
+
+int gprintv (gpDest dest, char *format, va_list argp) {
+
+  int status;
+  gpStream *stream;
+
   // this thread only writes to its own stream
   stream = gprintGetStream (dest);
-
-  va_start (argp, format);
 
   if (stream[0].mode == GP_FILE) {
@@ -303,5 +311,4 @@
     vPrintIOBuffer (stream[0].buffer, format, argp);
   }
-  va_end (argp);
   return (TRUE);
 }
@@ -332,11 +339,26 @@
 }
 
-/* I'm going to need to have different output targets for different threads
-   we can do this with these functions:
-
-   pthread_t pthread_self(void);
-   int pthread_equal(pthread_t thread1, pthread_t thread2);
-   // returns TRUE if equal, FALSE if not
-   
-*/
-
+# define MAX_ERROR_LENGTH 256           // Maximum length string for error messages
+
+// print an error (based on errno values) to gprint destination
+int gprint_syserror (gpDest dest, int myError, char *format, ...) {
+
+  char errorBuf[MAX_ERROR_LENGTH];
+  char *errorMsg;
+  va_list argp;  
+
+  // there are two strerror_r implementations; choose the right one:
+#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
+  errorMsg = strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
+#else
+  strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
+  errorMsg = errorBuf;
+#endif
+
+  va_start (argp, format);
+  gprintv (dest, format, argp);
+  va_end (argp);
+
+  gprintv (dest, "%s\n", errorMsg);
+  return TRUE;
+}
