src/windows/back/linker_md.c

Print this page
rev 6641 : [mq]: PrivateTransportTest


  27  * Maintains a list of currently loaded DLLs (Dynamic Link Libraries)
  28  * and their associated handles. Library names are case-insensitive.
  29  */
  30 
  31 #include <windows.h>
  32 #include <stdio.h>
  33 #include <string.h>
  34 #include <errno.h>
  35 #include <io.h>
  36 
  37 #include "sys.h"
  38 
  39 #include "path_md.h"
  40 
  41 static void dll_build_name(char* buffer, size_t buflen,
  42                            const char* pname, const char* fname) {
  43     // Based on os_windows.cpp
  44 
  45     char *path_sep = PATH_SEPARATOR;
  46     char *pathname = (char *)pname;

  47     while (strlen(pathname) > 0) {
  48         char *p = strchr(pathname, *path_sep);
  49         if (p == NULL) {
  50             p = pathname + strlen(pathname);
  51         }
  52         /* check for NULL path */
  53         if (p == pathname) {
  54             continue;
  55         }
  56         if (*(p-1) == ':' || *(p-1) == '\\') {
  57             (void)_snprintf(buffer, buflen, "%.*s%s.dll", (p - pathname),
  58                             pathname, fname);
  59         } else {
  60             (void)_snprintf(buffer, buflen, "%.*s\\%s.dll", (p - pathname),
  61                             pathname, fname);
  62         }
  63         if (_access(buffer, 0) == 0) {
  64             break;
  65         }



  66         pathname = p + 1;

  67         *buffer = '\0';
  68     }
  69 }
  70 
  71 /*
  72  * From system_md.c v1.54
  73  */
  74 int
  75 dbgsysGetLastErrorString(char *buf, int len)
  76 {
  77     long errval;
  78 
  79     if ((errval = GetLastError()) != 0) {
  80         /* DOS error */
  81         int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
  82                               NULL, errval,
  83                               0, buf, len, NULL);
  84         if (n > 3) {
  85             /* Drop final '.', CR, LF */
  86             if (buf[n - 1] == '\n') n--;




  27  * Maintains a list of currently loaded DLLs (Dynamic Link Libraries)
  28  * and their associated handles. Library names are case-insensitive.
  29  */
  30 
  31 #include <windows.h>
  32 #include <stdio.h>
  33 #include <string.h>
  34 #include <errno.h>
  35 #include <io.h>
  36 
  37 #include "sys.h"
  38 
  39 #include "path_md.h"
  40 
  41 static void dll_build_name(char* buffer, size_t buflen,
  42                            const char* pname, const char* fname) {
  43     // Based on os_windows.cpp
  44 
  45     char *path_sep = PATH_SEPARATOR;
  46     char *pathname = (char *)pname;
  47     *buffer = '\0';
  48     while (strlen(pathname) > 0) {
  49         char *p = strchr(pathname, *path_sep);
  50         if (p == NULL) {
  51             p = pathname + strlen(pathname);
  52         }
  53         /* check for NULL path */
  54         if (p == pathname) {
  55             continue;
  56         }
  57         if (*(p-1) == ':' || *(p-1) == '\\') {
  58             (void)_snprintf(buffer, buflen, "%.*s%s.dll", (int)(p - pathname),
  59                             pathname, fname);
  60         } else {
  61             (void)_snprintf(buffer, buflen, "%.*s\\%s.dll", (int)(p - pathname),
  62                             pathname, fname);
  63         }
  64         if (_access(buffer, 0) == 0) {
  65             break;
  66         }
  67         if (*p == '\0') {
  68             pathname = p;
  69         } else {
  70             pathname = p + 1;
  71         }
  72         *buffer = '\0';
  73     }
  74 }
  75 
  76 /*
  77  * From system_md.c v1.54
  78  */
  79 int
  80 dbgsysGetLastErrorString(char *buf, int len)
  81 {
  82     long errval;
  83 
  84     if ((errval = GetLastError()) != 0) {
  85         /* DOS error */
  86         int n = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS,
  87                               NULL, errval,
  88                               0, buf, len, NULL);
  89         if (n > 3) {
  90             /* Drop final '.', CR, LF */
  91             if (buf[n - 1] == '\n') n--;