我是靠谱客的博主 调皮蜜蜂,最近开发中收集的这篇文章主要介绍vxworks dosfs文件系统文件读写测试,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

/**
  ******************************************************************************
  * @file    dosfsTest.c
  * @author  Daniel_Lee
  * @version V1.0
  * @date    2013.7.15
  * @brief   This is a test of using dosfs.
  ******************************************************************************
**/ 
/* Includes ------------------------------------------------------------------*/

#include "vxWorks.h"

#include "iv.h"

#include "intLib.h"
#include "sysLib.h"
#include "logLib.h"
#include "dosfsLib.h"
#include "ioLib.h"

#include "stdio.h"


STATUS dosfsTest(){
    int fd,bytes = 0, length = 0;
    unsigned char buf[64] = "Hello,I'm testing the file system";
    unsigned char revBuf[64] = {0};
    /*fd = creat("/D/my.txt",O_RDWR); 
    if(fd == -1){
logMsg("error: creat file failedrn",0,0,0,0,0,0);
        return ERROR;
    }*/
    fd = open("/D/my.txt",O_RDWR,0);
    if(fd == -1){
logMsg("error: open file failedrn",0,0,0,0,0,0);
        return ERROR;
    }
    bytes = write(fd,buf,sizeof("Hello,I'm testing the file system"));
    logMsg("write %d bytes datarn",bytes,0,0,0,0,0);
    if(bytes != sizeof("Hello,I'm testing the file system")){
logMsg("error: write %d bytes datarn",bytes,0,0,0,0,0);
        close(fd);
        return ERROR;
    }
    close(fd);
    fd = open("/D/my.txt",O_RDWR,0);
    if(fd == -1){
logMsg("error: open file failedrn",0,0,0,0,0,0);
        return ERROR;
    }
    bytes = read(fd,revBuf,sizeof(revBuf));
    logMsg("read %d bytes datarn",bytes,0,0,0,0,0);
    revBuf[9] = '';   
    logMsg("read %d bytes data, and read date is %srn",bytes,revBuf,0,0,0,0);
    close(fd);
    return OK;
}

实验总结:数组在初始化时必须指明分配的空间大小,不能用变量初始化。

不能write后立马去读数据,因为在写数据的时候文件指针已经指向了文件尾部,马上读的话什么也读不出来,需要使用lseek设置偏移指针才可正确读出。




最后

以上就是调皮蜜蜂为你收集整理的vxworks dosfs文件系统文件读写测试的全部内容,希望文章能够帮你解决vxworks dosfs文件系统文件读写测试所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(81)

评论列表共有 0 条评论

立即
投稿
返回
顶部