unistd.c 1.5 KB
Newer Older
mysterywolf's avatar
mysterywolf 已提交
1 2 3 4 5 6 7
/*
 * Copyright (c) 2006-2018, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
8 9
 * 2020-09-01     Meco Man     first Version
 * 2021-02-12     Meco Man     move all functions located in <pthread_sleep.c> to this file
mysterywolf's avatar
mysterywolf 已提交
10 11 12
 */

#include <unistd.h>
13 14
#include <rtthread.h>
#include <rthw.h>
mysterywolf's avatar
mysterywolf 已提交
15 16

#ifdef RT_USING_POSIX_TERMIOS
17
#include "termios.h"
18

mysterywolf's avatar
mysterywolf 已提交
19 20 21 22 23
int isatty(int fd)
{
    struct termios ts;
    return(tcgetattr(fd,&ts) != -1);/*true if no error (is a tty)*/
}
mysterywolf's avatar
mysterywolf 已提交
24
RTM_EXPORT(isatty);
mysterywolf's avatar
mysterywolf 已提交
25 26 27 28 29 30
#endif

char *ttyname(int fd)
{
    return "/dev/tty0"; /*TODO: need to add more specific*/
}
mysterywolf's avatar
mysterywolf 已提交
31
RTM_EXPORT(ttyname);
32 33 34 35 36 37 38 39 40 41 42

unsigned int sleep(unsigned int seconds)
{
    rt_tick_t delta_tick;

    delta_tick = rt_tick_get();
    rt_thread_delay(seconds * RT_TICK_PER_SECOND);
    delta_tick = rt_tick_get() - delta_tick;

    return seconds - delta_tick/RT_TICK_PER_SECOND;
}
mysterywolf's avatar
mysterywolf 已提交
43
RTM_EXPORT(sleep);
44 45 46 47 48 49 50

int usleep(useconds_t usec)
{
    rt_thread_mdelay(usec / 1000u);
    rt_hw_us_delay(usec % 1000u);
    return 0;
}
mysterywolf's avatar
mysterywolf 已提交
51
RTM_EXPORT(usleep);
mysterywolf's avatar
mysterywolf 已提交
52

mysterywolf's avatar
update  
mysterywolf 已提交
53 54 55 56 57 58 59
pid_t
#if defined (RT_USING_NEWLIB)
__rt_libc_getpid
#else
getpid
#endif
(void)
mysterywolf's avatar
update  
mysterywolf 已提交
60
{
mysterywolf's avatar
mysterywolf 已提交
61
    /*TODO*/
mysterywolf's avatar
update  
mysterywolf 已提交
62 63 64 65 66 67 68 69 70 71
    return 0;
}
RTM_EXPORT(getpid);

pid_t getppid(void)
{
    return 0;
}
RTM_EXPORT(getppid);

mysterywolf's avatar
mysterywolf 已提交
72 73
uid_t getuid(void)
{
mysterywolf's avatar
mysterywolf 已提交
74
    return 0; /*ROOT*/
mysterywolf's avatar
mysterywolf 已提交
75 76 77
}
RTM_EXPORT(getuid);

mysterywolf's avatar
update  
mysterywolf 已提交
78
uid_t geteuid(void)
mysterywolf's avatar
mysterywolf 已提交
79
{
mysterywolf's avatar
mysterywolf 已提交
80
    return 0; /*ROOT*/
mysterywolf's avatar
mysterywolf 已提交
81
}
mysterywolf's avatar
update  
mysterywolf 已提交
82 83 84 85
RTM_EXPORT(geteuid);

gid_t getgid(void)
{
mysterywolf's avatar
mysterywolf 已提交
86
    return 0; /*ROOT*/
mysterywolf's avatar
update  
mysterywolf 已提交
87 88 89 90 91
}
RTM_EXPORT(getgid);

gid_t getegid(void)
{
mysterywolf's avatar
mysterywolf 已提交
92
    return 0; /*ROOT*/
mysterywolf's avatar
update  
mysterywolf 已提交
93 94
}
RTM_EXPORT(getegid);