Ignore:
Timestamp:
Feb 12, 2015, 12:35:20 PM (9 years ago)
Author:
knut
Message:

Added function getLastErrorMessage() (service_internal.c). Fixed problems caused by differing return types for GetLastError?() (unsigned int) and dlerror() (char*). Added DEBUG-conditional macros for diagnostic output in zoo_service_loader.c.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-project/zoo-kernel/service_internal.c

    r577 r578  
    3737#endif
    3838
     39#ifndef WIN32
     40#include <dlfcn.h>
     41#endif
     42
     43#define ERROR_MSG_MAX_LENGTH 1024
     44
    3945int isValidLang(maps* conf,const char *str){
    4046  map *tmpMap=getMapFromMaps(conf,"main","lang");
     
    152158
    153159#ifdef DEBUG
    154       fprintf(stderr,"Semaphore failed to create ! %s\n",GetLastError());
     160      fprintf(stderr,"Semaphore failed to create: %s\n", getLastErrorMessage());
    155161#endif
    156162      return NULL;
     
    166172  semid sem_id=getShmLockId(conf,1);
    167173  if (CloseHandle(sem_id) == 0) {
    168     fprintf(stderr,"Unable to remove semaphore %s",GetLastError());
     174    fprintf(stderr,"Unable to remove semaphore: %s\n", getLastErrorMessage());
    169175    return -1;
    170176  }
     
    232238  if (hMapObjectG == NULL){
    233239#ifdef DEBUG
    234     fprintf(stderr,"Unable to create shared memory segment %d !! \n",GetLastError());
     240    fprintf(stderr,"Unable to create shared memory segment: %s\n", getLastErrorMessage());
    235241#endif
    236242    return -2;
     
    292298#ifdef DEBUG
    293299    fprintf(stderr,"ERROR on line %d\n",__LINE__);
    294     fprintf(stderr,"READING STRING S %s\n",GetLastError());
     300    fprintf(stderr,"READING STRING S %s\n", getLastErrorMessage());
    295301#endif
    296302    fIgnore = UnmapViewOfFile(lpvMem);
     
    309315#ifdef DEBUG
    310316    fprintf(stderr,"READING STRING S %d\n",__LINE__);
    311     fprintf(stderr,"READING STRING S %s\n",GetLastError());
     317    fprintf(stderr,"READING STRING S %s\n", getLastErrorMessage());
    312318#endif
    313319    return "-1";
     
    37333739  }
    37343740}
     3741
     3742/*
     3743 * The character string returned from getLastErrorMessage resides
     3744 * in a static buffer. The application should not write to this
     3745 * buffer or attempt to free() it.
     3746 */
     3747char* getLastErrorMessage() {                                                                                                                                                   
     3748#ifdef WIN32   
     3749        LPVOID lpMsgBuf;
     3750        DWORD errCode = GetLastError();
     3751        static char msg[ERROR_MSG_MAX_LENGTH];
     3752        size_t i;
     3753
     3754        DWORD length = FormatMessage(
     3755                                         FORMAT_MESSAGE_ALLOCATE_BUFFER |
     3756                                         FORMAT_MESSAGE_FROM_SYSTEM |
     3757                                         FORMAT_MESSAGE_IGNORE_INSERTS,
     3758                                         NULL,
     3759                                         errCode,
     3760                                         MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
     3761                                         (LPTSTR) &lpMsgBuf,
     3762                                         0, NULL );     
     3763       
     3764        #ifdef UNICODE         
     3765                wcstombs_s( &i, msg, ERROR_MSG_MAX_LENGTH,
     3766                                        (wchar_t*) lpMsgBuf, _TRUNCATE );
     3767        #else
     3768                strcpy_s( msg, ERROR_MSG_MAX_LENGTH,
     3769                      (char *) lpMsgBuf );             
     3770        #endif 
     3771        LocalFree(lpMsgBuf);
     3772       
     3773        return msg;
     3774#else
     3775        return dlerror();
     3776#endif
     3777}
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png