如何使用 apr_file_open() 创建文件
我正在对 Apache Portable Runtime 库(版本 1.4)进行以下调用:
result = apr_file_open(
&file, // new file handle
pathname, // file name
APR_FOPEN_CREATE | // create file if not there
APR_FOPEN_EXCL | // error if file was there already
APR_FOPEN_APPEND | // move to end of file on open
APR_FOPEN_BINARY | // binary mode (ignored on UNIX)
APR_FOPEN_XTHREAD | // allow multiple threads to use file
0, // flags
APR_OS_DEFAULT |
0, // permissions
pool // memory pool to use
);
if ( APR_SUCCESS != result ) {
fprintf(
stderr,
"could not create file \"%s\": %s",
pathname,
apr_errorstr( result )
);
}
并且 pathname
包含字符串 /tmp/tempfile20110614091201
。
我不断收到错误“权限被拒绝”(结果代码 APR_EACCES
),但我有权读取/写入 /tmp
- 可能是什么原因导致的?
I am making the following call to the Apache Portable Runtime library (version 1.4):
result = apr_file_open(
&file, // new file handle
pathname, // file name
APR_FOPEN_CREATE | // create file if not there
APR_FOPEN_EXCL | // error if file was there already
APR_FOPEN_APPEND | // move to end of file on open
APR_FOPEN_BINARY | // binary mode (ignored on UNIX)
APR_FOPEN_XTHREAD | // allow multiple threads to use file
0, // flags
APR_OS_DEFAULT |
0, // permissions
pool // memory pool to use
);
if ( APR_SUCCESS != result ) {
fprintf(
stderr,
"could not create file \"%s\": %s",
pathname,
apr_errorstr( result )
);
}
and pathname
contains the string /tmp/tempfile20110614091201
.
I keep getting the error "Permission denied" (result code APR_EACCES
) but I have permissions to read/write to /tmp
- what could be causing this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要
APR_FOPEN_WRITE
标志。我错误地认为APR_FOPEN_APPEND
标志就足够了。所以,有效的调用是:
I needed the
APR_FOPEN_WRITE
flag. I had mistakenly assumed theAPR_FOPEN_APPEND
flag was enough.So, the call that worked was: