linux之getcwd函数解析
[lingyun@localhost getcwd]$ cat getcwd.c
/*********************************************************************************
* Copyright: (C) 2013 fulinux<fulinux@sina.com>
* All rights reserved.
*
* Filename: getcwd.c
* Description: This file
*
* Version: 1.0.0(08/06/2013~)
* Author: fulinux <fulinux@sina.com>
* ChangeLog: 1, Release initial version on "08/06/2013 03:56:30 PM"
*
********************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int main(void)
{
char *ptr;
int size = 50;
if(chdir("/usr/tmp/yum-lingyun-sYjnfB") < 0)
{
perror("chdir");
exit(1);
}
ptr = malloc(size);
if(getcwd(ptr, size) == NULL)
{
perror("getcwd");
exit(1);
}
printf("cwd = %s\n", ptr);
exit(0);
}
[lingyun@localhost getcwd]$ ll /usr/
total 224
dr-xr-xr-x. 2 root root 69632 Apr 29 03:32 bin
drwxr-xr-x. 2 root root 4096 Sep 23 2011 etc
drwxr-xr-x. 2 root root 4096 Sep 23 2011 games
drwxr-xr-x. 39 root root 4096 Apr 15 15:44 include
dr-xr-xr-x. 29 root root 4096 Apr 22 03:18 lib
dr-xr-xr-x. 132 root root 86016 Apr 29 03:32 lib64
drwxr-xr-x. 30 root root 12288 Apr 29 03:32 libexec
drwxr-xr-x. 15 root root 4096 Jun 5 19:57 local
drwxr-xr-x 3 root root 4096 Apr 21 20:38 man
dr-xr-xr-x. 2 root root 12288 Jul 30 03:42 sbin
drwxr-xr-x. 265 root root 12288 Jun 9 09:34 share
drwxr-xr-x. 4 root root 4096 Jul 6 2012 src
lrwxrwxrwx. 1 root root 10 Jul 6 2012 tmp -> ../var/tmp
[lingyun@localhost getcwd]$ ls /usr/tmp/yum-lingyun-sYjnfB/
[lingyun@localhost getcwd]$ gcc getcwd.c
[lingyun@localhost getcwd]$ ./a.out
cwd = /var/tmp/yum-lingyun-sYjnfB
[lingyun@localhost getcwd]$
linux之getcwd函数解析的更多相关文章
- Linux exec族函数解析
背景 在提到 vfork 函数时,我们提到了这个概念.为了更好地学习与运用,我们对exec族函数进行展开. exec函数族 介绍 有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中 ...
- linux之unlink函数解析
[lingyun@localhost unlink]$ cat unlink.c /********************************************************* ...
- linux之access函数解析
[lingyun@localhost access_1]$ ls access.c 实例一: [lingyun@localhost access_1]$ cat access.c /******** ...
- linux之ioctl函数解析
[lingyun@localhost ioctl_1]$ ls ipconfig.c [lingyun@localhost ioctl_1]$ cat ipconfig.c /*********** ...
- linux之umask函数解析
[lingyun@localhost umask_1]$ vim umask.c + umask.c ...
- linux之utime函数解析
[lingyun@localhost utime]$ ls hello utime.c world [lingyun@localhost utime]$ cat utime.c /******* ...
- linux之chdir函数解析
[lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c /********************* ...
- linux之stat函数解析
[lingyun@localhost stat_1]$ vim stat.c + stat.c ...
- 关于Linux系统basename函数缺陷的思考
某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...
随机推荐
- UIView添加支持代码块的手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(a ...
- 第18讲- UI常用组件之EditText
第18讲UI常用组件之EditText 三.文本输入框EditText EditTex类继承自TextView.EditText是接受用户输入信息的最重要控件.在html当中,相当于<input ...
- MyBatis魔法堂:Insert操作详解
一.前言 数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二. insert元素 属性详解 其属性如下: parameterType:入参的全限 ...
- (转)Android’s HTTP Clients
转载自:http://android-developers.blogspot.com/2011/09/androids-http-clients.html Most network-connected ...
- cocos2d移植到安卓引入第三方so文件时候编译会删除解决方式
在游戏中对接支付的SDK的时候引入支付的so文件的时候在编译的时候总是被删除,后来经过查找资料自己整理出了一个解决方式 方案例如以下 在项目导入安卓中之后.在相应的jni目录中创建一个prebuilt ...
- DB2查询当前时间与指定时间的时间差(相隔的秒数)
DB2查询当前时间与指定时间的时间差(相隔的秒数). 例子:“拍品表 auct_item”中有个“结束时间 end_date”的字段,求结束时间与当前时间的间隔秒数. select (DAYS(a. ...
- LRU Cache的简单c++实现
什么是 LRU LRU Cache是一个Cache的置换算法,含义是“最近最少使用”,把满足“最近最少使用”的数据从Cache中剔除出去,并且保证Cache中第一个数据是最近刚刚访问的,因为这样的数据 ...
- World Wind Java开发之十五——载入三维模型
之前的一篇博客是关于载入粗三维模型的,见http://blog.csdn.net/giser_whu/article/details/43452703,这个地方还存在着不能载入纹理的问题,一直没呢解决 ...
- openssl 摘要和签名验证指令dgst使用详解
1.信息摘要和数字签名概述 信息摘要:对数据进行处理,得到一段固定长度的结果,其特点输入: 1.输出长度固定.即输出长度和输入长度无关. 2.不可逆.即由输出数据理论上不能推导出输入数据 4.对输入数 ...
- poj1159 dp(滚动数组优化)
H - 简单dp 例题扩展 Crawling in process... Crawling failed Time Limit:3000MS Memory Limit:65536KB ...