[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. syslog_test.c 简单的syslog函数

    #cat syslog_test.c #include<stdio.h> #include<stdlib.h> #include<syslog.h> int mai ...

  2. Open Session In View

    Open Session In View模式的主要思想是:在用户的每一次请求过程始终保持一个Session对象打开着 实现步骤: 步骤一.创建一个Web项目,创建包cn.happy.util,创建Hi ...

  3. Windows下模拟Linux开发

    1.背景 Linux环境下开发是大势所趋,也是开发者必须掌握的技能.然windows系统已深入人心,实在不想放弃windows下的成熟应用,因此可以在Windows上模拟一个Linux系统.这样就满足 ...

  4. 【编程范式】汇编解释swap方法

    先要熟悉一些汇编的基本知识: 1.SP是什么? SP是堆栈寄存器,在调用子程序时,都会用到,保存原来程序的环境使用,如各个寄存器的内容,最重要的是,调用返回时程序的运行指令地址,这是由调用时将返回地址 ...

  5. Java学习笔记——JDBC之与数据库MySQL的连接以及增删改查等操作

    必须的准备工作 一.MySQL的安装.可以参考博文: http://blog.csdn.net/jueblog/article/details/9499245 二.下载 jdbc 驱动.可以从在官网上 ...

  6. CodeSmith使用总结--下拉列表和文件夹对话框属性

    上一篇有点短了,因为实在没有什么可说的,这一篇会多一点.O(∩_∩)O~ 一.下拉列表 关于如何在CodeSmith中创建一个下拉列表的属性框其实很简单,是要使用C#中的枚举就行了,看操作. 首先定义 ...

  7. this函数的理解

    Javascript的this用法 this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test(){ this. ...

  8. scala中的implict

    1.作为隐式参数 object Test { def main(args: Array[String]) { import FruitColor._ Fruit.get("apple&quo ...

  9. Geodatabase - 打开要素类

    string dbPath = @"G:\doc\gis\1.400\data\pdb.mdb"; ESRI.ArcGIS.Geodatabase.IWorkspaceFactor ...

  10. struts2 使用jsonplugin

    配置中的参数含义: root参数用于指定要序列化的根对象,如果省去这一配置,表示要序列化action中的所有属性 ignoreHierarchy 为false时表示要序列化根对象的所有基类 exclu ...