diff options
Diffstat (limited to 'src/libc/include')
-rw-r--r-- | src/libc/include/__errno.h | 6 | ||||
-rw-r--r-- | src/libc/include/arpa/inet.h | 8 | ||||
-rw-r--r-- | src/libc/include/fcntl.h | 1 | ||||
-rw-r--r-- | src/libc/include/netdb.h | 11 | ||||
-rw-r--r-- | src/libc/include/netinet/in.h | 16 | ||||
-rw-r--r-- | src/libc/include/signal.h | 9 | ||||
-rw-r--r-- | src/libc/include/stdlib.h | 2 | ||||
-rw-r--r-- | src/libc/include/sys/select.h | 13 | ||||
-rw-r--r-- | src/libc/include/sys/socket.h | 38 | ||||
-rw-r--r-- | src/libc/include/sys/stat.h | 11 | ||||
-rw-r--r-- | src/libc/include/sys/time.h | 5 | ||||
-rw-r--r-- | src/libc/include/sys/types.h | 6 | ||||
-rw-r--r-- | src/libc/include/unistd.h | 1 |
13 files changed, 117 insertions, 10 deletions
diff --git a/src/libc/include/__errno.h b/src/libc/include/__errno.h index 7976fba..56bd64a 100644 --- a/src/libc/include/__errno.h +++ b/src/libc/include/__errno.h @@ -26,4 +26,10 @@ E(208, "EAGAIN") E(209, "EIO") E(210, "EDOM domain error") E(211, "EFBIG file too large") +E(212, "EINPROGRESS") +E(213, "EAFNOSUPPORT") +E(214, "EADDRNOTAVAIL") +E(215, "EADDRINUSE") +E(216, "ENOSPC") +E(217, "ECONNREFUSED") #endif diff --git a/src/libc/include/arpa/inet.h b/src/libc/include/arpa/inet.h new file mode 100644 index 0000000..d372467 --- /dev/null +++ b/src/libc/include/arpa/inet.h @@ -0,0 +1,8 @@ +#pragma once +#include <stdint.h> + +uint32_t htonl(uint32_t n); +uint16_t htons(uint16_t n); + +uint32_t ntohl(uint32_t n); +uint16_t ntohs(uint16_t n); diff --git a/src/libc/include/fcntl.h b/src/libc/include/fcntl.h index ba9b9e0..63d301b 100644 --- a/src/libc/include/fcntl.h +++ b/src/libc/include/fcntl.h @@ -4,6 +4,7 @@ #define F_GETFL 2 #define F_DUPFD 3 #define F_SETFD 4 +#define F_GETFD 5 #define FD_CLOEXEC 1 diff --git a/src/libc/include/netdb.h b/src/libc/include/netdb.h new file mode 100644 index 0000000..c88221c --- /dev/null +++ b/src/libc/include/netdb.h @@ -0,0 +1,11 @@ +#pragma once + +struct hostent { + char *h_name; + char **h_aliases; + int h_addrtype; + int h_length; + char **h_addr_list; +}; + +struct hostent *gethostbyname(const char *name); diff --git a/src/libc/include/netinet/in.h b/src/libc/include/netinet/in.h new file mode 100644 index 0000000..b56a22a --- /dev/null +++ b/src/libc/include/netinet/in.h @@ -0,0 +1,16 @@ +#pragma once +#include <sys/socket.h> + +#define IPPROTO_TCP 1 +#define IPPROTO_UDP 2 +#define IPPROTO_IP 4 + +struct in_addr { + in_addr_t s_addr; +}; + +struct sockaddr_in { + sa_family_t sin_family; /* AF_INET */ + in_port_t sin_port; + struct in_addr sin_addr; +}; diff --git a/src/libc/include/signal.h b/src/libc/include/signal.h index 012481e..b01aef3 100644 --- a/src/libc/include/signal.h +++ b/src/libc/include/signal.h @@ -26,14 +26,15 @@ #define NSIG 32 -#define SIG_DFL 0 -#define SIG_ERR 0 -#define SIG_IGN 0 +#define SIG_DFL ((void*)0) +#define SIG_ERR ((void*)0) +#define SIG_IGN ((void*)0) #define SIG_SETMASK 0 typedef int sig_atomic_t; typedef struct {} sigset_t; typedef struct {} siginfo_t; +typedef void (*sighandler_t)(int); extern const char *const sys_siglist[]; struct sigaction { @@ -49,6 +50,6 @@ int sigemptyset(sigset_t *set); int sigfillset(sigset_t *set); int sigprocmask(int how, const sigset_t *set, const sigset_t *oldset); int sigsuspend(const sigset_t *mask); -int signal(int sig, void (*func)(int)); +sighandler_t signal(int sig, void (*func)(int)); int kill(pid_t pid, int sig); int raise(int sig); diff --git a/src/libc/include/stdlib.h b/src/libc/include/stdlib.h index c3fd4bd..61d9734 100644 --- a/src/libc/include/stdlib.h +++ b/src/libc/include/stdlib.h @@ -36,3 +36,5 @@ double strtod(const char *restrict s, char **restrict end); void qsort(void *base, size_t nmemb, size_t size, int (*cmp)(const void *a, const void *b)); void qsort_r(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *, void *), void *arg); void* bsearch(const void* key, const void* base_ptr, size_t nmemb, size_t size, int (*compare)(const void*, const void*)); + +int rand(void); diff --git a/src/libc/include/sys/select.h b/src/libc/include/sys/select.h new file mode 100644 index 0000000..3c1bb90 --- /dev/null +++ b/src/libc/include/sys/select.h @@ -0,0 +1,13 @@ +#pragma once +#include <stdint.h> +#include <sys/time.h> + +typedef uint64_t fd_set; + +#define FD_SETSIZE 64 +void FD_CLR(int fd, fd_set *set); +int FD_ISSET(int fd, fd_set *set); +void FD_SET(int fd, fd_set *set); +void FD_ZERO(fd_set *set); + +int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout); diff --git a/src/libc/include/sys/socket.h b/src/libc/include/sys/socket.h new file mode 100644 index 0000000..e3a4752 --- /dev/null +++ b/src/libc/include/sys/socket.h @@ -0,0 +1,38 @@ +#pragma once +#include <stdint.h> +#include <unistd.h> // ssize_t + +typedef int socklen_t; +typedef int sa_family_t; +typedef uint32_t in_addr_t; +typedef uint16_t in_port_t; + +#define AF_UNSPEC 0 +#define AF_UNIX 1 +#define AF_INET 4 +#define PF_INET 4 + +struct sockaddr { + sa_family_t sa_family; + char sa_data[]; +}; + +#define SOCK_STREAM 1 +#define SOCK_DGRAM 2 +int socket(int domain, int type, int protocol); +int bind(int sockfd, const struct sockaddr *addr, socklen_t addrlen); +int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen); +int listen(int sockfd, int backlog); + +int connect(int sockfd, const struct sockaddr *addr, socklen_t addrlen); +ssize_t send(int sockfd, const void *buf, size_t len, int flags); +ssize_t recv(int sockfd, void *buf, size_t len, int flags); + +#define SOL_SOCKET 1 +#define SO_KEEPALIVE 1 +#define SO_REUSEADDR 2 + +int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen); +int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen); + +int getsockname(int sockfd, struct sockaddr *addr, socklen_t *addrlen); diff --git a/src/libc/include/sys/stat.h b/src/libc/include/sys/stat.h index b9d0e8b..0d828ec 100644 --- a/src/libc/include/sys/stat.h +++ b/src/libc/include/sys/stat.h @@ -4,6 +4,7 @@ #include <sys/types.h> #include <time.h> // struct timespec #include <errno.h> // only for ENOSYS +#include <fcntl.h> // for R_OK etc. (curl) struct stat { dev_t st_dev; @@ -38,7 +39,15 @@ struct stat { #define S_ISGID 02000 #define S_ISVTX 01000 -#define S_IRUSR 0x400 +#define S_IRUSR 0400 +#define S_IWUSR 0200 +#define S_IXUSR 0100 +#define S_IRGRP 0040 +#define S_IWGRP 0020 +#define S_IXGRP 0010 +#define S_IROTH 0004 +#define S_IWOTH 0002 +#define S_IXOTH 0001 /* inode(7) */ #define S_ISREG(m) ((m & S_IFMT) == S_IFREG) diff --git a/src/libc/include/sys/time.h b/src/libc/include/sys/time.h index 54df6b3..5e00fe9 100644 --- a/src/libc/include/sys/time.h +++ b/src/libc/include/sys/time.h @@ -2,6 +2,11 @@ #include <errno.h> #include <sys/types.h> +typedef long long off_t; +typedef int64_t time_t; +typedef int64_t suseconds_t; +typedef uint64_t clock_t; + struct timeval { time_t tv_sec; suseconds_t tv_usec; diff --git a/src/libc/include/sys/types.h b/src/libc/include/sys/types.h index 2e7f54b..d637fd6 100644 --- a/src/libc/include/sys/types.h +++ b/src/libc/include/sys/types.h @@ -1,11 +1,7 @@ #pragma once #include <stddef.h> #include <stdint.h> - -typedef long long off_t; -typedef int64_t time_t; -typedef int64_t suseconds_t; -typedef uint64_t clock_t; +#include <sys/select.h> typedef int mode_t; typedef int dev_t; diff --git a/src/libc/include/unistd.h b/src/libc/include/unistd.h index 2158511..41cf0a0 100644 --- a/src/libc/include/unistd.h +++ b/src/libc/include/unistd.h @@ -5,6 +5,7 @@ #include <getopt.h> // TODO custom stdint.h, ssize_t doesn't belong here +// used from sys/socket.h typedef long long ssize_t; extern char **environ; |