mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-18 08:06:32 +00:00
Add dup,dup2 (#224)
* dup,dup2 * fix: sys_dup2语义与posix不一致的问题 --------- Co-authored-by: longjin <longjin@RinGoTek.cn>
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
#include "sys_version.h" // 这是系统的版本头文件,在编译过程中自动生成
|
||||
#include "sys_version.h" // 这是系统的版本头文件,在编译过程中自动生成
|
||||
#include <fcntl.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
void print_ascii_logo()
|
||||
{
|
||||
printf(" ____ ___ ____ \n");
|
||||
@ -36,7 +36,7 @@ void print_copyright()
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
{
|
||||
print_ascii_logo();
|
||||
print_copyright();
|
||||
|
||||
|
@ -122,6 +122,10 @@ void swab(void *restrict src, void *restrict dest, ssize_t nbytes);
|
||||
|
||||
pid_t getpid(void);
|
||||
|
||||
int dup(int fd);
|
||||
|
||||
int dup2(int ofd, int nfd);
|
||||
|
||||
#if defined(__cplusplus)
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
@ -1,10 +1,10 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <libsystem/syscall.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <libsystem/syscall.h>
|
||||
|
||||
/**
|
||||
* @brief 关闭文件接口
|
||||
@ -88,7 +88,6 @@ pid_t vfork(void)
|
||||
uint64_t brk(uint64_t end_brk)
|
||||
{
|
||||
uint64_t x = (uint64_t)syscall_invoke(SYS_BRK, (uint64_t)end_brk, 0, 0, 0, 0, 0, 0, 0);
|
||||
// printf("brk(): end_brk=%#018lx x=%#018lx", (uint64_t)end_brk, x);
|
||||
return x;
|
||||
}
|
||||
|
||||
@ -197,10 +196,20 @@ void swab(void *restrict src, void *restrict dest, ssize_t nbytes)
|
||||
|
||||
/**
|
||||
* @brief 获取当前进程的pid(进程标识符)
|
||||
*
|
||||
*
|
||||
* @return pid_t 当前进程的pid
|
||||
*/
|
||||
pid_t getpid(void)
|
||||
{
|
||||
syscall_invoke(SYS_GETPID, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
return syscall_invoke(SYS_GETPID, 0, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int dup(int fd)
|
||||
{
|
||||
return syscall_invoke(SYS_DUP, fd, 0, 0, 0, 0, 0, 0, 0);
|
||||
}
|
||||
|
||||
int dup2(int ofd, int nfd)
|
||||
{
|
||||
return syscall_invoke(SYS_DUP2, ofd, nfd, 0, 0, 0, 0, 0, 0);
|
||||
}
|
@ -32,6 +32,8 @@
|
||||
#define SYS_SIGACTION 24 // 设置进程的信号处理动作
|
||||
#define SYS_RT_SIGRETURN 25 // 从信号处理函数返回
|
||||
#define SYS_GETPID 26 // 获取当前进程的pid(进程标识符)
|
||||
#define SYS_DUP 28
|
||||
#define SYS_DUP2 29
|
||||
|
||||
/**
|
||||
* @brief 用户态系统调用函数
|
||||
|
Reference in New Issue
Block a user