[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函数解析的更多相关文章

  1. Linux exec族函数解析

    背景 在提到 vfork 函数时,我们提到了这个概念.为了更好地学习与运用,我们对exec族函数进行展开. exec函数族 介绍 有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中 ...

  2. linux之unlink函数解析

    [lingyun@localhost unlink]$ cat unlink.c  /********************************************************* ...

  3. linux之access函数解析

    [lingyun@localhost access_1]$ ls access.c 实例一: [lingyun@localhost access_1]$ cat access.c  /******** ...

  4. linux之ioctl函数解析

    [lingyun@localhost ioctl_1]$ ls ipconfig.c [lingyun@localhost ioctl_1]$ cat ipconfig.c  /*********** ...

  5. linux之umask函数解析

    [lingyun@localhost umask_1]$ vim umask.c  + umask.c                                                 ...

  6. linux之utime函数解析

    [lingyun@localhost utime]$ ls hello  utime.c  world [lingyun@localhost utime]$ cat utime.c  /******* ...

  7. linux之chdir函数解析

    [lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c  /********************* ...

  8. linux之stat函数解析

    [lingyun@localhost stat_1]$ vim stat.c  + stat.c                                                     ...

  9. 关于Linux系统basename函数缺陷的思考

    某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...

随机推荐

  1. oracle10.2 dblink impd 同库不同用户复制数据

    同库不同用户复制数据 1.授权用户导入表权限; SQL> grant exp_full_database to system; SQL> commit; 2.创建dblink; SQL&g ...

  2. [Qt] searchBox 搜索框实现

    [Qt] searchBox 搜索框实现 也就是在lineEdit中加入button.在搜索框的右边会有个小小的搜索图标,输入内容之后,搜索的图标会变成叉叉. 类中的IconHelper见我的另一篇博 ...

  3. flash与字符串:字符串与属性

    有时候,我们想通过设置一个DisplayObject 类是属性值,只是需要通过点来引用即可.有时候,通过字符串也可以引用显示对象里面的属性值.     下面举个例子 .                 ...

  4. 站点建设10个最好的响应的HTML5滑块插件

    大多数的最佳响应的HTML5滑块插件能够使用移动应用程序,站点建设项目,以及Web开发项目提供一些令人兴奋的功能,如无限的动画效果,百分之中的一个百响应布局设计和很多其它. 1.别急!慢慢来 功能丰富 ...

  5. Codeforces Round #311 (Div. 2) E - Ann and Half-Palindrome(字典树+dp)

    E. Ann and Half-Palindrome time limit per test 1.5 seconds memory limit per test 512 megabytes input ...

  6. OC教程10-NSNumber具体

    NSNumber简单介绍 NSNumber是数字的对象形式,由于在OC的数组和字典中仅仅同意存放对象,所以我们有时候须要转化 我们普通的类型是   123 那么 NSNumber类型的是  @123, ...

  7. webpack的配置及使用

    webpack 安装 命令行输入 npm install webpack 配置文件 webpack.config.js moudule.exports = { //Import 入口文件 entry: ...

  8. js方法调用

    <!DOCTYPE html> <html> <head> <title>测试</title> </head> <body ...

  9. LAMP架构搭建+Discuz论坛搭建【weber出品必属精品】

    一.     本机简介: 本机系统: CentOS-6.4-x86_64 主机名:oracle.ywb IP地址:192.168.146.129 二.     在Linux环境下安装Apache步骤 ...

  10. eclipse 连接手机的 核心解决办法

    重启adb的方法  根本不是最本质的方法 最本质的问题 ,一句话概括 : 没安装好驱动呗! 下面是转载的 android开发一般用到的开发工具就是eclipe,而安卓手机则用来调试程序.一般新手在建立 ...