IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23516


Ignore:
Timestamp:
Mar 25, 2009, 11:15:28 AM (17 years ago)
Author:
eugene
Message:

add gprint_syserror function, gprintv

Location:
branches/eam_branches/eam_branch_20090322/Ohana/src/opihi
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/include/shell.h

    r21153 r23516  
    166166int           gprint                    PROTO((gpDest dest, char *format, ...));
    167167int           gwrite                    PROTO((char *buffer, int size, int N, gpDest dest));
     168int           gprint_syserror           PROTO((gpDest dest, int myError, char *format, ...));
     169int           gprintv                   PROTO((gpDest dest, char *format, va_list argp));
    168170
    169171/* socket functions */
  • branches/eam_branches/eam_branch_20090322/Ohana/src/opihi/lib.shell/gprint.c

    r22423 r23516  
    287287
    288288  int status;
    289   gpStream *stream;
    290289  va_list argp; 
    291290
     291  va_start (argp, format);
     292  status = gprintv (dest, format, argp);
     293  va_end (argp);
     294  return (status);
     295}
     296
     297int gprintv (gpDest dest, char *format, va_list argp) {
     298
     299  int status;
     300  gpStream *stream;
     301
    292302  // this thread only writes to its own stream
    293303  stream = gprintGetStream (dest);
    294 
    295   va_start (argp, format);
    296304
    297305  if (stream[0].mode == GP_FILE) {
     
    303311    vPrintIOBuffer (stream[0].buffer, format, argp);
    304312  }
    305   va_end (argp);
    306313  return (TRUE);
    307314}
     
    332339}
    333340
    334 /* I'm going to need to have different output targets for different threads
    335    we can do this with these functions:
    336 
    337    pthread_t pthread_self(void);
    338    int pthread_equal(pthread_t thread1, pthread_t thread2);
    339    // returns TRUE if equal, FALSE if not
    340    
    341 */
    342 
     341# define MAX_ERROR_LENGTH 256           // Maximum length string for error messages
     342
     343// print an error (based on errno values) to gprint destination
     344int gprint_syserror (gpDest dest, int myError, char *format, ...) {
     345
     346  char errorBuf[MAX_ERROR_LENGTH];
     347  char *errorMsg;
     348  va_list argp; 
     349
     350  // there are two strerror_r implementations; choose the right one:
     351#if ((_POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600) && ! _GNU_SOURCE)
     352  errorMsg = strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
     353#else
     354  strerror_r (myError, errorBuf, MAX_ERROR_LENGTH);
     355  errorMsg = errorBuf;
     356#endif
     357
     358  va_start (argp, format);
     359  gprintv (dest, format, argp);
     360  va_end (argp);
     361
     362  gprintv (dest, "%s\n", errorMsg);
     363  return TRUE;
     364}
Note: See TracChangeset for help on using the changeset viewer.