realpath

本文介绍了realpath函数的功能和使用方法,该函数用于将路径名规范化并解析符号链接,生成绝对路径。文章详细解释了参数含义及返回值,并指出在特定情况下如何分配和释放内存。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#include <limits.h>
#include <stdlib.h>

char *realpath(const char *path, char *resolved_path);
Feature Test Macro Requirements for glibc (see  feature_test_macros (7)):
realpath():
_BSD_SOURCE || _XOPEN_SOURCE >= 500 || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED

Description

realpath() expands all symbolic links and resolves references to /.//../ and extra '/' characters in the null-terminated string named by path to produce a canonicalized absolute pathname. The resulting pathname is stored as a null-terminated string, up to a maximum of PATH_MAX bytes, in the buffer pointed to by resolved_path. The resulting path will have no symbolic link, /./ or /../ components.

If resolved_path is specified as NULL, then realpath() uses malloc(3) to allocate a buffer of up to PATH_MAX bytes to hold the resolved pathname, and returns a pointer to this buffer. The caller should deallocate this buffer using free(3).

Return Value

If there is no error, realpath() returns a pointer to the resolved_path.

Otherwise, it returns a NULL pointer, the contents of the array resolved_path are undefined, and errno is set to indicate the error

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值