c - C 中 realpath 函数的示例

标签 c posix realpath

我正在寻找有关如何在 C 程序中使用 realpath 函数的示例。我似乎无法在网上或我的任何 C 编程书籍中找到它。

最佳答案

  • 备注

  • 示例代码

#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) { // or: if (res != NULL)
        printf("This source is at %s.\n", buf);
    } else {
        char* errStr = strerror(errno);
        printf("error string: %s\n", errStr);

        perror("realpath");
        exit(EXIT_FAILURE);
    }
    return 0;
}

关于c - C 中 realpath 函数的示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1563168/

相关文章:

c - 在单独的线程上打印奇数和偶数的程序

C程序: determine which directory a file is in

c - 我无法在 Windows 7 上设置服务器来监听特定端口

c - scanf()将新行char留在缓冲区中

c - 如何在不堆叠旧数据的情况下接收UDP数据

c - 制作我自己的 shell - C - chdir()

python - 防止 RAM 分页到交换区 (mlock)

c++ - 如何在 Linux 中实用地检索连接的接入点信息

java - getServletContext().getRealPath() 在 Controller (NPE)中不起作用,但在 jsp 中起作用

c - realpath() 不解析符号链接(symbolic link)?