-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathunistd.c
More file actions
69 lines (57 loc) · 2.32 KB
/
Copy pathunistd.c
File metadata and controls
69 lines (57 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//-------------------------------------------------------------------------------
// Copyright 2022 Mark Seminatore. All rights reserved.
//-------------------------------------------------------------------------------
#include "stddef.h"
#include "unistd.h"
#include "stdarg.h"
#if defined(__APPLE_CC__) || defined(__linux__)
# include <sys/syscall.h>
#endif
//-------------------------------------------------------------------------------
// Opens the file specified by pathname and returns a file descriptor.
//-------------------------------------------------------------------------------
INT open(const char *pathname, int flags, ...)
{
mode_t mode = 0;
va_list argp;
va_start(argp, flags);
if (flags & O_CREAT)
mode = (mode_t)va_arg(argp, int);
va_end(argp);
return syscall(SYS_open, pathname, flags, mode);
}
//-------------------------------------------------------------------------------
// Closes the given file descriptor.
//-------------------------------------------------------------------------------
INT close(INT fd)
{
return syscall(SYS_close, fd);
}
//-------------------------------------------------------------------------------
// Reads data from the given file descriptor into the array pointed to by buf.
//-------------------------------------------------------------------------------
size_t read(INT fd, void *buf, size_t count)
{
return syscall(SYS_read, fd, buf, count);
}
//-------------------------------------------------------------------------------
// Writes data from the array pointed to by buf to the given file descriptor.
//-------------------------------------------------------------------------------
INT write(INT fd, const void *buf, size_t count)
{
return syscall(SYS_write, fd, buf, count);
}
//-------------------------------------------------------------------------------
// Deletes the file specified by pathname.
//-------------------------------------------------------------------------------
INT unlink(const char *pathname)
{
return syscall(SYS_unlink, pathname);
}
//-------------------------------------------------------------------------------
// Renames the file specified by oldpath to newpath.
//-------------------------------------------------------------------------------
INT _rename(const char *oldpath, const char *newpath)
{
return syscall(SYS_rename, oldpath, newpath);
}