2020-09-02 10:22:47 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2020-09-02 10:22:47 +08:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
2021-02-12 02:12:33 +08:00
|
|
|
* 2020-09-01 Meco Man first Version
|
|
|
|
* 2021-02-12 Meco Man move all functions located in <pthread_sleep.c> to this file
|
2020-09-02 10:22:47 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
2021-02-12 02:12:33 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
2020-09-02 10:22:47 +08:00
|
|
|
|
|
|
|
#ifdef RT_USING_POSIX_TERMIOS
|
2020-10-03 00:27:49 +08:00
|
|
|
#include "termios.h"
|
2020-09-02 10:22:47 +08:00
|
|
|
int isatty(int fd)
|
|
|
|
{
|
|
|
|
struct termios ts;
|
2021-04-26 14:31:31 +08:00
|
|
|
return(tcgetattr(fd, &ts) != -1); /*true if no error (is a tty)*/
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
int isatty(int fd)
|
|
|
|
{
|
|
|
|
if (fd >=0 && fd < 3)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2020-09-02 10:22:47 +08:00
|
|
|
}
|
|
|
|
#endif
|
2021-04-26 14:31:31 +08:00
|
|
|
RTM_EXPORT(isatty);
|
2020-09-02 10:22:47 +08:00
|
|
|
|
|
|
|
char *ttyname(int fd)
|
|
|
|
{
|
2021-06-16 12:15:24 +08:00
|
|
|
return "/dev/tty"; /* TODO: need to add more specific */
|
2020-09-02 10:22:47 +08:00
|
|
|
}
|
2021-02-12 02:21:30 +08:00
|
|
|
RTM_EXPORT(ttyname);
|
2021-02-12 02:12:33 +08:00
|
|
|
|
|
|
|
unsigned int sleep(unsigned int seconds)
|
|
|
|
{
|
2021-06-16 12:15:24 +08:00
|
|
|
if (rt_thread_self() != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_thread_delay(seconds * RT_TICK_PER_SECOND);
|
|
|
|
}
|
|
|
|
else /* scheduler has not run yet */
|
|
|
|
{
|
|
|
|
while(seconds > 0)
|
|
|
|
{
|
|
|
|
rt_hw_us_delay(1000000u);
|
|
|
|
seconds --;
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 02:12:33 +08:00
|
|
|
|
2021-06-16 12:15:24 +08:00
|
|
|
return 0;
|
2021-02-12 02:12:33 +08:00
|
|
|
}
|
2021-02-12 02:21:30 +08:00
|
|
|
RTM_EXPORT(sleep);
|
2021-02-12 02:12:33 +08:00
|
|
|
|
|
|
|
int usleep(useconds_t usec)
|
|
|
|
{
|
2021-06-15 18:29:58 +08:00
|
|
|
if (rt_thread_self() != RT_NULL)
|
|
|
|
{
|
|
|
|
rt_thread_mdelay(usec / 1000u);
|
|
|
|
}
|
2021-06-16 12:15:24 +08:00
|
|
|
else /* scheduler has not run yet */
|
2021-06-15 18:29:58 +08:00
|
|
|
{
|
|
|
|
rt_hw_us_delay(usec / 1000u);
|
|
|
|
}
|
2021-02-12 02:12:33 +08:00
|
|
|
rt_hw_us_delay(usec % 1000u);
|
2021-06-16 12:15:24 +08:00
|
|
|
|
2021-02-12 02:12:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-02-12 02:21:30 +08:00
|
|
|
RTM_EXPORT(usleep);
|
2021-02-21 17:25:36 +08:00
|
|
|
|
2021-04-26 14:31:31 +08:00
|
|
|
pid_t gettid(void)
|
2021-02-21 18:01:29 +08:00
|
|
|
{
|
2021-02-21 18:05:47 +08:00
|
|
|
/*TODO*/
|
2021-02-21 18:01:29 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2021-04-26 14:31:31 +08:00
|
|
|
|
|
|
|
pid_t getpid(void)
|
|
|
|
{
|
|
|
|
return gettid();
|
|
|
|
}
|
2021-02-21 18:01:29 +08:00
|
|
|
RTM_EXPORT(getpid);
|
|
|
|
|
|
|
|
pid_t getppid(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
RTM_EXPORT(getppid);
|
|
|
|
|
2021-02-21 17:25:36 +08:00
|
|
|
uid_t getuid(void)
|
|
|
|
{
|
2021-02-21 18:05:47 +08:00
|
|
|
return 0; /*ROOT*/
|
2021-02-21 17:25:36 +08:00
|
|
|
}
|
|
|
|
RTM_EXPORT(getuid);
|
|
|
|
|
2021-02-21 18:01:29 +08:00
|
|
|
uid_t geteuid(void)
|
2021-02-21 17:25:36 +08:00
|
|
|
{
|
2021-02-21 18:05:47 +08:00
|
|
|
return 0; /*ROOT*/
|
2021-02-21 17:25:36 +08:00
|
|
|
}
|
2021-02-21 18:01:29 +08:00
|
|
|
RTM_EXPORT(geteuid);
|
|
|
|
|
|
|
|
gid_t getgid(void)
|
|
|
|
{
|
2021-02-21 18:05:47 +08:00
|
|
|
return 0; /*ROOT*/
|
2021-02-21 18:01:29 +08:00
|
|
|
}
|
|
|
|
RTM_EXPORT(getgid);
|
|
|
|
|
|
|
|
gid_t getegid(void)
|
|
|
|
{
|
2021-02-21 18:05:47 +08:00
|
|
|
return 0; /*ROOT*/
|
2021-02-21 18:01:29 +08:00
|
|
|
}
|
|
|
|
RTM_EXPORT(getegid);
|