realpath和access函数浅谈

在我所做项目中,用上了realpath和access函数,整理一下

一.主要说明

1.realpath函数

   头文件: 
       #include <limits.h>
       #include <stdlib.h>

  函数原型:char *realpath(const char *path, char *resolved_path)
  函数说明:realpath()用来将参数path所指的相对路径转换成绝对路径后存于参数resolved_path所指的字符串数组或指针中
  返回值: 成功则返回指向resolved_path的指针,失败返回NULL,错误代码存于errno

2.access函数

NAME
       access - determine accessibility of a file

SYNOPSIS
       #include <unistd.h>

       int access(const char *path, int amode);
DESCRIPTION
    The access() function shall check the file named by the  pathname pointed  to  by  the path argument for accessibility according to the bit pattern contained in amode, using the  real  user  ID  in place  of the effective user ID and the real group ID in place of the effective group ID.
    The value of amode is either  the  bitwise-inclusive  OR  of  the access  permissions to be checked (R_OK, W_OK, X_OK) or the exis‐tence test (F_OK).
    If any access permissions are  checked,  each  shall  be  checked individually,  as  described  in  the  Base Definitions volume of IEEE Std 1003.1-2001, Chapter 3, Definitions. If the process  has appropriate privileges,  an  implementation may indicate success for X_OK even if none of the execute  file  permission  bits  are set.
RETURN VALUE
       If the requested access is permitted, access() succeeds and shall return 0; otherwise, -1 shall be returned and errno shall be  set to indicate the error.

二.代码演示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值