bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/25713] Linker(ld.exe) runs in Windows unable to find file if pat


From: fredrick.eisele at gmail dot com
Subject: [Bug ld/25713] Linker(ld.exe) runs in Windows unable to find file if path length is more than 260 characters.
Date: Wed, 16 Feb 2022 19:12:01 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=25713

--- Comment #25 from Fred Eisele <fredrick.eisele at gmail dot com> ---
Use of those functions would give us something like...

  size_t filelen;

  /* PR 25713: Handle extra long path names possibly containing '..' and '.'.
*/
  wchar_t **lpFilePart = {NULL};
  const char ccs[] = "ccs=UNICODE";
  const int partPathLen = strlen(filename);
  const char *partPathOrig = calloc(partPathLen, sizeof(char));
  /*
   * Convert any UNIX style path separators into the DOS form.
   */
  for (int ix=0; ix < partPathLen) switch (filename[ix]) {
      case '/': partPathOrig[ix] = '\\'; break;
      default: partPathOrig[ix] = filename[ix]
    }
  /*
   * Converting from the partial path from ascii to unicode.
   * Calling with lpWideCharStr set to null returns the length.
   * Calling with cbMultiByte set to -1 includes the terminating null.
   */
  int partPathWSize = MultiByteToWideChar(CP_UTF8, 0, partPathOrig, -1, NULL,
0);
  wchar_t *partPath = calloc(partPathWSize, sizeof(wchar_t));
  MultiByteToWideChar(CP_UTF8, 0, partPathOrig, -1, partPath, partPathWSize);
  /*
   * Getting the full path from the provided partial path.
   * Calling twice: 1) get the length; 2) resolve the path.
   */
  long fullPathWSize = GetFullPathNameW(partPath, 0, NULL, lpFilePart);
  wchar_t *fullPath = calloc(fullPathWSize, sizeof(wchar_t));
  long copiedPathLen = GetFullPathNameW(partPath, fullPathWSize, fullPath,
lpFilePart);
  free(partPath);

  char* remode = calloc(strlen(modes) + sizeof(ccs) + 1, sizeof(char));
  strcpy(remode, modes);
  strcat(remode, ccs);
       file = fopen (fullPath, remode);
fprintf(stderr, "k26: %d %s\n", errno, strerror(errno));
      file = close_on_exec (file);
fprintf(stderr, "k27: %d %s\n", errno, strerror(errno));

      free (fullPath);
      return file;

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]