ioctl: add fallback for new time64 SIOCGSTAMP[NS]
[musl] / src / misc / ioctl.c
1 #include <sys/ioctl.h>
2 #include <stdarg.h>
3 #include <errno.h>
4 #include <time.h>
5 #include <sys/time.h>
6 #include "syscall.h"
7
8 int ioctl(int fd, int req, ...)
9 {
10         void *arg;
11         va_list ap;
12         va_start(ap, req);
13         arg = va_arg(ap, void *);
14         va_end(ap);
15         int r = __syscall(SYS_ioctl, fd, req, arg);
16         if (r==-ENOTTY) switch (req) {
17         case SIOCGSTAMP:
18         case SIOCGSTAMPNS:
19                 if (SIOCGSTAMP==SIOCGSTAMP_OLD) break;
20                 if (req==SIOCGSTAMP) req=SIOCGSTAMP_OLD;
21                 if (req==SIOCGSTAMPNS) req=SIOCGSTAMPNS_OLD;
22                 long t32[2];
23                 r = __syscall(SYS_ioctl, fd, req, t32);
24                 if (r<0) break;
25                 if (req==SIOCGSTAMP_OLD) {
26                         struct timeval *tv = arg;
27                         tv->tv_sec = t32[0];
28                         tv->tv_usec = t32[1];
29                 } else {
30                         struct timespec *ts = arg;
31                         ts->tv_sec = t32[0];
32                         ts->tv_nsec = t32[1];
33                 }
34         }
35         return __syscall_ret(r);
36 }