usb 2.17.0 → 2.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +14 -0
  3. package/binding.gyp +2 -9
  4. package/dist/usb/bindings.d.ts +27 -2
  5. package/dist/usb/bindings.js.map +1 -1
  6. package/dist/usb/index.d.ts +0 -29
  7. package/dist/usb/index.js +4 -18
  8. package/dist/usb/index.js.map +1 -1
  9. package/libusb/.clang-tidy +5 -3
  10. package/libusb/.private/ci-build.sh +5 -1
  11. package/libusb/AUTHORS +14 -0
  12. package/libusb/ChangeLog +15 -2
  13. package/libusb/README +8 -5
  14. package/libusb/Xcode/libusb.xcodeproj/project.pbxproj +4 -0
  15. package/libusb/configure.ac +12 -2
  16. package/libusb/examples/hotplugtest.c +19 -11
  17. package/libusb/examples/listdevs.c +41 -3
  18. package/libusb/examples/xusb.c +6 -1
  19. package/libusb/libusb/Makefile.am +4 -0
  20. package/libusb/libusb/core.c +175 -14
  21. package/libusb/libusb/descriptor.c +163 -14
  22. package/libusb/libusb/io.c +7 -3
  23. package/libusb/libusb/libusb-1.0.def +10 -0
  24. package/libusb/libusb/libusb.h +59 -9
  25. package/libusb/libusb/libusbi.h +89 -25
  26. package/libusb/libusb/os/darwin_usb.c +126 -46
  27. package/libusb/libusb/os/darwin_usb.h +10 -8
  28. package/libusb/libusb/os/emscripten_webusb.cpp +31 -10
  29. package/libusb/libusb/os/haiku_usb_raw.cpp +4 -0
  30. package/libusb/libusb/os/linux_usbfs.c +73 -25
  31. package/libusb/libusb/os/netbsd_usb.c +2 -0
  32. package/libusb/libusb/os/openbsd_usb.c +2 -0
  33. package/libusb/libusb/os/sunos_usb.c +2 -0
  34. package/libusb/libusb/os/threads_posix.c +3 -3
  35. package/libusb/libusb/os/threads_posix.h +8 -2
  36. package/libusb/libusb/os/threads_windows.h +2 -1
  37. package/libusb/libusb/os/windows_common.c +86 -1
  38. package/libusb/libusb/os/windows_common.h +20 -1
  39. package/libusb/libusb/os/windows_hotplug.c +321 -0
  40. package/libusb/libusb/os/windows_hotplug.h +28 -0
  41. package/libusb/libusb/os/windows_usbdk.c +16 -8
  42. package/libusb/libusb/os/windows_winusb.c +753 -41
  43. package/libusb/libusb/os/windows_winusb.h +11 -6
  44. package/libusb/libusb/version.h +1 -1
  45. package/libusb/libusb/version_nano.h +1 -1
  46. package/libusb/msvc/Base.props +1 -1
  47. package/libusb/msvc/Configuration.Base.props +2 -1
  48. package/libusb/msvc/Configuration.DynamicLibrary.props +12 -0
  49. package/libusb/msvc/ProjectConfigurations.Base.props +69 -16
  50. package/libusb/msvc/build_all.ps1 +2 -2
  51. package/libusb/msvc/config.h +4 -0
  52. package/libusb/msvc/getopt/bits/getopt_core.h +96 -0
  53. package/libusb/msvc/getopt/bits/getopt_ext.h +77 -0
  54. package/libusb/msvc/getopt/features.h +21 -0
  55. package/libusb/msvc/getopt/getopt.c +456 -705
  56. package/libusb/msvc/getopt/getopt.h +16 -158
  57. package/libusb/msvc/getopt/getopt1.c +40 -69
  58. package/libusb/msvc/getopt/getopt_int.h +118 -0
  59. package/libusb/msvc/getopt/gettext.h +7 -0
  60. package/libusb/msvc/getopt/unistd.h +5 -0
  61. package/libusb/msvc/getopt.vcxproj +11 -4
  62. package/libusb/msvc/libusb.sln +515 -268
  63. package/libusb/msvc/libusb_dll.vcxproj +2 -0
  64. package/libusb/msvc/libusb_static.vcxproj +2 -0
  65. package/libusb/msvc/xusb.vcxproj +1 -1
  66. package/libusb/tests/Makefile.am +10 -1
  67. package/libusb/tests/fuzz/corpus/bos/min.bos +0 -0
  68. package/libusb/tests/fuzz/corpus/descriptor_parsers/min_valid_config.bin +0 -0
  69. package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_a_endpoint_null.bin +0 -0
  70. package/libusb/tests/fuzz/corpus/descriptor_parsers/regression_bug_b_iad_oob.bin +0 -0
  71. package/libusb/tests/fuzz/fuzz_bos_descriptor.c +49 -0
  72. package/libusb/tests/fuzz/fuzz_descriptor_parsers.c +83 -0
  73. package/libusb/tests/stress_mt.c +2 -1
  74. package/libusb/tests/webusb-test-shim/index.js +6 -5
  75. package/libusb.gypi +5 -0
  76. package/package.json +1 -1
  77. package/prebuilds/android-arm/node.napi.armv7.node +0 -0
  78. package/prebuilds/android-arm64/node.napi.armv8.node +0 -0
  79. package/prebuilds/darwin-x64+arm64/node.napi.node +0 -0
  80. package/prebuilds/linux-arm/node.napi.armv6.node +0 -0
  81. package/prebuilds/linux-arm/node.napi.armv7.node +0 -0
  82. package/prebuilds/linux-arm64/node.napi.armv8.node +0 -0
  83. package/prebuilds/linux-ia32/node.napi.node +0 -0
  84. package/prebuilds/linux-x64/node.napi.glibc.node +0 -0
  85. package/prebuilds/linux-x64/node.napi.musl.node +0 -0
  86. package/prebuilds/win32-arm64/node.napi.node +0 -0
  87. package/prebuilds/win32-ia32/node.napi.node +0 -0
  88. package/prebuilds/win32-x64/node.napi.node +0 -0
  89. package/src/{hotplug/libusb.cc → hotplug.cc} +2 -3
  90. package/src/{hotplug/hotplug.h → hotplug.h} +2 -6
  91. package/src/node_usb.cc +3 -3
  92. package/test/usb.coffee +4 -4
  93. package/test/webusb.coffee +22 -12
  94. package/src/hotplug/windows.cc +0 -168
@@ -87,6 +87,9 @@ struct windows_usb_api_backend {
87
87
  int (*submit_control_transfer)(int sub_api, struct usbi_transfer *itransfer);
88
88
  int (*cancel_transfer)(int sub_api, struct usbi_transfer *itransfer);
89
89
  enum libusb_transfer_status (*copy_transfer_data)(int sub_api, struct usbi_transfer *itransfer, DWORD length);
90
+ int (*endpoint_supports_raw_io)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t endpoint);
91
+ int (*endpoint_set_raw_io)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t endpoint, int enable);
92
+ int (*get_max_raw_io_transfer_size)(int sub_api, struct libusb_device_handle *dev_handle, uint8_t endpoint);
90
93
  };
91
94
 
92
95
  extern const struct windows_usb_api_backend usb_api_backend[USB_API_MAX];
@@ -176,6 +179,7 @@ static inline struct winusb_device_priv *winusb_device_priv_init(struct libusb_d
176
179
  struct winusb_device_priv *priv = usbi_get_device_priv(dev);
177
180
  int i;
178
181
 
182
+ usbi_mutex_init(&priv->interface_lock);
179
183
  priv->apib = &usb_api_backend[USB_API_UNSUPPORTED];
180
184
  priv->sub_api = SUB_API_NOTSET;
181
185
  for (i = 0; i < USB_MAXINTERFACES; i++) {
@@ -206,6 +210,7 @@ static inline void winusb_device_priv_release(struct libusb_device *dev)
206
210
  free(priv->usb_interface[i].path);
207
211
  free(priv->usb_interface[i].endpoint);
208
212
  }
213
+ usbi_mutex_destroy(&priv->interface_lock);
209
214
  }
210
215
 
211
216
  // used to match a device driver (including filter drivers) against a supported API
@@ -307,7 +312,7 @@ typedef enum _USB_HUB_NODE {
307
312
  #endif
308
313
 
309
314
  // Most of the structures below need to be packed
310
- #include <pshpack1.h>
315
+ #pragma pack(push, 1)
311
316
 
312
317
  typedef struct _USB_HUB_DESCRIPTOR {
313
318
  UCHAR bDescriptorLength;
@@ -401,7 +406,7 @@ typedef struct _USB_NODE_CONNECTION_INFORMATION_EX_V2 {
401
406
  USB_NODE_CONNECTION_INFORMATION_EX_V2_FLAGS Flags;
402
407
  } USB_NODE_CONNECTION_INFORMATION_EX_V2, *PUSB_NODE_CONNECTION_INFORMATION_EX_V2;
403
408
 
404
- #include <poppack.h>
409
+ #pragma pack(pop)
405
410
 
406
411
  #if defined(_MSC_VER)
407
412
  // Restore original warnings
@@ -443,7 +448,7 @@ typedef struct {
443
448
  ULONG MaximumBytesPerInterval;
444
449
  } WINUSB_PIPE_INFORMATION_EX, *PWINUSB_PIPE_INFORMATION_EX;
445
450
 
446
- #include <pshpack1.h>
451
+ #pragma pack(push, 1)
447
452
 
448
453
  typedef struct _WINUSB_SETUP_PACKET {
449
454
  UCHAR RequestType;
@@ -453,7 +458,7 @@ typedef struct _WINUSB_SETUP_PACKET {
453
458
  USHORT Length;
454
459
  } WINUSB_SETUP_PACKET, *PWINUSB_SETUP_PACKET;
455
460
 
456
- #include <poppack.h>
461
+ #pragma pack(pop)
457
462
 
458
463
  typedef PVOID WINUSB_INTERFACE_HANDLE, *PWINUSB_INTERFACE_HANDLE;
459
464
  typedef PVOID WINUSB_ISOCH_BUFFER_HANDLE, *PWINUSB_ISOCH_BUFFER_HANDLE;
@@ -695,7 +700,7 @@ struct winusb_interface {
695
700
  #define HIDP_STATUS_SUCCESS 0x110000
696
701
  typedef void * PHIDP_PREPARSED_DATA;
697
702
 
698
- #include <pshpack1.h>
703
+ #pragma pack(push, 1)
699
704
 
700
705
  typedef struct _HIDD_ATTIRBUTES {
701
706
  ULONG Size;
@@ -704,7 +709,7 @@ typedef struct _HIDD_ATTIRBUTES {
704
709
  USHORT VersionNumber;
705
710
  } HIDD_ATTRIBUTES, *PHIDD_ATTRIBUTES;
706
711
 
707
- #include <poppack.h>
712
+ #pragma pack(pop)
708
713
 
709
714
  typedef USHORT USAGE;
710
715
  typedef struct _HIDP_CAPS {
@@ -7,7 +7,7 @@
7
7
  #define LIBUSB_MINOR 0
8
8
  #endif
9
9
  #ifndef LIBUSB_MICRO
10
- #define LIBUSB_MICRO 29
10
+ #define LIBUSB_MICRO 30
11
11
  #endif
12
12
  #ifndef LIBUSB_NANO
13
13
  #define LIBUSB_NANO 0
@@ -1 +1 @@
1
- #define LIBUSB_NANO 11953
1
+ #define LIBUSB_NANO 12037
@@ -15,7 +15,7 @@
15
15
  <IntrinsicFunctions>true</IntrinsicFunctions>
16
16
  <MultiProcessorCompilation>true</MultiProcessorCompilation>
17
17
  <!--Treat sources as utf-8-->
18
- <AdditionalOptions Condition="'$(PlatformToolsetVersion)'&gt;'120'">/utf-8 %(AdditionalOptions)</AdditionalOptions>
18
+ <AdditionalOptions Condition="'$(LibusbPlatformToolsetVersion)'&gt;'120'">/utf-8 %(AdditionalOptions)</AdditionalOptions>
19
19
  <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
20
20
  <DiagnosticsFormat>Caret</DiagnosticsFormat>
21
21
  </ClCompile>
@@ -7,6 +7,7 @@
7
7
  <PlatformToolset Condition="$(VisualStudioVersion)=='15.0'">v141</PlatformToolset>
8
8
  <PlatformToolset Condition="$(VisualStudioVersion)=='16.0'">v142</PlatformToolset>
9
9
  <PlatformToolset Condition="$(VisualStudioVersion)=='17.0'">v143</PlatformToolset>
10
+ <PlatformToolset Condition="$(VisualStudioVersion)=='18.0'">v145</PlatformToolset>
10
11
  <!--We may need the equivalent of PlatformToolsetVersion before it's ready, so create it ourself-->
11
12
  <LibusbPlatformToolsetVersion>$(PlatformToolset.Substring(1))</LibusbPlatformToolsetVersion>
12
13
  <CharacterSet>Unicode</CharacterSet>
@@ -44,4 +45,4 @@
44
45
  <PropertyGroup Label="Globals" Condition="'$(LibusbPlatformToolsetVersion)'&gt;='142'">
45
46
  <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
46
47
  </PropertyGroup>
47
- </Project>
48
+ </Project>
@@ -7,15 +7,27 @@
7
7
  <ItemDefinitionGroup>
8
8
  <ClCompile Condition="'$(Configuration)'=='Debug'">
9
9
  <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
10
+ </ClCompile>
11
+ <ClCompile Condition="'$(Configuration)'=='Debug-Hotplug'">
12
+ <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
10
13
  </ClCompile>
11
14
  <ClCompile Condition="'$(Configuration)'=='Debug-MT'">
12
15
  <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
16
+ </ClCompile>
17
+ <ClCompile Condition="'$(Configuration)'=='Debug-Hotplug-MT'">
18
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
13
19
  </ClCompile>
14
20
  <ClCompile Condition="'$(Configuration)'=='Release'">
15
21
  <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
22
+ </ClCompile>
23
+ <ClCompile Condition="'$(Configuration)'=='Release-Hotplug'">
24
+ <RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
16
25
  </ClCompile>
17
26
  <ClCompile Condition="'$(Configuration)'=='Release-MT'">
18
27
  <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
28
+ </ClCompile>
29
+ <ClCompile Condition="'$(Configuration)'=='Release-Hotplug-MT'">
30
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
19
31
  </ClCompile>
20
32
  </ItemDefinitionGroup>
21
33
  </Project>
@@ -1,10 +1,15 @@
1
1
  <?xml version="1.0" encoding="utf-8"?>
2
2
  <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3
+ <Target Name="ShowHotplugState" BeforeTargets="ClCompile">
4
+ <Message Condition="'$(EnableWindowsHotplug)' == 'true'" Text="EnableWindowsHotplug is enabled" Importance="High" />
5
+ <Message Condition="'$(EnableWindowsHotplug)' != 'true'" Text="EnableWindowsHotplug is disabled" Importance="High" />
6
+ </Target>
7
+ <ItemDefinitionGroup Condition="'$(EnableWindowsHotplug)' == 'true'">
8
+ <ClCompile>
9
+ <PreprocessorDefinitions>LIBUSB_WINDOWS_HOTPLUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
10
+ </ClCompile>
11
+ </ItemDefinitionGroup>
3
12
  <ItemGroup Label="ProjectConfigurations">
4
- <ProjectConfiguration Include="Debug|ARM">
5
- <Configuration>Debug</Configuration>
6
- <Platform>ARM</Platform>
7
- </ProjectConfiguration>
8
13
  <ProjectConfiguration Include="Debug|ARM64">
9
14
  <Configuration>Debug</Configuration>
10
15
  <Platform>ARM64</Platform>
@@ -17,10 +22,6 @@
17
22
  <Configuration>Debug</Configuration>
18
23
  <Platform>x64</Platform>
19
24
  </ProjectConfiguration>
20
- <ProjectConfiguration Include="Release|ARM">
21
- <Configuration>Release</Configuration>
22
- <Platform>ARM</Platform>
23
- </ProjectConfiguration>
24
25
  <ProjectConfiguration Include="Release|ARM64">
25
26
  <Configuration>Release</Configuration>
26
27
  <Platform>ARM64</Platform>
@@ -32,10 +33,6 @@
32
33
  <ProjectConfiguration Include="Release|x64">
33
34
  <Configuration>Release</Configuration>
34
35
  <Platform>x64</Platform>
35
- </ProjectConfiguration>
36
- <ProjectConfiguration Include="Debug-MT|ARM">
37
- <Configuration>Debug-MT</Configuration>
38
- <Platform>ARM</Platform>
39
36
  </ProjectConfiguration>
40
37
  <ProjectConfiguration Include="Debug-MT|ARM64">
41
38
  <Configuration>Debug-MT</Configuration>
@@ -48,10 +45,6 @@
48
45
  <ProjectConfiguration Include="Debug-MT|x64">
49
46
  <Configuration>Debug-MT</Configuration>
50
47
  <Platform>x64</Platform>
51
- </ProjectConfiguration>
52
- <ProjectConfiguration Include="Release-MT|ARM">
53
- <Configuration>Release-MT</Configuration>
54
- <Platform>ARM</Platform>
55
48
  </ProjectConfiguration>
56
49
  <ProjectConfiguration Include="Release-MT|ARM64">
57
50
  <Configuration>Release-MT</Configuration>
@@ -65,5 +58,65 @@
65
58
  <Configuration>Release-MT</Configuration>
66
59
  <Platform>x64</Platform>
67
60
  </ProjectConfiguration>
61
+ <ProjectConfiguration Include="Debug-Hotplug|ARM64">
62
+ <Configuration>Debug-Hotplug</Configuration>
63
+ <Platform>ARM64</Platform>
64
+ </ProjectConfiguration>
65
+ <ProjectConfiguration Include="Debug-Hotplug|Win32">
66
+ <Configuration>Debug-Hotplug</Configuration>
67
+ <Platform>Win32</Platform>
68
+ </ProjectConfiguration>
69
+ <ProjectConfiguration Include="Debug-Hotplug|x64">
70
+ <Configuration>Debug-Hotplug</Configuration>
71
+ <Platform>x64</Platform>
72
+ </ProjectConfiguration>
73
+ <ProjectConfiguration Include="Release-Hotplug|ARM64">
74
+ <Configuration>Release-Hotplug</Configuration>
75
+ <Platform>ARM64</Platform>
76
+ </ProjectConfiguration>
77
+ <ProjectConfiguration Include="Release-Hotplug|Win32">
78
+ <Configuration>Release-Hotplug</Configuration>
79
+ <Platform>Win32</Platform>
80
+ </ProjectConfiguration>
81
+ <ProjectConfiguration Include="Release-Hotplug|x64">
82
+ <Configuration>Release-Hotplug</Configuration>
83
+ <Platform>x64</Platform>
84
+ </ProjectConfiguration>
85
+ <ProjectConfiguration Include="Debug-Hotplug-MT|ARM64">
86
+ <Configuration>Debug-Hotplug-MT</Configuration>
87
+ <Platform>ARM64</Platform>
88
+ </ProjectConfiguration>
89
+ <ProjectConfiguration Include="Debug-Hotplug-MT|Win32">
90
+ <Configuration>Debug-Hotplug-MT</Configuration>
91
+ <Platform>Win32</Platform>
92
+ </ProjectConfiguration>
93
+ <ProjectConfiguration Include="Debug-Hotplug-MT|x64">
94
+ <Configuration>Debug-Hotplug-MT</Configuration>
95
+ <Platform>x64</Platform>
96
+ </ProjectConfiguration>
97
+ <ProjectConfiguration Include="Release-Hotplug-MT|ARM64">
98
+ <Configuration>Release-Hotplug-MT</Configuration>
99
+ <Platform>ARM64</Platform>
100
+ </ProjectConfiguration>
101
+ <ProjectConfiguration Include="Release-Hotplug-MT|Win32">
102
+ <Configuration>Release-Hotplug-MT</Configuration>
103
+ <Platform>Win32</Platform>
104
+ </ProjectConfiguration>
105
+ <ProjectConfiguration Include="Release-Hotplug-MT|x64">
106
+ <Configuration>Release-Hotplug-MT</Configuration>
107
+ <Platform>x64</Platform>
108
+ </ProjectConfiguration>
68
109
  </ItemGroup>
110
+ <PropertyGroup Condition="'$(Configuration)' == 'Debug-Hotplug'">
111
+ <EnableWindowsHotplug>true</EnableWindowsHotplug>
112
+ </PropertyGroup>
113
+ <PropertyGroup Condition="'$(Configuration)' == 'Debug-Hotplug-MT'">
114
+ <EnableWindowsHotplug>true</EnableWindowsHotplug>
115
+ </PropertyGroup>
116
+ <PropertyGroup Condition="'$(Configuration)' == 'Release-Hotplug'">
117
+ <EnableWindowsHotplug>true</EnableWindowsHotplug>
118
+ </PropertyGroup>
119
+ <PropertyGroup Condition="'$(Configuration)' == 'Release-Hotplug-MT'">
120
+ <EnableWindowsHotplug>true</EnableWindowsHotplug>
121
+ </PropertyGroup>
69
122
  </Project>
@@ -1,4 +1,4 @@
1
- $toolsets = "v120", "v140", "v141", "v142", "v143"
1
+ $toolsets = "v120", "v140", "v141", "v142", "v143", "v145"
2
2
  $platforms = "Win32", "x64", "ARM", "ARM64"
3
3
  $configurations = "Debug", "Release"
4
4
 
@@ -14,4 +14,4 @@ foreach ($toolset in $toolsets) {
14
14
  msbuild -m -v:m -p:PlatformToolset=$toolset,Platform=$plat,Configuration=$conf $PSScriptRoot\libusb.sln
15
15
  }
16
16
  }
17
- }
17
+ }
@@ -30,6 +30,10 @@
30
30
  #pragma warning(disable:4324)
31
31
  /* Disable: warning C4996: 'GetVersionExA': was declared deprecated */
32
32
  #pragma warning(disable:4996)
33
+ #if (_MSC_VER > 1800)
34
+ /* Disable: warning C5287: operands are different enum types, supported after Visual Studio 2013 */
35
+ #pragma warning(disable:5287)
36
+ #endif
33
37
 
34
38
  #if defined(_PREFAST_)
35
39
  /* Disable "Banned API" errors when using the MS's WDK OACR/Prefast */
@@ -0,0 +1,96 @@
1
+ /* Declarations for getopt (basic, portable features only).
2
+ Copyright (C) 1989-2026 Free Software Foundation, Inc.
3
+ This file is part of the GNU C Library and is also part of gnulib.
4
+ Patches to this file should be submitted to both projects.
5
+
6
+ The GNU C Library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ The GNU C Library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with the GNU C Library; if not, see
18
+ <https://www.gnu.org/licenses/>. */
19
+
20
+ #ifndef _GETOPT_CORE_H
21
+ #define _GETOPT_CORE_H 1
22
+
23
+ /* This header should not be used directly; include getopt.h or
24
+ unistd.h instead. Unlike most bits headers, it does not have
25
+ a protective #error, because the guard macro for getopt.h in
26
+ gnulib is not fixed. */
27
+
28
+ __BEGIN_DECLS
29
+
30
+ /* For communication from 'getopt' to the caller.
31
+ When 'getopt' finds an option that takes an argument,
32
+ the argument value is returned here.
33
+ Also, when 'ordering' is RETURN_IN_ORDER,
34
+ each non-option ARGV-element is returned here. */
35
+
36
+ extern char *optarg;
37
+
38
+ /* Index in ARGV of the next element to be scanned.
39
+ This is used for communication to and from the caller
40
+ and for communication between successive calls to 'getopt'.
41
+
42
+ On entry to 'getopt', zero means this is the first call; initialize.
43
+
44
+ When 'getopt' returns -1, this is the index of the first of the
45
+ non-option elements that the caller should itself scan.
46
+
47
+ Otherwise, 'optind' communicates from one call to the next
48
+ how much of ARGV has been scanned so far. */
49
+
50
+ extern int optind;
51
+
52
+ /* Callers store zero here to inhibit the error message 'getopt' prints
53
+ for unrecognized options. */
54
+
55
+ extern int opterr;
56
+
57
+ /* Set to an option character which was unrecognized. */
58
+
59
+ extern int optopt;
60
+
61
+ /* Get definitions and prototypes for functions to process the
62
+ arguments in ARGV (ARGC of them, minus the program name) for
63
+ options given in OPTS.
64
+
65
+ Return the option character from OPTS just read. Return -1 when
66
+ there are no more options. For unrecognized options, or options
67
+ missing arguments, 'optopt' is set to the option letter, and '?' is
68
+ returned.
69
+
70
+ The OPTS string is a list of characters which are recognized option
71
+ letters, optionally followed by colons, specifying that that letter
72
+ takes an argument, to be placed in 'optarg'.
73
+
74
+ If a letter in OPTS is followed by two colons, its argument is
75
+ optional. This behavior is specific to the GNU 'getopt'.
76
+
77
+ The argument '--' causes premature termination of argument
78
+ scanning, explicitly telling 'getopt' that there are no more
79
+ options.
80
+
81
+ If OPTS begins with '-', then non-option arguments are treated as
82
+ arguments to the option '\1'. This behavior is specific to the GNU
83
+ 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
84
+ the environment, then do not permute arguments.
85
+
86
+ For standards compliance, the 'argv' argument has the type
87
+ char *const *, but this is inaccurate; if argument permutation is
88
+ enabled, the argv array (not the strings it points to) must be
89
+ writable. */
90
+
91
+ extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
92
+ __THROW __nonnull ((2, 3));
93
+
94
+ __END_DECLS
95
+
96
+ #endif /* getopt_core.h */
@@ -0,0 +1,77 @@
1
+ /* Declarations for getopt (GNU extensions).
2
+ Copyright (C) 1989-2026 Free Software Foundation, Inc.
3
+ This file is part of the GNU C Library and is also part of gnulib.
4
+ Patches to this file should be submitted to both projects.
5
+
6
+ The GNU C Library is free software; you can redistribute it and/or
7
+ modify it under the terms of the GNU Lesser General Public
8
+ License as published by the Free Software Foundation; either
9
+ version 2.1 of the License, or (at your option) any later version.
10
+
11
+ The GNU C Library is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ Lesser General Public License for more details.
15
+
16
+ You should have received a copy of the GNU Lesser General Public
17
+ License along with the GNU C Library; if not, see
18
+ <https://www.gnu.org/licenses/>. */
19
+
20
+ #ifndef _GETOPT_EXT_H
21
+ #define _GETOPT_EXT_H 1
22
+
23
+ /* This header should not be used directly; include getopt.h instead.
24
+ Unlike most bits headers, it does not have a protective #error,
25
+ because the guard macro for getopt.h in gnulib is not fixed. */
26
+
27
+ __BEGIN_DECLS
28
+
29
+ /* Describe the long-named options requested by the application.
30
+ The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
31
+ of 'struct option' terminated by an element containing a name which is
32
+ zero.
33
+
34
+ The field 'has_arg' is:
35
+ no_argument (or 0) if the option does not take an argument,
36
+ required_argument (or 1) if the option requires an argument,
37
+ optional_argument (or 2) if the option takes an optional argument.
38
+
39
+ If the field 'flag' is not NULL, it points to a variable that is set
40
+ to the value given in the field 'val' when the option is found, but
41
+ left unchanged if the option is not found.
42
+
43
+ To have a long-named option do something other than set an 'int' to
44
+ a compiled-in constant, such as set a value from 'optarg', set the
45
+ option's 'flag' field to zero and its 'val' field to a nonzero
46
+ value (the equivalent single-letter option character, if there is
47
+ one). For long options that have a zero 'flag' field, 'getopt'
48
+ returns the contents of the 'val' field. */
49
+
50
+ struct option
51
+ {
52
+ const char *name;
53
+ /* has_arg can't be an enum because some compilers complain about
54
+ type mismatches in all the code that assumes it is an int. */
55
+ int has_arg;
56
+ int *flag;
57
+ int val;
58
+ };
59
+
60
+ /* Names for the values of the 'has_arg' field of 'struct option'. */
61
+
62
+ #define no_argument 0
63
+ #define required_argument 1
64
+ #define optional_argument 2
65
+
66
+ extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
67
+ const char *__shortopts,
68
+ const struct option *__longopts, int *__longind)
69
+ __THROW __nonnull ((2, 3));
70
+ extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
71
+ const char *__shortopts,
72
+ const struct option *__longopts, int *__longind)
73
+ __THROW __nonnull ((2, 3));
74
+
75
+ __END_DECLS
76
+
77
+ #endif /* getopt_ext.h */
@@ -0,0 +1,21 @@
1
+ /* Minimal features.h shim for standalone getopt build on MSVC. */
2
+ #ifndef _FEATURES_H
3
+ #define _FEATURES_H 1
4
+
5
+ #ifdef __cplusplus
6
+ # define __BEGIN_DECLS extern "C" {
7
+ # define __END_DECLS }
8
+ #else
9
+ # define __BEGIN_DECLS
10
+ # define __END_DECLS
11
+ #endif
12
+
13
+ #ifndef __THROW
14
+ # define __THROW
15
+ #endif
16
+
17
+ #ifndef __nonnull
18
+ # define __nonnull(params)
19
+ #endif
20
+
21
+ #endif /* _FEATURES_H */