Using SDI_stdarg.h for OS4 and OS3 with VBCC

1 post / 0 new
jabirulo
jabirulo's picture
Offline
Last seen: 17 hours 28 min ago
Joined: 2013-05-30 00:53
Using SDI_stdarg.h for OS4 and OS3 with VBCC

HI I (re)use this piece of code for OS4 and OS3 and with VBCC, OS3 build works fine, but OS4 build I get always a crash :-(
What am I doing wrong? Do I need to use/add "VA_ARG(ap, )" to VSNPrintf(), or change it to SNPrintf() ¿:-/

Alresdy read "https://os4coding.net/forum/vsprintf" but still don't get it.

  1. void VARARGS68K log_printf(struct ArchiverData *ad, int type, const char *fmt, ...) {
  2. static char log_buf[16], buffer[2048];
  3. struct DateStamp ds;
  4. int hour, minute, second, offset;
  5. VA_LIST ap;
  6. struct ArchiverGUI *ag = &ad->ad_GUIData;
  7.  
  8. assert(type >= LOG_INFO && type <= LOG_ERROR);
  9.  
  10. DateStamp(&ds);
  11.  
  12. ObtainSemaphore(&ad->ad_LogSem);
  13.  
  14. hour = ds.ds_Minute / 60;
  15. minute = ds.ds_Minute % 60;
  16. second = ds.ds_Tick / TICKS_PER_SECOND;
  17.  
  18. offset = SNPrintf(log_buf, sizeof(log_buf), "%lc: [%02ld:%02ld:%02ld] ",
  19. log_type[type], hour, minute, second);
  20. Write(ad->ad_LogFile, log_buf, strlen(log_buf));
  21.  
  22. VA_START(ap, fmt);
  23. VSNPrintf(buffer, sizeof(buffer), fmt, ap);
  24. //VSNPrintf(buffer + offset, sizeof(buffer) - offset, fmt,ap);
  25. VA_END(ap);
  26.  
  27. #ifdef _USE_MUI_
  28. if(ag->ag_Status) {
  29. SetAttrs(ag->ag_Status, MUIA_Text_Contents,buffer, TAG_END);
  30. }
  31. #endif
  32.  
  33. Strlcat(buffer, "\n", sizeof(buffer));
  34. Write(ad->ad_LogFile, buffer, strlen(buffer));
  35.  
  36. ReleaseSemaphore(&ad->ad_LogSem);
  37. }

TiA