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

📄 osfileapi.c

📁 osal for Vxworks,c code
💻 C
📖 第 1 页 / 共 2 页
字号:
    OS_NameChange(local_path);        /* check if the name of the file is too long */    if (OS_check_name_length(local_path) == OS_FS_ERROR)        return OS_FS_ERR_NAME_TOO_LONG;    status = remove (local_path);    if (status == OK)        return OS_FS_SUCCESS;    else        return OS_FS_ERROR;    } /* end OS_remove *//*--------------------------------------------------------------------------------------    Name: OS_rename        Purpose: renames a file    Returns: OS_FS_SUCCESS if the rename works             OS_FS_ERROR if the file could not be opened or renamed.             OS_FS_INVALID_POINTER if old or new are NULL             OS_FS_ERR_PATH_TOO_LONG if the paths given are too long to be stored locally             OS_FS_ERR_NAME_TOO_LONG if the new name is too long to be stored locally---------------------------------------------------------------------------------------*/int32 OS_rename (const char *old, const char *new){    int status;    char old_path[OS_MAX_PATH_LEN];    char new_path[OS_MAX_PATH_LEN];        if (old == NULL || new == NULL)        return OS_FS_ERR_INVALID_POINTER;    if (strlen(old) > OS_MAX_PATH_LEN)        return OS_FS_ERR_PATH_TOO_LONG;        if (strlen(new) > OS_MAX_PATH_LEN)        return OS_FS_ERR_PATH_TOO_LONG;    /* make a local copy of the path */    strcpy(old_path, old);    OS_NameChange(old_path);    strcpy(new_path, new);    OS_NameChange(new_path);    /* check if the name of the file is too long */    if (OS_check_name_length(new_path) == OS_FS_ERROR)        return OS_FS_ERR_NAME_TOO_LONG;     status = rename (old_path, new_path);     if (status == OK)         return OS_FS_SUCCESS;     else         return OS_FS_ERROR;     }/*end OS_rename *//*** Directory API *//*--------------------------------------------------------------------------------------    Name: OS_mkdir    Purpose: makes a directory specified by path.    Returns: OS_FS_ERR_INVALID_POINTER if path is NULL             OS_FS_ERR_PATH_TOO_LONG if the path is too long to be stored locally             OS_FS_ERROR if the OS call fails             OS_FS_SUCCESS if success    Note: The access parameter is currently unused.---------------------------------------------------------------------------------------*/int32 OS_mkdir (const char *path, uint32 access){   STATUS status;      char local_path[OS_MAX_PATH_LEN];    if (path == NULL)        return OS_FS_ERR_INVALID_POINTER;    if (strlen(path) > OS_MAX_PATH_LEN)        return OS_FS_ERR_PATH_TOO_LONG;       /* make a local copy of the path */    strcpy(local_path, path);    OS_NameChange(local_path);    status = mkdir(local_path);    if (status == OK)        return OS_FS_SUCCESS;    else        return OS_FS_ERROR;    }/* end OS_mkdir *//*--------------------------------------------------------------------------------------    Name: OS_opendir    Purpose: opens a directory for searching    Returns: NULL if path is NULL,path is too long, OS call fails             a pointer to a directory if success---------------------------------------------------------------------------------------*/os_dirp_t OS_opendir (const char *path){    os_dirp_t dirdescptr;    char local_path[OS_MAX_PATH_LEN];        if (path == NULL)        return NULL;    if (strlen(path) > OS_MAX_PATH_LEN)        return NULL;       /* make a local copy of the path */    strcpy(local_path, path);    OS_NameChange(local_path);    dirdescptr = opendir( (char*) local_path);        /* explicitly returns null for clarity */    if (dirdescptr == NULL)        return NULL;    else        return dirdescptr;    } /* end OS_opendir *//*--------------------------------------------------------------------------------------    Name: OS_closedir        Purpose: closes a directory    Returns: OS_FS_SUCCESS if success             OS_FS_ERROR if close failed---------------------------------------------------------------------------------------*/int32 OS_closedir (os_dirp_t directory){     int status;    if (directory == NULL)        return OS_FS_ERR_INVALID_POINTER;    status = closedir(directory);        if (status == OK)        return OS_FS_SUCCESS;    else        return OS_FS_ERROR;} /* end OS_closedir *//*--------------------------------------------------------------------------------------    Name: OS_readdir    Purpose: obtains directory entry data for the next file from an open directory    Returns: a pointer to the next entry for success             NULL if error or end of directory is reached---------------------------------------------------------------------------------------*/os_dirent_t *  OS_readdir (os_dirp_t directory){     os_dirent_t *tempptr;    errno = OK;        if (directory == NULL)        return NULL;    tempptr = readdir( directory);        if (tempptr != NULL)        return tempptr;    else    {        if (errno != OK)            return NULL;         else            return NULL;    }    /* should never reach this point in the code */    return NULL;    } /* end OS_readdir *//*--------------------------------------------------------------------------------------    Name: OS_rmdir        Purpose: removes a directory from  the structure (must be an empty directory)    Returns: OS_FS_ERR_INVALID_POINTER if path us NULL             OS_FS_ER_PATH_TOO_LONG---------------------------------------------------------------------------------------*/int32  OS_rmdir (const char *path){    STATUS status;    char local_path [OS_MAX_PATH_LEN];        if (path == NULL)        return OS_FS_ERR_INVALID_POINTER;    if (strlen(path) > OS_MAX_PATH_LEN)        return OS_FS_ERR_PATH_TOO_LONG;    strcpy(local_path,path);    OS_NameChange(local_path);        status = rmdir(local_path);        if (status == OK)        return OS_FS_SUCCESS;    else        return OS_FS_ERROR;    }/* end OS_rmdir *//* --------------------------------------------------------------------------------------    Name: OS_check_path_length        Purpose: Checks the length of the file name at the end of the path.        Returns: OS_FS_ERROR if path is NULL, path is too long, there is no '/' in the path             name, the name is too long             OS_SUCCESS if success                NOTE: This is only an internal function and is not intended for use by the user ---------------------------------------------------------------------------------------*/int32 OS_check_name_length(const char *path){    char* name_ptr;    char* end_of_path;    int name_len;    if (path == NULL)        return OS_FS_ERROR;    if (strlen(path) > OS_MAX_PATH_LEN)        return OS_FS_ERROR;        /* checks to see if there is a '/' somewhere in the path */    name_ptr = strrchr(path, '/');        if (name_ptr == NULL)        return OS_FS_ERROR;        /* strrchr returns a pointer to the last '/' char, so we advance one char */    name_ptr = name_ptr + sizeof(char);        /* end_of_path points to the null terminator at the end of the path */    end_of_path = strrchr(path,'\0');    /* pointer subraction to see how many characters there are in the name */    name_len = ((int) end_of_path - (int)name_ptr) / sizeof(char);        if( name_len > OS_MAX_FILE_NAME)        return OS_FS_ERROR;    return OS_FS_SUCCESS;    }/* end OS_check_path_length *//*---------------------------------------------------------------------------------------    Name: OS_FS_GetErrorName()    Purpose: a handy debugging tool that will copy the name of the error code to a buffer    Returns: OS_FS_ERROR if given error number is unknown             OS_FS_SUCCESS if given error is found and copied to the buffer--------------------------------------------------------------------------------------- */int32 OS_FS_GetErrorName(int32 error_num, os_fs_err_name_t * err_name){    os_fs_err_name_t local_name;    int32 return_code;    return_code = OS_FS_SUCCESS;        switch (error_num)    {        case OS_FS_SUCCESS:             strcpy(local_name,"OS_FS_SUCCESS"); break;        case OS_FS_ERROR:             strcpy(local_name,"OS_FS_ERROR"); break;        case OS_FS_ERR_INVALID_POINTER:             strcpy(local_name,"OS_FS_ERR_INVALID_POINTER"); break;        case OS_FS_ERR_PATH_TOO_LONG:             strcpy(local_name,"OS_FS_ERR_PATH_TOO_LONG"); break;        case OS_FS_ERR_NAME_TOO_LONG:             strcpy(local_name,"OS_FS_NAME_TOO_LONG"); break;        case OS_FS_UNIMPLEMENTED:             strcpy(local_name,"OS_FS_UNIMPLEMENTED"); break;        case OS_FS_ERR_DRIVE_NOT_CREATED:             strcpy(local_name,"OS_FS_ERR_DRIVE_NOT_CREATED"); break;        default: strcpy(local_name,"ERROR_UNKNOWN");                 return_code = OS_FS_ERROR;    }    strcpy((char*) err_name, local_name);     return return_code;}/* end OS_FS_GetErrorName */

⌨️ 快捷键说明

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