Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: LGPL-2.1 OR MIT */
0002 /*
0003  * unistd function definitions for NOLIBC
0004  * Copyright (C) 2017-2022 Willy Tarreau <w@1wt.eu>
0005  */
0006 
0007 #ifndef _NOLIBC_UNISTD_H
0008 #define _NOLIBC_UNISTD_H
0009 
0010 #include "std.h"
0011 #include "arch.h"
0012 #include "types.h"
0013 #include "sys.h"
0014 
0015 
0016 static __attribute__((unused))
0017 int msleep(unsigned int msecs)
0018 {
0019     struct timeval my_timeval = { msecs / 1000, (msecs % 1000) * 1000 };
0020 
0021     if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
0022         return (my_timeval.tv_sec * 1000) +
0023             (my_timeval.tv_usec / 1000) +
0024             !!(my_timeval.tv_usec % 1000);
0025     else
0026         return 0;
0027 }
0028 
0029 static __attribute__((unused))
0030 unsigned int sleep(unsigned int seconds)
0031 {
0032     struct timeval my_timeval = { seconds, 0 };
0033 
0034     if (sys_select(0, 0, 0, 0, &my_timeval) < 0)
0035         return my_timeval.tv_sec + !!my_timeval.tv_usec;
0036     else
0037         return 0;
0038 }
0039 
0040 static __attribute__((unused))
0041 int usleep(unsigned int usecs)
0042 {
0043     struct timeval my_timeval = { usecs / 1000000, usecs % 1000000 };
0044 
0045     return sys_select(0, 0, 0, 0, &my_timeval);
0046 }
0047 
0048 static __attribute__((unused))
0049 int tcsetpgrp(int fd, pid_t pid)
0050 {
0051     return ioctl(fd, TIOCSPGRP, &pid);
0052 }
0053 
0054 #endif /* _NOLIBC_UNISTD_H */