add readlink api

This commit is contained in:
Shuhei Tanuma 2012-06-23 11:22:41 +09:00
parent 380cc0b270
commit 0f28e7f5ee
3 changed files with 43 additions and 3 deletions

View File

@ -41,15 +41,12 @@
* UV_EXTERN void uv_fs_req_cleanup(uv_fs_t* req);
* UV_EXTERN int uv_fs_sendfile(uv_loop_t* loop, uv_fs_t* req, uv_file out_fd,uv_file in_fd, off_t in_offset, size_t length, uv_fs_cb cb);
* UV_EXTERN int uv_fs_readdir(uv_loop_t* loop, uv_fs_t* req,const char* path, int flags, uv_fs_cb cb);
* UV_EXTERN int uv_fs_stat(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);
* UV_EXTERN int uv_fs_fstat(uv_loop_t* loop, uv_fs_t* req, uv_file file,uv_fs_cb cb);
* UV_EXTERN int uv_fs_lstat(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);
* UV_EXTERN int uv_fs_readlink(uv_loop_t* loop, uv_fs_t* req, const char* path,uv_fs_cb cb);
* UV_EXTERN int uv_fs_event_init(uv_loop_t* loop, uv_fs_event_t* handle,const char* filename, uv_fs_event_cb cb, int flags);
* UV_EXTERN struct sockaddr_in6 uv_ip6_addr(const char* ip, int port);

8
examples/readlink.php Normal file
View File

@ -0,0 +1,8 @@
<?php
uv_fs_readlink(uv_default_loop(), "li", function($result,$buffer){
var_dump($result);
var_dump($buffer);
});
uv_run();

View File

@ -773,6 +773,14 @@ static void php_uv_fs_cb(uv_fs_t* req)
case UV_FS_FUTIME:
argc = 0;
break;
case UV_FS_READLINK: {
zval *buffer;
MAKE_STD_ZVAL(buffer);
ZVAL_STRING(buffer, req->ptr, 1);
params[1] = &buffer;
break;
}
case UV_FS_READ: {
zval *buffer;
@ -4127,6 +4135,32 @@ PHP_FUNCTION(uv_fs_symlink)
}
/* }}} */
/* {{{ */
PHP_FUNCTION(uv_fs_readlink)
{
int error;
zval *callback, *tmp, *zloop = NULL;
uv_loop_t *loop;
php_uv_t *uv;
char *path;
int path_len = 0;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
"zsz", &zloop, &path, &path_len, &callback) == FAILURE) {
return;
}
PHP_UV_INIT_UV(uv, IS_UV_FS);
PHP_UV_FETCH_UV_DEFAULT_LOOP(loop, zloop);
uv->fs_cb = callback;
Z_ADDREF_P(callback);
uv->uv.fs.data = uv;
PHP_UV_FS_ASYNC(loop, readlink, path);
}
/* }}} */
static zend_function_entry uv_functions[] = {
/* general */
PHP_FE(uv_update_time, arginfo_uv_update_time)
@ -4236,6 +4270,7 @@ static zend_function_entry uv_functions[] = {
PHP_FE(uv_fs_fchown, NULL)
PHP_FE(uv_fs_link, NULL)
PHP_FE(uv_fs_symlink, NULL)
PHP_FE(uv_fs_readlink, NULL)
/* info */
PHP_FE(uv_loadavg, NULL)
PHP_FE(uv_uptime, NULL)