⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libc.h

📁 Simple Operating Systems (简称SOS)是一个可以运行在X86平台上(包括QEMU
💻 H
字号:
/* Copyright (C) 2005 David Decotigny   Copyright (C) 2003 Thomas Petazzoni   This program is free software; you can redistribute it and/or   modify it under the terms of the GNU General Public License   as published by the Free Software Foundation; either version 2   of the License, or (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,   USA. */#ifndef _SOS_USER_LIBC_H_#define _SOS_USER_LIBC_H_#include <types.h>/** * @file libc.h * * The basic user C library for user programs *//** * The most important function of a C program ! ;) */void exit (int status)     __attribute__((noreturn, alias("_sos_exit")));/** * Function to duplicate the current running process */pid_t fork(void)     __attribute__ ((alias("_sos_fork")));/** * Function to re-initialize the address space of the current process * with that of the program 'progname' */int exec(const char *progname)     __attribute__ ((alias("_sos_exec")));int nanosleep(unsigned long int sec,	      unsigned long int nanosec)     __attribute__ ((alias("_sos_nanosleep")));/** * These flags (for mmap API) MUST be consistent with those defined in * paging.h and umem_vmm.h */#define PROT_NONE  0#define PROT_READ  (1<<0)#define PROT_WRITE (1<<1)#define PROT_EXEC  (1<<2) /* Not supported on IA32 */#define MAP_SHARED (1 << 0)#define MAP_FIXED  (1 << 31)/** * Non standard version of mmap. Differences with standard version: *  - the resource to map is given by its "path", not by a file descriptor *  - the offset is a signed 64bits, and MUST be >= 0 (error otherwise) *  - no errno support */void * fakemmap(void *start, size_t length, int prot , int flags,		const char *path, loff_t offset);/** * Unmap the given user address interval */int munmap(void * start, size_t length)     __attribute__ ((alias("_sos_munmap")));/** * Change the access permissions of the given user address interval */int mprotect(const void *addr, size_t len, int prot)     __attribute__ ((alias("_sos_mprotect")));/** * This flag tells mremap that the underlying VR may be moved, when necessary */#define MREMAP_MAYMOVE (1 << 30)/** * Grow/shrink the end of the given mapping */void * mremap(void * old_addr, size_t old_len,	      size_t new_len,	      unsigned long flags);/** * Standard heap management API *//** @note MT UNSAFE */int brk(void *end_data_seg);/** @note MT UNSAFE */void *sbrk(ptrdiff_t increment);/** @note MT UNSAFE */void * calloc (size_t nmemb, size_t size);/** @note MT UNSAFE */void * malloc (size_t size);/** @note Does nothing (not implemented yet) */void free(void *ptr);/* * Filesystem subsystem */int mount(const char *source, const char *target,	  const char *filesystemtype, unsigned long mountflags,	  const char *data)     __attribute__ ((alias("_sos_mount")));int umount(const char *target)     __attribute__ ((alias("_sos_umount")));void sync(void)     __attribute__ ((alias("_sos_sync")));struct statvfs{  size_t        f_sz_total;  /**< Total size */  size_t        f_sz_free;   /**< Size left on device */  unsigned int  f_node_total;/**< Total allocatable FS nodes */  unsigned int  f_node_avail;/**< Number of available free FS nodes */  unsigned int  f_flags;};int statvfs(const char *path, struct statvfs *buf)     __attribute__ ((alias("_sos_statvfs")));#define O_EXCL      (1 << 0)#define O_CREAT     (1 << 1)#define O_NOFOLLOW  (1 << 2)#define O_DIRECTORY (1 << 3) /* Incompatible with CREAT */#define O_SYNC      (1 << 4)#define O_RDONLY    (1 << 16)#define O_WRONLY    (1 << 17)#define O_RDWR      (O_RDONLY | O_WRONLY)/** * FS access rights. Same as in kernel fs.h */#define S_IRUSR     00400#define S_IWUSR     00200#define S_IXUSR     00100#define S_IRWXALL   07777 /* For symlinks */int open(const char *pathname, int flags, /* mode_t mode */...);int close(int fd)     __attribute__ ((alias("_sos_close")));int read(int fd, char * buf, size_t len);int write(int fd, const char * buf, size_t len);/* Same as sos_seek_whence_t in kernel fs.h */#define SEEK_SET 42#define SEEK_CUR 24#define SEEK_END 84off_t lseek(int fd, off_t offset, int whence);loff_t lseek64(int fd, loff_t offset, int whence);void * mmap(void *start, size_t length, int prot , int flags,	    int fd, loff_t offset);int ftruncate(int fd, off_t length);int ftruncate64(int fd, loff_t length)     __attribute__ ((alias("_sos_ftruncate64")));int fcntl(int fd, int cmd, int arg)     __attribute__ ((alias("_sos_fcntl")));int creat(const char *pathname, mode_t mode)     __attribute__ ((alias("_sos_creat")));int link (const char *oldpath, const char *newpath)     __attribute__ ((alias("_sos_link")));int unlink(const char *pathname)     __attribute__ ((alias("_sos_unlink")));int rename(const char *oldpath, const char *newpath)     __attribute__ ((alias("_sos_rename")));int symlink(const char *target, const char *path)     __attribute__ ((alias("_sos_symlink")));int mkdir(const char *pathname, mode_t mode)     __attribute__ ((alias("_sos_mkdir")));int rmdir(const char *pathname)     __attribute__ ((alias("_sos_rmdir")));int chmod(const char *path, mode_t mode)     __attribute__ ((alias("_sos_chmod")));struct dirent{  unsigned long long int storage_location;  unsigned long long int offset_in_dirfile;/* Same as sos_fs_node_type_t in kernel fs.h */#define S_IFREG 0x42#define S_IFDIR 0x24#define S_IFLNK 0x84  unsigned int type;  unsigned short namelen;#define SOS_FS_DIRENT_NAME_MAXLEN 128  char       name[SOS_FS_DIRENT_NAME_MAXLEN];};/* Forward declaration (defined in libc.c) */struct sos_DIR_struct;#define DIR struct sos_DIR_structDIR *opendir(const char *name);int dirfd(const DIR * dir);struct dirent *readdir(DIR *dir);int closedir(DIR *dir);struct stat{  int                    st_type;  unsigned long long int st_storage_location;  int                    st_access_rights;  unsigned int           st_nlink;  signed long long int   st_size;};int stat(const char *file_name, struct stat *buf);int lstat(const char *file_name, struct stat *buf);int chroot(const char *path)     __attribute__ ((alias("_sos_chroot")));int chdir(const char *path)     __attribute__ ((alias("_sos_chdir")));int fchdir(int fd)     __attribute__ ((alias("_sos_fchdir")));#endif /* _SOS_USER_LIBC_H_ */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -