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 ...
随机推荐
- mybatis学习笔记第一讲
第一步:先配置mybatis配置 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE confi ...
- 解决selenium 启动ie浏览器报错:Unexpected error launching Internet Explorer. Protected Mode settings are not the same for all zones
启动ie代码: System.setProperty("webdriver.ie.driver", "bin/IEDriverServer.exe"); Web ...
- 使用PHPExcel导入导出excel格式文件
使用PHPExcel导入导出excel格式文件 作者:zccst 因为导出使用较多,以下是导出实现过程. 第一步,将PHPExcel的源码拷贝到项目的lib下 文件包含:PHPExcel.ph ...
- 安装tcmalloc
安装google-perftools:#tar zxvf google-perftools-1.6.tar.gz #cd google-perftools-1.6 #./configure#make# ...
- LoadRuner性能测试之内存分析方法及步骤(Windows)
1.首先观察Available Mbytes(可用内存),至少要>=1/2的内存空间 2.然后观察Pages/sec值是不是很大 3.再观察Page Faules/sec是不是很大,其值表示 ...
- 生命周期-初识IOS
经常因为生命周期的事情,而视图顺序加载错误,或者出现一系列的小错误并且修改不出来,程序员不知道生命周期确实挺可悲的. IOS生命周期: 自上而下的执行,并且viewDidLoad只会执行一次,所以我们 ...
- 支持多QQ登录的软件
支持多QQ登录,批量加好友,批量回复QQ消息,当然也能接收 下载链接:多QQ登录软件
- 查看Oracle当前用户下的信息(用户,表视图,索引,表空间,同义词,存储过程函数,约束条件)
0.表空间 SQL>select username,default_tablespace from user_users; 查看当前用户的角色 SQL>select * from user ...
- c# 取得扩展名
string KZM=files[0].FileName.Substring(files[0].FileName.LastIndexOf(".") + 1);
- Django REST Framework学习——Android使用REST方法访问Diango
本文更应该叫做Android如何模拟浏览器访问Django服务器后台. 环境为: Android通过HttpClient访问服务器,从Django中获取json数据,解析显示在UI界面上. 问题为: ...