Skip to content

Commit a01fcaf

Browse files
andrea-adamimthuurne
authored andcommitted
loop.c: klibc specific fix for ioctl argument 3
Fixing: | loop.c:20:14: error: too few arguments to function 'ioctl' | int devnr = ioctl(fd, LOOP_CTL_GET_FREE); | ^ | In file included from loop.c:6:0: | /oe/oe-core/build/tmp-glibc/sysroots/poodle/usr/lib/klibc/include/unistd.h:111:14: note: declared here | __extern int ioctl(int, int, void *); | ^ | loop.c: In function 'losetup': | loop.c:48:12: warning: passing argument 3 of 'ioctl' makes pointer from integer without a cast | int res = ioctl(loopfd, LOOP_SET_FD, filefd); | ^ | In file included from loop.c:6:0: | /oe/oe-core/build/tmp-glibc/sysroots/poodle/usr/lib/klibc/include/unistd.h:111:14: note: expected 'void *' but argument is of type 'int' | __extern int ioctl(int, int, void *); | ^ | make: *** [loop.o] Error 1 Signed-off-by: Andrea Adami <[email protected]> Maarten ter Huurne <[email protected]>: Add comment in code that we pass 3rd arg for klibc. Add intptr_t typecast to suppress warning on systems where sizeof(int) < sizeof(void *).
1 parent 2079511 commit a01fcaf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

loop.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <fcntl.h>
22
#include <linux/loop.h>
3+
#include <stdint.h>
34
#include <sys/ioctl.h>
45
#include <sys/stat.h>
56
#include <sys/types.h>
@@ -9,6 +10,8 @@
910
#include "loop.h"
1011

1112

13+
// Note: klibc demands the third ioctl arg to be a void*.
14+
1215
int logetfree(void)
1316
{
1417
int fd = open("/dev/loop-control", O_RDWR);
@@ -17,7 +20,7 @@ int logetfree(void)
1720
return -1;
1821
}
1922

20-
int devnr = ioctl(fd, LOOP_CTL_GET_FREE);
23+
int devnr = ioctl(fd, LOOP_CTL_GET_FREE, NULL);
2124
if (devnr < 0) {
2225
WARNING("Failed to acquire free loop device: %d\n", devnr);
2326
} else {
@@ -45,7 +48,7 @@ int losetup(const char *loop, const char *file)
4548
return -1;
4649
}
4750

48-
int res = ioctl(loopfd, LOOP_SET_FD, filefd);
51+
int res = ioctl(loopfd, LOOP_SET_FD, (void *)(intptr_t)filefd);
4952
if (res < 0) {
5053
ERROR("Cannot setup loop device '%s': %d\n", loop, res);
5154
}

0 commit comments

Comments
 (0)