linux之getcwd函数解析
来源:互联网 发布:手机免费扫描软件 编辑:程序博客网 时间:2024/06/05 22:29
[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]$
/*********************************************************************************
* 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 中getcwd函数使用解析
- 8Linux服务器编程之:chdir()函数和cd命令,getcwd()函数和pwd
- getcwd函数
- getcwd函数
- getcwd函数
- getcwd函数简介
- getcwd()函数的用法
- getcwd函数学习
- linux之open函数解析
- linux之creat函数解析
- linux之lseek函数解析
- linux之read函数解析
- linux之fcntl函数解析
- linux之select函数解析
- linux之ioctl函数解析
- linux之stat函数解析
- linux之lstat函数解析
- VC++调试TRACE和断点的使用
- oracle 分析函数lag 和 lead 简介
- HDU1671 Phone List 解题报告--字典树
- java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade
- ContentProvider
- linux之getcwd函数解析
- 【xtku】女星&&黄美姬win7主题_8.6
- NSString / NSData / char 类型之间的转换
- 查看端口被哪个资源占用的方法
- IOCP编程小结(中)--转载
- ListActivity---
- android TextView中文字通过SpannableString设置属性
- USACO:Your Ride is here
- JDK配置环境变量