diff --git a/include/nfsc/libnfs.h b/include/nfsc/libnfs.h index ff7350e..49acc4e 100644 --- a/include/nfsc/libnfs.h +++ b/include/nfsc/libnfs.h @@ -1091,6 +1091,16 @@ EXTERN int nfs_readlink_async(struct nfs_context *nfs, const char *path, nfs_cb */ EXTERN int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsize); +/* + * Sync readlink2() + * Function returns + * NULL : The command failed. + * buf : The content of the link. The returned buffer must be freed + * by the caller. + */ +EXTERN char *nfs_readlink2(struct nfs_context *nfs, const char *path); + + /* diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index 2adc8d6..7bca2d3 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -1003,6 +1003,46 @@ int nfs_readlink(struct nfs_context *nfs, const char *path, char *buf, int bufsi return cb_data.status; } +static void readlink2_cb(int status, struct nfs_context *nfs, void *data, void *private_data) +{ + struct sync_cb_data *cb_data = private_data; + char **bufptr; + char *buf; + + cb_data->is_finished = 1; + + if (status < 0) { + nfs_set_error(nfs, "readlink call failed with \"%s\"", (char *)data); + return; + } + + buf = strdup(data); + if (buf == NULL) + return; + + bufptr = cb_data->return_data; + *bufptr = buf; +} + +char *nfs_readlink2(struct nfs_context *nfs, const char *path) +{ + char *buf; + struct sync_cb_data cb_data; + + buf = NULL; + cb_data.is_finished = 0; + cb_data.return_data = &buf; + + if (nfs_readlink_async(nfs, path, readlink2_cb, &cb_data) != 0) { + nfs_set_error(nfs, "nfs_readlink_async failed"); + return NULL; + } + + wait_for_nfs_reply(nfs, &cb_data); + + return buf; +} + /*