-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #75 from coolyjg/libc-dev9
Libc: epoll and more libc function
- Loading branch information
Showing
24 changed files
with
683 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#ifndef _DIRENT_H | ||
#define _DIRENT_H | ||
|
||
#include <sys/types.h> | ||
|
||
struct __dirstream { | ||
long long tell; | ||
int fd; | ||
int buf_pos; | ||
int buf_end; | ||
int lock[1]; | ||
char buf[2048]; | ||
}; | ||
|
||
typedef struct __dirstream DIR; | ||
|
||
struct dirent { | ||
ino_t d_ino; | ||
off_t d_off; | ||
unsigned short d_reclen; | ||
unsigned char d_type; | ||
char d_name[256]; | ||
}; | ||
|
||
int closedir(DIR *); | ||
DIR *fdopendir(int); | ||
int dirfd(DIR *); | ||
|
||
#define DT_UNKNOWN 0 | ||
#define DT_FIFO 1 | ||
#define DT_CHR 2 | ||
#define DT_DIR 4 | ||
#define DT_BLK 6 | ||
#define DT_REG 8 | ||
#define DT_LNK 10 | ||
#define DT_SOCK 12 | ||
#define DT_WHT 14 | ||
#define IFTODT(x) ((x) >> 12 & 017) | ||
#define DTTOIF(x) ((x) << 12) | ||
|
||
#endif //_DIRENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef _LIBGEN_H | ||
#define _LIBGEN_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
char *dirname(char *); | ||
char *basename(char *); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#ifndef _SYS_EPOLL_H | ||
#define _SYS_EPOLL_H | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <fcntl.h> | ||
#include <stdint.h> | ||
|
||
#define EPOLL_CLOEXEC O_CLOEXEC | ||
#define EPOLL_NONBLOCK O_NONBLOCK | ||
|
||
enum EPOLL_EVENTS { __EPOLL_DUMMY }; | ||
#define EPOLLIN 0x001 | ||
#define EPOLLPRI 0x002 | ||
#define EPOLLOUT 0x004 | ||
#define EPOLLRDNORM 0x040 | ||
#define EPOLLNVAL 0x020 | ||
#define EPOLLRDBAND 0x080 | ||
#define EPOLLWRNORM 0x100 | ||
#define EPOLLWRBAND 0x200 | ||
#define EPOLLMSG 0x400 | ||
#define EPOLLERR 0x008 | ||
#define EPOLLHUP 0x010 | ||
#define EPOLLRDHUP 0x2000 | ||
#define EPOLLEXCLUSIVE (1U << 28) | ||
#define EPOLLWAKEUP (1U << 29) | ||
#define EPOLLONESHOT (1U << 30) | ||
#define EPOLLET (1U << 31) | ||
|
||
#define EPOLL_CTL_ADD 1 | ||
#define EPOLL_CTL_DEL 2 | ||
#define EPOLL_CTL_MOD 3 | ||
|
||
typedef union epoll_data { | ||
void *ptr; | ||
int fd; | ||
uint32_t u32; | ||
uint64_t u64; | ||
} epoll_data_t; | ||
|
||
struct epoll_event { | ||
uint32_t events; | ||
epoll_data_t data; | ||
} | ||
#ifdef __x86_64__ | ||
__attribute__((__packed__)) | ||
#endif | ||
; | ||
|
||
int epoll_create(int __size); | ||
int epoll_ctl(int, int, int, struct epoll_event *); | ||
int epoll_wait(int, struct epoll_event *, int, int); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //_SYS_EPOLL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include <dirent.h> | ||
#include <errno.h> | ||
#include <fcntl.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
|
||
#ifdef AX_CONFIG_ALLOC | ||
int closedir(DIR *dir) | ||
{ | ||
int ret = close(dir->fd); | ||
free(dir); | ||
return ret; | ||
} | ||
|
||
DIR *fdopendir(int fd) | ||
{ | ||
DIR *dir; | ||
struct stat st; | ||
|
||
if (fstat(fd, &st) < 0) { | ||
return 0; | ||
} | ||
if (fcntl(fd, F_GETFL) & O_PATH) { | ||
errno = EBADF; | ||
return 0; | ||
} | ||
if (!S_ISDIR(st.st_mode)) { | ||
errno = ENOTDIR; | ||
return 0; | ||
} | ||
if (!(dir = calloc(1, sizeof(*dir)))) { | ||
return 0; | ||
} | ||
|
||
fcntl(fd, F_SETFD, FD_CLOEXEC); | ||
dir->fd = fd; | ||
return dir; | ||
} | ||
|
||
#endif | ||
|
||
int dirfd(DIR *d) | ||
{ | ||
return d->fd; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <string.h> | ||
#include <unistd.h> | ||
|
||
char **environ = 0; | ||
|
||
char *getenv(const char *name) | ||
{ | ||
size_t l = strchrnul(name, '=') - name; | ||
if (l && !name[l] && environ) | ||
for (char **e = environ; *e; e++) | ||
if (!strncmp(name, *e, l) && l[*e] == '=') | ||
return *e + l + 1; | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#include <stdio.h> | ||
#include <sys/epoll.h> | ||
|
||
#include <libax.h> | ||
|
||
int epoll_create(int size) | ||
{ | ||
return ax_epoll_create(size); | ||
} | ||
|
||
int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev) | ||
{ | ||
return ax_epoll_ctl(fd, op, fd2, ev); | ||
} | ||
|
||
int epoll_wait(int fd, struct epoll_event *ev, int cnt, int to) | ||
{ | ||
return ax_epoll_wait(fd, ev, cnt, to); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include <libgen.h> | ||
#include <string.h> | ||
|
||
char *dirname(char *s) | ||
{ | ||
size_t i; | ||
if (!s || !*s) | ||
return "."; | ||
i = strlen(s) - 1; | ||
for (; s[i] == '/'; i--) | ||
if (!i) | ||
return "/"; | ||
for (; s[i] != '/'; i--) | ||
if (!i) | ||
return "."; | ||
for (; s[i] == '/'; i--) | ||
if (!i) | ||
return "/"; | ||
s[i + 1] = 0; | ||
return s; | ||
} | ||
|
||
char *basename(char *s) | ||
{ | ||
size_t i; | ||
if (!s || !*s) | ||
return "."; | ||
i = strlen(s) - 1; | ||
for (; i && s[i] == '/'; i--) s[i] = 0; | ||
for (; i && s[i - 1] != '/'; i--) | ||
; | ||
return s + i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,4 +93,5 @@ double floor(double x) | |
return x + y - 1; | ||
return x + y; | ||
} | ||
#endif | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.