0001-quickjs-libc-add-realpath-for-Windows.patch 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. --- quickjs-libc.c 2021-06-11 22:42:15.729357600 +0800
  2. +++ patched.c 2021-06-11 22:44:01.426073100 +0800
  3. @@ -511,6 +511,18 @@
  4. }
  5. #endif /* !_WIN32 */
  6. +#if defined(_WIN32)
  7. +static char *realpath(const char *path, char *buf)
  8. +{
  9. + if (!_fullpath(buf, path, PATH_MAX)) {
  10. + errno = ENOENT;
  11. + return NULL;
  12. + } else {
  13. + return buf;
  14. + }
  15. +}
  16. +#endif
  17. +
  18. int js_module_set_import_meta(JSContext *ctx, JSValueConst func_val,
  19. JS_BOOL use_realpath, JS_BOOL is_main)
  20. {
  21. @@ -530,7 +542,7 @@
  22. return -1;
  23. if (!strchr(module_name, ':')) {
  24. strcpy(buf, "file://");
  25. -#if !defined(_WIN32)
  26. +//#if !defined(_WIN32)
  27. /* realpath() cannot be used with modules compiled with qjsc
  28. because the corresponding module source code is not
  29. necessarily present */
  30. @@ -542,7 +554,7 @@
  31. return -1;
  32. }
  33. } else
  34. -#endif
  35. +//#endif
  36. {
  37. pstrcat(buf, sizeof(buf), module_name);
  38. }
  39. @@ -2638,18 +2650,6 @@
  40. return JS_NewInt32(ctx, ret);
  41. }
  42. -#if defined(_WIN32)
  43. -static char *realpath(const char *path, char *buf)
  44. -{
  45. - if (!_fullpath(buf, path, PATH_MAX)) {
  46. - errno = ENOENT;
  47. - return NULL;
  48. - } else {
  49. - return buf;
  50. - }
  51. -}
  52. -#endif
  53. -
  54. /* return [path, errorcode] */
  55. static JSValue js_os_realpath(JSContext *ctx, JSValueConst this_val,
  56. int argc, JSValueConst *argv)