Code Monkey home page Code Monkey logo

minicrt's Introduction

MiniCRT

来自 程序员的自我修养——链接、装载与库

简单 C/C++ 运行时库实现 Simple C/C++ run time implementation

支持 Support

X86 X64 ARM AARCH64
WIN10
OSX
Manjaro
Ubuntu
// io
FILE *  fopen(const char *filename, const char *mode);
int64_t fread(void *buffer, uint64_t size, uint64_t count, FILE *stream);
int64_t fwrite(const void *buffer, uint64_t size, uint64_t count, FILE *stream);
int64_t fclose(FILE *fp);
int64_t fseek(FILE *fp, uint64_t offest, int set);
int fputc(int c, FILE *stream);
int fputs(const char *str, FILE *stream);
int printf(const char *format, ...);
int fprintf(FILE *stream, const char *format, ...);
// string
int8_t   strcmp(const char *src, const char *dst);
char *   strcpy(char *dest, const char *src);
uint64_t strlen(const char *str);
void     memset(void *dest, uint8_t val, uint32_t len);
void     bzero(void *dest, uint32_t len);
// stdlib
void  free(void *ptr);
void *malloc(size_t size);
char *itoa(int n, char *str, int radix);
int atexit(atexit_func_t func);
// iostream
// ofstream
class ofstream {
private:
protected:
    FILE *fp;
    ofstream(const ofstream &lhs);

public:
    enum openmode : uint8_t {
        in     = 1,
        out    = 2,
        binary = 4,
        trunc  = 8,
    };
    ofstream(void);
    explicit ofstream(const char *       filename,
                      ofstream::openmode md = ofstream::out);
    ~ofstream(void);
    ofstream &operator<<(char c);
    ofstream &operator<<(int n);
    ofstream &operator<<(const char *lhs);
    ofstream &operator<<(ofstream &(*)(ofstream &));

    void open(const char *filename, ofstream::openmode md = ofstream::out);
    void close(void);
    ofstream &write(const char *buf, unsigned size);
};

// string
class string {
private:
    size_t len;
    char * pbuf;

protected:
public:
    explicit string(const char *str);
    string(const string &s);
    ~string(void);
    string &    operator=(const string &s);
    string &    operator=(const char *s);
    const char &operator[](size_t idx) const;
    char &      operator[](size_t idx);
    const char *c_str(void) const;
    size_t      length(void) const;
    size_t      size(void) const;
};

使用方法 Usage

git clone https://github.com/MRNIU/MiniCRT.git
cd MiniCRT
mkdir build
cmake ..
make

构建完成后,库文件保存在 build/lib/libminicrt.a 测试程序为 build/bin/test

TODO

多平台适配

minicrt's People

Contributors

mrniu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.