成功的开始

2020年2月6日,我在为LENIX开发标准C库,同一段代码在LENIX和windows都能运行了,关键不是测试代码高不高明,而是gu在于这说明LENIX准备可以使用部分标准C的函数来开发程序了。

1. 测试的代码

这个主要是测试文件功能,最基本的几个功能OK了

/*  2020-01-31 */
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
#include <assert.h>
#include <errno.h>
//
char                msg[] = "test lenix standard c library!\n";
char                filebuf[8192];
//
int main(int argc, char ** argv)
{
    int             i;
    size_t          size = 0;
    FILE *          file;
    char          * testfile;
    unsigned        chksum = 0;
//
    printf(msg);
    for( i = 0; i < argc; i++ )
        printf(" No.%2d argument '%s'\n", i, argv[i]);
//
    file = fopen("1.t", "rb");
    if( file ){
        fseek(file, 0, SEEK_END);
        printf("file size: %d\n", ftell(file));
        fclose(file);
    }else
        printf("1.t not exist\n");
    testfile = argv[1] ? argv[1] : "testfile.txt";
    file = fopen(testfile, "w+");
    if( !file ){
        printf("open '%s' failed\n", testfile);
        return EXIT_FAILURE;
    }
    fprintf(file, "%p %s\n", file, msg);
    i = 0xa5a5a5a5;
    fprintf(file, "%hd %hhi %d %i %u %lu %ld %lld %llX %C\n",
        i, i, i, i, i, i, i, (long long)-1, (long long)-1, 'a');
    i = 0;
    fseek(file, 0, SEEK_SET);
    while( !feof(file) && i < 4096 ){
        filebuf[i++] = (char)fgetc(file);
    }
    filebuf[i] = 0;
    printf("file content: \n%s\n",filebuf);
    fclose(file);
    printf("test fseek extend file space\n");
    file = fopen(testfile, "wb");
    if( NULL == file ){
        printf("failed to open '%s'\n",testfile);
        return EXIT_FAILURE;
    }
    printf("start test fseek extend file space\n");
    memset(filebuf, 'a', 1024);
    //fseek(file, 1024, SEEK_SET);
    printf("write %d count\n", fwrite(filebuf, 512, 1, file));
    printf("write %d count\n", fwrite(filebuf, 1, 512, file));
    fclose(file);
    file = fopen(testfile, "rb");
    if( NULL == file ){
        printf("failed to open '%s'\n",testfile);
        return EXIT_FAILURE;
    }
    printf(" read count: %d\n", fread(filebuf, 130, 10, file));
    fseek(file, 0, SEEK_SET);
    printf(" read count: %d\n", fread(filebuf, 10, 130, file));
    fclose(file);
    printf("test finish\n");
    return EXIT_SUCCESS;
}

2. 在windows下的运行结果

这个是在VS2019下直接运行的结果
在这里插入图片描述

3. 在Lenix下运行的结果

这是用VS2019编译后,在lenix下运行的结果,
在这里插入图片描述
成功的开始

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值