mozilla code -nspr 文件I/O - 2
来源:互联网 发布:白金数据是谁杀了人 编辑:程序博客网 时间:2024/06/05 13:36
#include <prio.h>
结构体:
PRFileDesc 这个结构体太深奥了.再研究
struct PRFileDesc { const PRIOMethods *methods; /* the I/O methods table */ //好像是函数指指的列表,也就是访问的函数的列表 PRFilePrivate *secret; /* layer dependent data */ //在PR_Open中好像调用了CreateFile,最后在prio.c中fd->secret->md.osfd = osfd这里就是返回的HANDLE PRFileDesc *lower, *higher; /* pointers to adjacent layers */ //不清楚 void (PR_CALLBACK *dtor)(PRFileDesc *fd); /* A destructor function for layer */ //不清楚 PRDescIdentity identity; /* Identity of this particular layer */ //特殊的layer的标志};typedef struct PRFileDesc PRFileDesc;
1.PR_Open
//打开or创建一个文件来读OR写OR读写,如果文件成功打开返回PRFileDesc *否则返回NULL;
//成功返回后,在使用完后要用PR_Close
.关闭PRFileDesc
*
/* Open flags */
#define PR_RDONLY 0x01 //只读打开,与PR_CREATE_FILE一起用时,如果没有文件则可以创建文件
#define PR_WRONLY 0x02 //只写打开,与PR_CREATE_FILE一起用时,如果没有文件则可以创建文件
#define PR_RDWR 0x04 //可读可写打开,与PR_CREATE_FILE一起用时,如果没有文件则可以创建文件
#define PR_CREATE_FILE 0x08 //如果不存在则创建,如果存在没有意义.与其它一起用,如果没有此flags时其它flags会返回NULL
#define PR_APPEND 0x10 //追加打开,打开时指针在最后,与PR_CREATE_FILE一起用时,如果没有文件则可以创建文件
#define PR_TRUNCATE 0x20 //覆盖打开,如果存在文件清零,
#define PR_SYNC 0x40 //写同步
#define PR_EXCL 0x80 //与PR_CREATE_FILE一起用,如果不存在在,则创建,存在则函数返回NULL
/*
** File modes ....
**只针对Unix-like系统 -rwxrwxrwx
**当设置了PR_CREATE_FILE,设定相对应的属性
#define PR_IRWXU 00700 /* read, write, execute/search by owner */
#define PR_IRUSR 00400 /* read permission, owner */
#define PR_IWUSR 00200 /* write permission, owner */
#define PR_IXUSR 00100 /* execute/search permission, owner */
#define PR_IRWXG 00070 /* read, write, execute/search by group */
#define PR_IRGRP 00040 /* read permission, group */
#define PR_IWGRP 00020 /* write permission, group */
#define PR_IXGRP 00010 /* execute/search permission, group */
#define PR_IRWXO 00007 /* read, write, execute/search by others */
#define PR_IROTH 00004 /* read permission, others */
#define PR_IWOTH 00002 /* write permission, others */
#define PR_IXOTH 00001 /* execute/search permission, others */
*/
NSPR_API(PRFileDesc*) PR_Open(const char *name, PRIntn flags, PRIntn mode);
NSPR_API(PRFileDesc*) PR_OpenFile( const char *name, PRIntn flags, PRIntn mode);
2.PR_Close
//关闭打开的PRFileDesc *fd (文件或Socket,)
NSPR_API(PRStatus) PR_Close(PRFileDesc *fd);
3.PR_Delete
//删除指定的文件,成功返回PR_SUCCESS,否则返回PR_FAILURE.
NSPR_API(PRStatus) PR_Delete(const char *name);
4.PR_GetFileInfo 和 PR_GetFileInfo64
见此处
5.PR_Rename
/*
**************************************************************************
* FUNCTION: PR_Rename
* DESCRIPTION:
* Rename a file from the old name 'from' to the new name 'to'.
* INPUTS:
* const char *from
* The old name of the file to be renamed.
* const char *to
* The new name of the file.
* OUTPUTS:
* None.
* RETURN: PRStatus
**************************************************************************
*/
//重命名一个文件or文件夹(重命名文件夹不一定成功,好像不能移动),成功返回PR_SUCCESS
,出错返回PR_FAILURE
//应有出错处理,
NSPR_API(PRStatus) PR_Rename(const char *from, const char *to);
6. PR_Access
/*
*************************************************************************
* FUNCTION: PR_Access
* DESCRIPTION:
* Determine accessibility of a file.
* INPUTS:
* const char *name
* path name of the file
* PRAccessHow how
* specifies which access permission to check for.
* It can be one of the following values:
* PR_ACCESS_READ_OK Test for read permission
* PR_ACCESS_WRITE_OK Test for write permission
* PR_ACCESS_EXISTS Check existence of file
* OUTPUTS:
* None.
* RETURN: PRStatus
* PR_SUCCESS is returned if the requested access is permitted.
* Otherwise, PR_FAILURE is returned. Additional information
* regarding the reason for the failure may be retrieved from
* PR_GetError().
*************************************************************************
*/
typedef enum PRAccessHow {
PR_ACCESS_EXISTS = 1,
PR_ACCESS_WRITE_OK = 2,
PR_ACCESS_READ_OK = 3
} PRAccessHow;
NSPR_API(PRStatus) PR_Access(const char *name, PRAccessHow how);
//例程(vc2008)
#include "nspr.h"
#include <iostream>
#pragma comment(lib,"nspr4.lib")
#pragma comment(lib,"plc4.lib")
using namespace std;
int main(int argc, char* argv[])
{
PR_Init(PR_USER_THREAD, PR_PRIORITY_NORMAL, 0);
PRErrorCode err_code;
PRFileDesc* fd;
if (! (fd = PR_Open("c:\\demo.txt", PR_CREATE_FILE| PR_EXCL, 0)))
{
err_code = PR_GetError();
PR_Cleanup();
return 0;
}
PR_Close(fd);
PR_Rename("c:\\demo.txt", "c:\\demo_rename.txt");
PR_MkDir("c:\\dir", 0);//没有写出错处理
if (PR_SUCCESS == PR_Access("c:\\dir",PR_ACCESS_EXISTS))
{
if (PR_FAILURE == PR_Rename("c:\\dir", "c:\\dir_rename"))
{
err_code = PR_GetError();
}
}
PR_Sleep(5000);
PR_Delete("c:\\demo_rename.txt");
PR_RmDir("c:\\dir_rename");
PR_Cleanup();
return 0;
}
- mozilla code -nspr 文件I/O - 2
- mozilla code -nspr 文件I/O - 1
- mozilla code nspr 多线程基础
- mozilla code -nspr 线程同步
- 文件I/O(2)
- File I/O source code--新建文件 相关方法阅读
- File I/O source code--读取文件 相关方法阅读
- File I/O source code--写入文件 相关方法阅读
- 文件I/O(2)
- 文件I/O实践(2) --文件stat
- 文件I/O实践(2) --文件stat
- 文件I/O实践(2) --文件stat
- 文件I/O实践(2) --文件stat
- 文件I/O与标准I/O
- 标准I/O、文件I/O
- 文件I/O与标准I/O
- 文件I/O操作(2)
- 第2章:文件I/O
- emacs下实现像vim的taglist
- WEB高并发解决方案
- ORA-07391: sftopn: fopen error, unable to open text file
- nologging的使用
- 不用重装系统 Windows 7下直接开启AHCI
- mozilla code -nspr 文件I/O - 2
- mysql小技巧
- 最小生成树算法(类Prim算法的笨办法)
- 虚拟机上下载jre和jdk的步骤
- 批处理调用另外一个批处理问题
- MyEclipse7.0创建基于Axis的Web service
- QT::QTimerEvent
- 获得 android 的 root 权限
- Problem B (Max Sum Plus Plus) (dp问题)