Skip to content

Commit 169842a

Browse files
committed
Improve Linux detection
__gnu_linux__ is not always present on all Linux platforms - add checking for __linux__ too.
1 parent 8de8c94 commit 169842a

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

uhubctl.c

+9-9
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ int snprintf(char * __restrict __str, size_t __size, const char * __restrict __f
4747
#include <time.h> /* for nanosleep */
4848
#endif
4949

50-
#ifdef __gnu_linux__
50+
#if defined(__gnu_linux__) || defined(__linux__)
5151
#include <fcntl.h> /* for open() / O_WRONLY */
5252
#endif
5353

@@ -227,14 +227,14 @@ static int opt_exact = 0; /* exact location match - disable USB3 duality handl
227227
static int opt_reset = 0; /* reset hub after operation(s) */
228228
static int opt_force = 0; /* force operation even on unsupported hubs */
229229
static int opt_nodesc = 0; /* skip querying device description */
230-
#ifdef __gnu_linux__
230+
#if defined(__gnu_linux__) || defined(__linux__)
231231
static int opt_nosysfs = 0; /* don't use the Linux sysfs port disable interface, even if available */
232232
#endif
233233

234234

235235
static const char short_options[] =
236236
"l:L:n:a:p:d:r:w:s:hvefRN"
237-
#ifdef __gnu_linux__
237+
#if defined(__gnu_linux__) || defined(__linux__)
238238
"S"
239239
#endif
240240
;
@@ -252,7 +252,7 @@ static const struct option long_options[] = {
252252
{ "exact", no_argument, NULL, 'e' },
253253
{ "force", no_argument, NULL, 'f' },
254254
{ "nodesc", no_argument, NULL, 'N' },
255-
#ifdef __gnu_linux__
255+
#if defined(__gnu_linux__) || defined(__linux__)
256256
{ "nosysfs", no_argument, NULL, 'S' },
257257
#endif
258258
{ "reset", no_argument, NULL, 'R' },
@@ -281,7 +281,7 @@ static int print_usage(void)
281281
"--exact, -e - exact location (no USB3 duality handling).\n"
282282
"--force, -f - force operation even on unsupported hubs.\n"
283283
"--nodesc, -N - do not query device description (helpful for unresponsive devices).\n"
284-
#ifdef __gnu_linux__
284+
#if defined(__gnu_linux__) || defined(__linux__)
285285
"--nosysfs, -S - do not use the Linux sysfs port disable interface.\n"
286286
#endif
287287
"--reset, -R - reset hub after each power-on action, causing all devices to reassociate.\n"
@@ -555,7 +555,7 @@ static int get_port_status(struct libusb_device_handle *devh, int port)
555555
}
556556

557557

558-
#ifdef __gnu_linux__
558+
#if defined(__gnu_linux__) || defined(__linux__)
559559
/*
560560
* Try to use the Linux sysfs interface to power a port off/on.
561561
* Returns 0 on success.
@@ -655,7 +655,7 @@ static int set_port_status_libusb(struct libusb_device_handle *devh, int port, i
655655

656656
static int set_port_status(struct libusb_device_handle *devh, struct hub_info *hub, int port, int on)
657657
{
658-
#ifdef __gnu_linux__
658+
#if defined(__gnu_linux__) || defined(__linux__)
659659
if (!opt_nosysfs) {
660660
if (set_port_status_linux(devh, hub, port, on) == 0) {
661661
return 0;
@@ -1046,7 +1046,7 @@ static int usb_find_hubs(void)
10461046
}
10471047
}
10481048
if (perm_ok == 0 && hub_phys_count == 0) {
1049-
#ifdef __gnu_linux__
1049+
#if defined(__gnu_linux__) || defined(__linux__)
10501050
if (geteuid() != 0) {
10511051
fprintf(stderr,
10521052
"There were permission problems while accessing USB.\n"
@@ -1129,7 +1129,7 @@ int main(int argc, char *argv[])
11291129
case 'N':
11301130
opt_nodesc = 1;
11311131
break;
1132-
#ifdef __gnu_linux__
1132+
#if defined(__gnu_linux__) || defined(__linux__)
11331133
case 'S':
11341134
opt_nosysfs = 1;
11351135
break;

0 commit comments

Comments
 (0)