C语言中的realpath函数示例 [英] Example of realpath function in C

查看:2488
本文介绍了C语言中的realpath函数示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个如何在C程序中使用realpath函数的示例.我似乎在网上或任何C编程书籍中都找不到.

I'm looking for an example of how to use the realpath function in a C program. I can't seem to find one on the web or in any of my C programming books.

推荐答案

C标准中未描述realpath()函数.但是, POSIX 1997

The realpath() function is not described in the C Standard. It is however described by POSIX 1997 and POSIX 2008. If that is what you mean, here is an example:

#include <limits.h> /* PATH_MAX */
#include <stdio.h>
#include <stdlib.h>
int main(void) {
    char buf[PATH_MAX]; /* PATH_MAX incudes the \0 so +1 is not required */
    char *res = realpath("this_source.c", buf);
    if (res) {
        printf("This source is at %s.\n", buf);
    } else {
        perror("realpath");
        exit(EXIT_FAILURE);
    }
    return 0;
}

PATH_MAX在< limits.h> (< limits.h>)

PATH_MAX is defined in <limits.h> (<limits.h> from POSIX 1997)

这篇关于C语言中的realpath函数示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆