[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. MyBatis魔法堂:Insert操作详解

    一.前言 数据库操作怎能少了INSERT操作呢?下面记录MyBatis关于INSERT操作的笔记,以便日后查阅. 二. insert元素 属性详解 其属性如下: parameterType:入参的全限 ...

  2. hdu 5422 Rikka with Graph(简单题)

    Problem Description As we know, Rikka is poor at math. Yuta is worrying about this situation, so he ...

  3. maven java.lang.OutOfMemoryError:PermGEn space

    配置环境变量: JAVA_OPTS-Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m   MAVEN_OPTS-Xms256m -Xmx ...

  4. [原创]Web前端开发——让ie 7 8支持表单的placeholder属性

    今天在写页面的时候,测试低版本浏览器时,发现input写的placeholder显示的是空白,所以特意写了一个普遍试用的方法来让低版本浏览器支持这个属性. 博主建了一个技术共享qq群:,因为目前人数还 ...

  5. 用户控件(.ascx)与<ul><li>以及<a>布局之小结

    用户控件(.ascx)与<ul><li>以及<a>布局 小结 一.用户控件(.ascx) 1.aspx是浏览器直接访问的页面,而ascx是用户控件,一般是用来重用. ...

  6. Enabling Active Directory Authentication for VMWare Server running on Linux《转载》

    Enabling Active Directory Authentication for VMWare Server running on Linux Version 0.2 - Adam Breid ...

  7. CSS基础知识笔记(二)之选择器

    CSS选择器 选择器{ 样式; } 每一条css样式声明(定义)由两部分组成,形式如下: 在{}之前的部分就是“选择器”,“选择器”指明了{}中的“样式”的作用对象,也就是“样式”作用于网页中的哪些元 ...

  8. HTMl5的sessionStorage和localStorage(转)

    html5中的Web Storage包括了两种存储方式:sessionStorage和localStorage. sessionStorage用于本地存储一个会话(session)中的数据,这些数据只 ...

  9. SQL cmd 实用工具学习 -1

    启动 sqlcmd 实用工具并连接到 SQL Server 的默认实例 在"开始"菜单上,单击"运行". 在"打开"框中,键入 cmd,然后 ...

  10. .NET技术

    1.在C#中,string str = null 与 string str = “” 请尽量使用文字或图象说明其中的区别.回答要点:说明详细的空间分配.(10分) 解:string str=null ...